Skip to contents

The Python sibling of repro_dependencies(): walks each file's import/ from ... import statements via code_library_names() (lang = "Python"), and additionally reads any requirements.txt/pyproject.toml the repository supplies for version pins — static analysis of the code alone cannot see those (a script that does import numpy says nothing about which version), so when a manifest is present its pin is attached to the matching imported package instead of being reported separately. A top- level package name is tagged base (the Python standard library; a run never needs to pip install these) or pypi — unlike R's CRAN/ Bioconductor/GitHub/URL split, this does not attempt to tell a PyPI install apart from a pip install git+.../local-path install named in a requirements.txt line: both are reported source = "pypi", with ref carrying the raw requirement line verbatim when it is not a bare package==version pin, so the install step can still attempt it.

Usage

repro_dependencies_py(code_text, manifest_text = NULL)

Arguments

code_text

the code text for a single file (character vector), OR a list of such vectors (one per file) to pool across files

manifest_text

optional character vector: the text of a requirements.txt (one requirement per line) or the [project]/ [tool.poetry] dependency lines of a pyproject.toml, if the repository has one. NULL (default) when none was found — dependencies are then name-only, exactly like a code-only R scan.

Value

a data frame with columns package, source (pypi or base), ref (the manifest's own pin/requirement text for that package, or NA when the package was seen only via import), and base (logical, TRUE for a standard-library module). One row per distinct package. Empty frame (same columns) when none are found.

Examples

code_text <- c("import numpy as np", "from sklearn.linear_model import LinearRegression")
repro_dependencies_py(code_text)
#>        package source  ref  base
#> 1        numpy   pypi <NA> FALSE
#> 2 scikit-learn   pypi <NA> FALSE