rsconnect-python icon indicating copy to clipboard operation
rsconnect-python copied to clipboard

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

Open johanpel opened this issue 2 years ago • 3 comments

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.

johanpel avatar Apr 13 '23 18:04 johanpel

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?

aronatkins avatar Apr 14 '23 13:04 aronatkins

  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.

johanpel avatar Apr 17 '23 07:04 johanpel

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.

aronatkins avatar Apr 18 '23 13:04 aronatkins