Skip to main content

depfinder

image

image

Installation

depfinder is on pypi. It is tested against Python 2.7 and 3.6-3.8.

pip install depfinder

It is available via conda.

conda install -c conda-forge depfinder

It is also via github.

git clone git@github.com:ericdill/depfinder
cd depfinder
python setup.py install

Using depfinder

$ depfinder -h
usage: depfinder [-h] [-y] [-V] [--no-remap] [-v] [-q] [-k KEY] [--conda]
                [--pdb]
                file_or_directory

Tool for inspecting the dependencies of your python project.

positional arguments:
    file_or_directory  Valid options are a single python file, a single jupyter
                        (ipython) notebook or a directory of files that include
                        python files

optional arguments:
    -h, --help         show this help message and exit
    -y, --yaml         Output in syntactically valid yaml when true. Defaults to
                        False
    -V, --version      Print out the version of depfinder and exit
    --no-remap         Do not remap the names of the imported libraries to their
                        proper conda name
    -v, --verbose      Enable debug level logging info from depfinder
    -q, --quiet        Turn off all logging from depfinder
    -k KEY, --key KEY  Select some or all of the output keys. Valid options are
                        'required', 'optional', 'builtin', 'relative', 'all'.
                        Defaults to 'all'
    --conda            Format output so it can be passed as an argument to conda
                        install or conda create
    --pdb              Enable PDB debugging on exception

Ok, great. That's the help output. Not super helpful. What does the output of depfinder look like when we run it on the source code for depfinder?

$ depfinder depfinder
{'builtin': ['__future__',
                'argparse',
                'ast',
                'collections',
                'copy',
                'errno',
                'json',
                'logging',
                'os',
                'pprint',
                're',
                'subprocess',
                'sys'],
    'relative': ['_version', 'main'],
    'required': ['pyyaml', 'stdlib-list']}

So, what do these things mean? Well builtin are modules that are built in to the standard library. required are modules that are not from the standard library or from within the depfinder package and relative are modules that are imported from one module to another within the depfinder source code.

Also see this notebook

Description

Find all the unique imports in your library, automatically, because who likes do it by hand? depfinder uses the ast (Abstract Syntax Tree) module (and more ast docs) to find all :pyast.Try{.interpreted-text role="class"} and :pyast.ImportFrom{.interpreted-text role="class"} nodes. These :pyast.Import{.interpreted-text role="class"} and :pyast.ImportFrom{.interpreted-text role="class"} nodes are then grouped according to the following categories, in order of decreasing precedence:

  • relative : The import is a relative import from within the same library

  • builtin : The import is built into the standard library, as determined by scraping the official python docs for the builtins with stdlib-list

  • questionable : The import occurs inside any combination of

    • {py:class}ast.Try ({py:class}ast.TryExcept on py27)
    • {py:class}ast.FunctionDef or {py:class}ast.AsyncFunctionDef
    • {py:class}ast.If, {py:class}ast.While, {py:class}ast.For, or {py:class}ast.AsyncFor.
    • {py:class}ast.match_case.

    The module may be importable without these imports, but the it will likely not have full functionality.

  • required : The import occurs at the top level of the module and will get executed when the module is imported. These imports must be accounted for in an environment, or the module will not be importable.

Testing

It has dependencies on, stdlib-list and pyyaml. I use stdlib-list to get the list of libraries built in to the standard library. These requirements can be installed via pip :

pip install -r requirements.txt

Also install the test-requiements :

pip install -r test-requirements.txt

Then you can run the tests from the root of the git repository :

coverage run run_tests.py

Releasing

manual:

  1. create an annotated tag and push it to github. git tag -a TAG and then git push --tags`
  2. git checkout TAG
  3. python -m build --sdist --wheel . --outdir dist
  4. twine check dist/*
  5. twine upload dist/* --verbose

API

.. currentmodule:: depfinder.main
.. autofunction:: get_imported_libs
.. autofunction:: iterate_over_library
.. autofunction:: simple_import_search

IPython/Jupyter Notebook support

depfinder has support for v4 Jupyter notebooks.

.. autofunction:: notebook_path_to_dependencies

Metadata

Release files for depfinder 2.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for depfinder 2.10.0
File Size Uploaded Provenance Actions
depfinder-2.10.0.tar.gz 96.2 kB Without provenance Details for depfinder-2.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for depfinder 2.10.0
File Interpreter ABI Platform Actions
depfinder-2.10.0-py3-none-any.whl Python 3 none any Details for depfinder-2.10.0-py3-none-any.whl

Total release size: 179.4 kB

Release files / depfinder-2.10.0.tar.gz

Download URL depfinder-2.10.0.tar.gz
Size 96.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cbaf7c10d53689df8d0893193ff0eaf728e0f541bd935c464d33c614dc662791
BLAKE2b-256 checksum
How to use checksums
93d512650415524fac04dbc34807b2b15cf06b1c8fea3103fcb937ddbadc8c2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / depfinder-2.10.0-py3-none-any.whl

Download URL depfinder-2.10.0-py3-none-any.whl
Size 83.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a7cdf3af2a06ceca306e0b717560bd9a841dafa007989fd0728dcd51e6701e8
BLAKE2b-256 checksum
How to use checksums
52e423af5a0e69cc86a9b2bccfc779024c62e24727b2b4d5c700ef74a5f1427b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Security for depfinder 2.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page