Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide API for pip show info by invoking pip as a subprocess (and offer to contribute) #55

Open
stevecj opened this issue Oct 13, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@stevecj
Copy link

stevecj commented Oct 13, 2020

I recently needed to read information from a requirements file and a frozen constraints file (which I did using pip-api and works wonderfully — thanks) and then walk the tree of dependencies to identify installed packages that are directly or implicitly required by those in the requirements file.

Walking through the dependency hierarchy requires information from pip show, so I wrote code to obtain that information by running pip show in a subprocess and parsing its textual output. I think that capability would make a nice addition to the pip-api package.

Is there interest in having me contribute that functionality?

Any preferences regarding what the Python API should look like for this?

@di
Copy link
Owner

di commented Oct 13, 2020

Hi @stevecj, thanks for the feature request. TL;DR: yes.

The purpose of this package to providing a drop-in replacement for existing uses of pip's internal API by wrapping command-line calls to pip. It looks like a function that replaces the pip._internal.commands.show.search_packages_info would be the function we'd want to replace by wrapping pip show.

This internal function takes a list of package names like ['six'] and yields a dictionary like:

{
    "name": "six",
    "version": "1.14.0",
    "location": "/Users/dustiningram/.pyenv/versions/3.8.2/lib/python3.8/site-packages",
    "requires": [],
    "required_by": [
        "virtualenv",
        "uncurl",
        "twilio",
        "tweepy",
        "tox",
        "readme-renderer",
        "python-frontmatter",
        "pip-tools",
        "bleach",
    ],
    "installer": "pip",
    "metadata-version": "2.1",
    "summary": "Python 2 and 3 compatibility utilities",
    "home-page": "https://github.com/benjaminp/six",
    "author": "Benjamin Peterson",
    "author-email": "[email protected]",
    "license": "MIT",
    "classifiers": [
        "Development Status :: 5 - Production/Stable",
        "Programming Language :: Python :: 2",
        "Programming Language :: Python :: 3",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: MIT License",
        "Topic :: Software Development :: Libraries",
        "Topic :: Utilities",
    ],
    "files": [
        "__pycache__/six.cpython-38.pyc",
        "six-1.14.0.dist-info/INSTALLER",
        "six-1.14.0.dist-info/LICENSE",
        "six-1.14.0.dist-info/METADATA",
        "six-1.14.0.dist-info/RECORD",
        "six-1.14.0.dist-info/WHEEL",
        "six-1.14.0.dist-info/top_level.txt",
        "six.py",
    ],
}

It looks like we can get all of this if using the following:

$ pip show -f --verbose six
Name: six
Version: 1.14.0
Summary: Python 2 and 3 compatibility utilities
Home-page: https://github.com/benjaminp/six
Author: Benjamin Peterson
Author-email: [email protected]
License: MIT
Location: /Users/dustiningram/.pyenv/versions/3.8.2/lib/python3.8/site-packages
Requires:
Required-by: virtualenv, uncurl, twilio, tweepy, tox, readme-renderer, python-frontmatter, pip-tools, bleach
Metadata-Version: 2.1
Installer: pip
Classifiers:
  Development Status :: 5 - Production/Stable
  Programming Language :: Python :: 2
  Programming Language :: Python :: 3
  Intended Audience :: Developers
  License :: OSI Approved :: MIT License
  Topic :: Software Development :: Libraries
  Topic :: Utilities
Entry-points:
Files:
  __pycache__/six.cpython-38.pyc
  six-1.14.0.dist-info/INSTALLER
  six-1.14.0.dist-info/LICENSE
  six-1.14.0.dist-info/METADATA
  six-1.14.0.dist-info/RECORD
  six-1.14.0.dist-info/WHEEL
  six-1.14.0.dist-info/top_level.txt
  six.py

Any preferences regarding what the Python API should look like for this?

I think this should mimic search_packages_info as much as possible. I'd imagine the docs for this would look something like:

  • pip_api.search_packages_info(List[str]: query) -> Iterator[Dict[str, src]]

    Takes a list of package names. Yields a dict for each matching package with the following fields:

    • name (string): The name of the installed distribution
    • ...

@di di added the enhancement New feature or request label Oct 13, 2020
@stevecj
Copy link
Author

stevecj commented Oct 13, 2020

Acknowledged. 🙂

@stevecj
Copy link
Author

stevecj commented Oct 25, 2021

I started on this quite a while ago and then got swamped with other things. Hopefully, I will eventually get back to it and make an MR. If anyone wants to beat me to it, feel free though. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants