Skip to content

Require requirements.txt when deploying reticulated content to Connect #1218

@karawoo

Description

@karawoo

tl;dr: rsconnect should require a requirements.txt for reticulated content, and offer some guidance about how to generate it.

background: py_require() is the recommended way for reticulated projects to declare dependencies. reticulate will then resolve those dependencies at runtime into an ephemeral environment.

The behavior of rsconnect, when deploying to Connect, will differ depending on whether the content has been run locally before deploying or not:

  1. If they run their code and hit all of the py_require functions before deploying, things will work as expected. Reticulate will have set the VIRTUAL_ENV variable and Connect will know where to look to find all the Python dependencies.
  2. If a user is working in a fresh R session, Connect will not realize that this deployment requires Python. No Python or packages will be installed, and instead when the application runs in Connect, uv will dynamically install everything.

Connect has separate processes for building and running content. This separation needs to be maintained in order to support other existing features (such as the API endpoint that lists what dependencies & versions are used by which pieces of content). Resolving dependencies and building an environment at runtime breaks this model, so we don't want to use the ephemeral environments on Connect.

Ideally rsconnect would be able to detect the use of ephemeral environments and give some specific guidance about how to materialize them. Unfortunately however, it is not possible to detect whether a local project uses ephemeral environments except by running it up until the point where it initializes Python and then checking reticulate:::is_epheremal_venv_initialized(). This won't work for rsconnect: we can't assume the user has run the code in their session before they try to deploy (and indeed the push-button deploy in RStudio happens in a separate process, so definitely won't have run the content).

After some discussion it seems like the thing to do is for rsconnect to require a requirements.txt for reticulated content. Connect can use this to build the environment in its normal way and prevent the runtime dependency resolution from occurring. If a requirements.txt is not present, rsconnect should fail fast with an error that gives some guidance as to how to generate the requirements.txt file.

See also:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions