raimon49 / pip-licenses

Dump the license list of packages installed with pip.
MIT License
298 stars 42 forks source link

Treat `-` and `_` as equivalent in package names #160

Closed KennyChenBasis closed 1 year ago

KennyChenBasis commented 1 year ago

pip treats - and _ as equivalent, but pip-licenses differentiates between the two when using the -p flag. Having pip-licenses also treat - and _ as equivalent makes it easier to work with.

In my particular use case, I have a venv that contains packages from a requirements.txt and also additional packages that I don't want licenses of. I then passed the packages in the requirements.txt to pip-licenses -p and was surprised when the license for typing-extensions wasn't found. However, passing typing_extensions instead to pip-licenses works.

requirements.txt in this form can be created from, e.g. pipenv requirements.

raimon49 commented 1 year ago

Thanks, I checked the specs on package name normalization. https://peps.python.org/pep-0503/#normalized-names

I'd like to normalize the options that accept package names in pip-licenses as well.

raimon49 commented 1 year ago

@KennyChenBasis We have shipped version 4.3.1, which fix this issue. https://pypi.org/project/pip-licenses/4.3.1/

Please check if it works as you expect using v4.3.1.

pip install pip-licenses=="4.3.1"
KennyChenBasis commented 1 year ago

Looks like it works; thanks for the timely response and fix!

ogencoglu commented 12 months ago

How do we list the licenses from requirements.txt?

pip-licenses -p requirements.txt returns an empty list in venv even though those libraries are installed in venv.

stefan6419846 commented 12 months ago

pip-licenses -p requirements.txt yields no results as there is no package requirements.txt. From the description of the -p parameter:

only include selected packages in output

So you would have to pass your desired packages by their name explicitly or find a Shell-specific way to extract the package names from your requirements file automatically.