Coder Social home page Coder Social logo

justintime50 / pip-tree Goto Github PK

View Code? Open in Web Editor NEW
19.0 4.0 0.0 86 KB

Get the dependency tree of your Python virtual environment via Pip.

License: MIT License

Python 81.12% Just 18.88%
python pip virtual environment venv dependency tree project package virtual-environments

pip-tree's Introduction

Pip Tree

Get the dependency tree of your Python virtual environment via Pip.

Build Status Coverage Status PyPi Licence

Showcase

There is no simple, native way to get the dependency tree of a Python virtual environment using the Pip package manager for Python. Pip Tree fixes this problem by retrieving every package from your virtual environment and returning a list of JSON objects that include the package name, version installed, date updated, and which packages are required by each package (the tree).

Install

# Install Pip Tree globally
pip3 install pip-tree

# Install Pip Tree into the virtual environment of the project you want to run it on
venv/bin/pip install pip-tree

# Install locally
just install

Usage

Virtual Env Usage:
    pip-tree

Global Usage:
    pip-tree --path "path/to/my_project/venv/lib/python3.9/site-packages"

Options:
    -h, --help            show this help message and exit
    -p PATH, --path PATH  The path to the site-packages directory of a Python virtual environment. If a path is not provided, the virtual environment Pip Tree is run from will be used.

Sample Output

Generating Pip Tree Report...

[
    {
        "name": "docopt",
        "version": "0.6.2",
        "updated": "2021-05-12",
        "requires": [],
        "required_by": [
            "coveralls"
        ]
    },
    {
        "name": "flake8",
        "version": "3.9.2",
        "updated": "2021-05-12",
        "requires": [
            "mccabe<0.7.0,>=0.6.0",
            "pyflakes<2.4.0,>=2.3.0",
            "pycodestyle<2.8.0,>=2.7.0"
        ],
        "required_by": []
    },
    {
        "name": "Flask",
        "version": "2.0.0",
        "updated": "2021-05-12",
        "requires": [
            "click>=7.1.2",
            "itsdangerous>=2.0",
            "Jinja2>=3.0"
            "Werkzeug>=2.0",
        ],
        "required_by": []
    }
]

Pip Tree report complete! 40 dependencies found for "path/to/my_project/venv/lib/python3.12/site-packages".

Package

In addition to the CLI tool, you can use functions to retrieve the list of packages and their details from a Python virtual environment in your own code:

import pip_tree

path = 'path/to/my_project/venv/lib/python3.12/site-packages'

package_list = pip_tree.get_pip_package_list(path)
for package in package_list:
    package_details = pip_tree.get_package_details(package)
    print(package_details['name'])

Development

# Get a comprehensive list of development tools
just --list

pip-tree's People

Contributors

borda avatar justintime50 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pip-tree's Issues

Improve Performance Speed of Generating Report

Pip Tree takes awhile to run, this is mostly due to the pip show <package> command taking about a half second for each package. This can very quickly add up.

Look into performance gains with Pip Tree by optimizing the code itself and also consider adding concurrently calling each command, appending each to the list, and at the end, sort the list by package name.

Switch from Shelling out to Pip to Using the Native Pip Module

Of course, the beauty of using Python for this project means we can access the native Pip module...

from pip._internal.utils.misc import get_installed_distributions

for package in get_installed_distributions:
    print(package)
    print(package.requires)

This will improve the performance of this tool dramatically (#2) and is much safer than shelling out.

Allow Extra Package Indexes to Be Set

By default, only the standard PyPi site will be used as the package index. We can add more indexes to check against with the following options on the list command.

Package Index Options:
  -i, --index-url <url>       Base URL of the Python Package Index (default https://pypi.org/simple). This should point to a repository compliant with PEP 503 (the simple repository API) or a local directory laid out in the same format.
  --extra-index-url <url>     Extra URLs of package indexes to use in addition to --index-url. Should follow the same rules as --index-url.
  --no-index                  Ignore package index (only looking at --find-links URLs instead).
  -f, --find-links <url>      If a URL or path to an html file, then parse for links to archives such as sdist (.tar.gz) or wheel (.whl) files. If a local path or file:// URL that's a directory,  then look for archives in the directory listing. Links to VCS project URLs
                              are not supported.

Add Dependency Depth Option

It may be cool to add an option where you can determine the depth of the tree. Currently the tool only goes one layer deep (getting all packages for the virtual env you specify and what packages they require: 2-levels deep). What this doesn't allow for is going even further (3+ levels deep) to see what packages of packages of packages require.

DeprecationWarning: pkg_resources is deprecated as an API

venv/lib/python3.11/site-packages/pkg_resources/__init__.py:121
  /Users/jhammond/git/personal/pip-tree/venv/lib/python3.11/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
    warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.