Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list python package dependencies without loading them?

Tags:

Say that python package A requires B, C and D; is there a way to list A → B C D without loading them ?
Requires in the metadata (yolk -M A) are often incomplete, grr.
One can download A.tar / A.egg, then look through A/setup.py, but some of those are pretty gory.

(I'd have thought that getting at least first-level dependencies could be mechanized; even a 98 % solution would be better than avalanching downloads.)

A related question: pip-upgrade-package-without-upgrading-dependencies

like image 306
denis Avatar asked May 20 '10 15:05

denis


People also ask

How can I see the dependencies of a python package?

Pip Check Command – Check Python Dependencies After Installation. Because pip doesn't currently address dependency issues on installation, the pip check command option can be used to verify that dependencies have been installed properly in your project. For example: $ pip check No broken requirements found.

How can I tell what dependencies are installed?

Usage in npm scripts You can use check-installed-dependencies inside npm scripts. Then in either prepublish or another npm script you can use check-installed-dependencies . Note: Using check-installed-dependencies in prepublish will stop the package from being published.

What is __ all __ In init py?

In the __init__.py file of a package __all__ is a list of strings with the names of public modules or other objects. Those features are available to wildcard imports.

What is Pydeps?

pydeps: Python Module Dependency Visualization - Data Science Simplified.


2 Answers

Snakefood

sfood -fuq package.py | sfood-target-files  

will list the dependencies.

`-f` tells sfood to follow dependencies recursively `-u` tells sfood to ignore unused imports `-q` tells sfood to be quiet about debugging information 

To filter out modules from the standard library, you could use

sfood -fuq package.py | sfood-filter-stdlib | sfood-target-files  

As you've already noted, if there are other directories you'd like ignored, you can also use the sfood -I flag.

like image 200
unutbu Avatar answered Sep 18 '22 05:09

unutbu


modulefinder from the standard lib

New in version 2.3.

This module provides a ModuleFinder class that can be used to determine the set of modules imported by a script. modulefinder.py can also be run as a script, giving the filename of a Python script as its argument, after which a report of the imported modules will be printed.

I am not sure if it complies with your requierement about not loading the modules. From here:

modulefinder use bytecode inspection to find dependencies, and therefore is free from any side-effects that may be caused by importing the modules being studied.

Other hints about the use of pylint or Gui2exe here

like image 25
joaquin Avatar answered Sep 19 '22 05:09

joaquin