Skip to content

Manifest generation for projects only using Python in pre-rendering should include Python #408

Open

Description

@johanpel

I have a project in which I only use a Python script in pre-rendering, but not in any .qmd files. Generating a manifest through:

rsconnect write-manifest quarto . --overwrite

causes the "python" section to not appear, which prevents the requirements.txt from being included, and it seems no Python environment is set up when deploying. The pre-render scripts then fail because they can't import my dependencies.

As a workaround I just added an empty Python cell to one of my .qmd files.

It would be nice if the manifest would also include Python things when there are Python scripts used in pre-rendering.

Activity

  1. aronatkins commented on Apr 14, 2023

    @aronatkins
    Collaborator

    rsconnect-python relies on the output from quarto inspect. The Python environment is included with the manifest when Quarto indicates that the "jupyter" engine is in use.

    We will reach out to the Quarto folks to try to understand if there is another way to determine that a Python environment is required.

    Would you be able to share a minimal example showing what you are attempting?

  2. johanpel commented on Apr 17, 2023

    @johanpel
    Author
    1. Create a Quarto project with the following files:
    • index.qmd:
    ```{ojs}
    foo = require("foo.bar")
    ```
    • pre_render.py:
    import pandas
    pandas.DataFrame(["a","b","c"]).to_csv("foo.bar")
    • _quarto.yml:
    project:
      pre-render: pre_render.py
    • requirements.txt:
    pandas
    
    1. Run rsconnect write-manifest quarto .

    2. Manifest now looks as follows:

    {
      "version": 1,
      "metadata": {
        "appmode": "quarto-static"
      },
      "quarto": {
        "version": "1.2.335",
        "engines": [
          "markdown"
        ]
      },
      "files": {
        "_quarto.yml": {
          "checksum": "b61e2f198e56a15e733b4ee9535dd26a"
        },
        "index.qmd": {
          "checksum": "94f105523bbe9288351afdd5ec53c71f"
        },
        "pre_render.py": {
          "checksum": "8d0cbc2773a63a0e14864722ac01668c"
        },
        "requirements.txt": {
          "checksum": "2f19884f14598d8de5efae75e6d86a7c"
        }
      }
    }
    1. Add an empty Python cell to the QMD file and repeat step 2, the manifest now looks like:
    {
      "version": 1,
      "locale": "en_US.UTF-8",
      "metadata": {
        "appmode": "quarto-static"
      },
      "quarto": {
        "version": "1.2.335",
        "engines": [
          "jupyter"
        ]
      },
      "python": {
        "version": "3.10.6",
        "package_manager": {
          "name": "pip",
          "version": "23.0.1",
          "package_file": "requirements.txt"
        }
      },
      "files": {
        "_quarto.yml": {
          "checksum": "b61e2f198e56a15e733b4ee9535dd26a"
        },
        "index.qmd": {
          "checksum": "5fc4682fa23cf39436031e6d570fafab"
        },
        "pre_render.py": {
          "checksum": "8d0cbc2773a63a0e14864722ac01668c"
        },
        "requirements.txt": {
          "checksum": "2f19884f14598d8de5efae75e6d86a7c"
        }
      }
    }

    I think it would be nice if rsconnect also checks whether Python is used in any pre- or post-render scripts such that it would produce the manifest as shown in step 4.

    Just to be sure, I am aware there are things like ojs_define to pass data from Python cells to OJS cells, but in my actual project the pre-render step is of significant size.

  3. aronatkins commented on Apr 18, 2023

    @aronatkins
    Collaborator

    Thanks @johanpel - we'll discuss and figure out how to solve your example. It might be that we need to let you "force" the Python environment even though the document itself does not demand one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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