reynoldsnlp / pipster

pipster: The pythonic way to `pip install`.
MIT License
8 stars 2 forks source link

make `_parse_target` more robust #16

Closed reynoldsnlp closed 1 year ago

reynoldsnlp commented 1 year ago

Converting whl filenames and requirement specifiers to distribution names is working, but I suspect that pip has more robust functions that we can import and use.

reynoldsnlp commented 1 year ago

I'm not sure handling URLs (pip install git+https://github.com/user/pkg.git) is reasonable, but if pip has a function for that, it would be nice.

reynoldsnlp commented 1 year ago

@ncoghlan @pfmoore @pradyunsg I need to get the distribution name from whatever argument is given after pip install, and I assume that pip internals would have a function that would do a better job than mine.

I poked around and found a regular expression for parsing whl filenames that I implemented here but I wasn't able to find where in pip's code a requirement specifier like my-pkg~=3.2.1 is parsed into distribution name, version, etc.

pradyunsg commented 1 year ago

You want packaging.requirement.Requirement for things that aren't direct paths.

For filesystem paths, you either get a file or a directory. For files, there's packaging.utils functions for parsing wheel and sdist names. For directories, there's no way to know the package name without doing a build.