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

pip index show command which fetches the package information via the JSON API #10470

Open
1 task done
ashwinvis opened this issue Sep 14, 2021 · 6 comments
Open
1 task done
Labels
resolution: needs standard Should be agreed as a standard before implementation type: feature request Request for a new feature

Comments

@ashwinvis
Copy link

What's the problem this feature will solve?

Now that pip search is not working and would be removed in favour of pip index versions in #10431 , there is short description is not accessible from the command line. This is an opportunity to re-imagine the command.

Describe the solution you'd like

If numpy is installed in the environment, the following description is obtained

$ pip show numpy
Name: numpy
Version: 1.21.2
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: 
License: BSD
Location: /home/avmo/.pyenv/versions/3.8.9/envs/snek/lib/python3.8/site-packages
Requires: 
Required-by: xarray, pandas, matplotlib, h5py

Say, numpy is not installed in the user environment.

$ pip show numpy
WARNING: Package(s) not found: numpy

The user would like to read the documentation, but only knows the name of the package. An output like this would be helpful

$ pip index show numpy
Name: numpy
Version: 1.21.2
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: 
License: BSD
Location: < irrelevant >
Requires: 
Required-by:  < hard to deduce? >

Such an output can be populated from the JSON API

curl -s https://pypi.org/pypi/numpy/json | jq .info
{
  "author": "Travis E. Oliphant et al.",
  "author_email": "",
  "bugtrack_url": null,
  "classifiers": [
    "Development Status :: 5 - Production/Stable",
    "Intended Audience :: Developers",
    "Intended Audience :: Science/Research",
    "License :: OSI Approved :: BSD License",
    "Operating System :: MacOS",
    "Operating System :: Microsoft :: Windows",
    "Operating System :: POSIX",
    "Operating System :: Unix",
    "Programming Language :: C",
    "Programming Language :: Python",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3 :: Only",
    "Programming Language :: Python :: 3.7",
    "Programming Language :: Python :: 3.8",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: 3.10",
    "Programming Language :: Python :: Implementation :: CPython",
    "Topic :: Scientific/Engineering",
    "Topic :: Software Development",
    "Typing :: Typed"
  ],
  "description": "It provides:\n\n- a powerful N-dimensional array object\n- sophisticated (broadcasting) functions\n- tools for integrating C/C++ and Fortran code\n- useful linear algebra, Fourier transform, and random number capabilities\n- and much more\n\nBesides its obvious scientific uses, NumPy can also be used as an efficient\nmulti-dimensional container of generic data. Arbitrary data-types can be\ndefined. This allows NumPy to seamlessly and speedily integrate with a wide\nvariety of databases.\n\nAll NumPy wheels distributed on PyPI are BSD licensed.\n\n\n\n",
  "description_content_type": "",
  "docs_url": null,
  "download_url": "https://pypi.python.org/pypi/numpy",
  "downloads": {
    "last_day": -1,
    "last_month": -1,
    "last_week": -1
  },
  "home_page": "https://www.numpy.org",
  "keywords": "",
  "license": "BSD",
  "maintainer": "NumPy Developers",
  "maintainer_email": "[email protected]",
  "name": "numpy",
  "package_url": "https://pypi.org/project/numpy/",
  "platform": "Windows",
  "project_url": "https://pypi.org/project/numpy/",
  "project_urls": {
    "Bug Tracker": "https://github.com/numpy/numpy/issues",
    "Documentation": "https://numpy.org/doc/1.21",
    "Download": "https://pypi.python.org/pypi/numpy",
    "Homepage": "https://www.numpy.org",
    "Source Code": "https://github.com/numpy/numpy"
  },
  "release_url": "https://pypi.org/project/numpy/1.21.2/",
  "requires_dist": null,
  "requires_python": ">=3.7,<3.11",
  "summary": "NumPy is the fundamental package for array computing with Python.",
  "version": "1.21.2",
  "yanked": false,
  "yanked_reason": null
}

Alternative Solutions

Alternatively, simply pretty print the JSON after fetching it.

Right now I use https://github.com/jeffmm/pypi-simple-search/ to mimic the old pip search behaviour.

Additional context

The inspiration for this command is how pacman in ArchLinux works.

  • pacman -Qi <package>: to query an installed package for information
  • pacman -Si <package>: to query the package index for information

Code of Conduct

@ashwinvis ashwinvis added S: needs triage Issues/PRs that need to be triaged type: feature request Request for a new feature labels Sep 14, 2021
@uranusjr uranusjr added resolution: needs standard Should be agreed as a standard before implementation and removed S: needs triage Issues/PRs that need to be triaged labels Sep 14, 2021
@uranusjr
Copy link
Member

The JSON API is not standardised, and our current principle is to only implements new features with a backing standard (old features are kept for compatibility). So you should push for the JSON API’s standardisation first.

See https://discuss.python.org/t/9205 for discussion on this.

@pfmoore
Copy link
Member

pfmoore commented Sep 14, 2021

Also, why is it necessary to implement this in pip when a 1-liner using curl and jq like you show gives the results so easily? (For people without curl or jq, a few lines of Python would give something similar).

@ashwinvis
Copy link
Author

@uranusjr Then we wait for the standard.

@pfmoore Displaying package description is a common feature of all package managers (not just pacman, but apt search, cargo search, and so on). I would assume others would like to have that information before they install the package. I don't see the benefit of a third party tool just to query the JSON API.

@pfmoore
Copy link
Member

pfmoore commented Sep 14, 2021

I guess that begs the question of whether pip is a "package manager". I've always thought of it as an "installer" rather than a broader tool. But I can see why framing it as a package manager makes sense.

@mikedlr
Copy link

mikedlr commented Nov 15, 2022

The reason for this command is that I would like to know what pip would do on an install before I do it. Right now I know of no way to predict the result of pip install unknown-and-maybe-dodgy-package except maybe doing pip download beforehand. What I'd like is to be able to run

pip info unknown-and-maybe-dodgy-package

and see at least

  • name of package
  • checksum of package to be installed
  • url of documentation for package

so that I have enough information to go away and check that this package is the one that I meant to install.

BTW. I would propose "info" as an alias (or even primary name) for this which would match with RedHat's dnf command. For apt, show uses the network.

@ashwinvis
Copy link
Author

see at least

* name of package

* checksum of package to be installed

* url of documentation for package

To do all of that the only way seems to be making a JSON API call (as I showed above) or visiting the PyPI project page (for example https://pypi.org/project/numpy/#files). If you only care about the dependencies and the checksums / hashes, you could use "pip-tools" by creating a requirements.in file and executing pip-compile --generate-hashes.

I know this is not the answer @mikedlr or me is looking for, but as a stop gap measure, hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution: needs standard Should be agreed as a standard before implementation type: feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

4 participants