poncho_package_analyze(1)

NAME

poncho_package_analyze - command-line utility for analyzing Python script for library and interpreter dependencies

SYNOPSIS

poncho_package_analyze [options] <python-script ...> <json-output-file>

DESCRIPTION

poncho_package_analyze is a simple command line utility for analyzing Python scripts for the necessary external dependencies. It generates an output file that can be used with python_package_create to build a self-contained Conda environment for the Python application.

The python-script ... argument is the path(s) to the Python script(s) to be analyzed. The json-output-file argument is the path to the output JSON file that will be generated by the command. Specifying - for either will use stdin/stdout instead of a file.

OPTIONS

  • -h,--help
    Show this help message
  • --toplevel
    Only include imports at the top level of the script.
  • --function=<<fn>>
    Only include imports in the given function.
  • --pkg-mapping=<<import=name>>
    Specify that the module imported as <import> in the code is provided by the pip/conda package <name>.
  • --extra-pkg=<pkg>
    Also include the pip/conda package <pkg>, even if it does not appear in the sources. May be useful for scripts that execute other (possibly non-Python) components that must also be included.

EXIT

On success, returns zero. On failure, returns non-zero.

EXAMPLE

An example Python script example.py contains the following code:

import os
import sys
import pickle

import antigravity
import matplotlib


if __name__ == "__main__":
    print("example")

To analyze the example.py script for its dependencies and generate the output JSON dependencies file dependencies.json, run the following command:

$ poncho_package_analyze example.py dependencies.json

Once the command completes, the dependencies.json file within the current working directory will contain a Conda environment specification (suitable to use with conda env create).

Note that system-level modules are considered part of the Python package installed into the Conda environment. Additionally, imports not managed by Pip or Conda are not allowed. This includes other modules within the CWD or in user-written packages.

The Cooperative Computing Tools are Copyright (C) 2022 The University of Notre Dame. This software is distributed under the GNU General Public License. See the file COPYING for details.

CCTools