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

Retrieve licenses from other environment #149

Closed
ClementPinard opened this issue Mar 21, 2023 · 0 comments · Fixed by #150
Closed

Retrieve licenses from other environment #149

ClementPinard opened this issue Mar 21, 2023 · 0 comments · Fixed by #150

Comments

@ClementPinard
Copy link
Contributor

Somehow related to #107

Currently, we can only get packages from the environments we are running pip-licenses on. This is a problem for two reasons

  • As said in mentioned issue, we cannot use it as a pre-commit hook easily. There is the possibility to use a hook within the activated environment, but it's clearly not following its guidelines
  • Using this libraries implies installing it in your venv, and thus contaminating it by installing packages you wouldn't need otherwise. It's no great given the purpose of this lib is to identify licenses of installed packages

I think there is a simple fix to this.

Indeed, thepckages are discovered via importlib distributions() function. As it can be seen here : https://github.com/raimon49/pip-licenses/blob/master/piplicenses.py#L193

By looking at the documentation and code of importlib, it seems to me that distributions should accept a path argument with a list of folders to search into.
See
https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.distributions

and https://github.com/python/importlib_metadata/blob/700f2c7d74543e3695163d5487155b92e6f04d65/importlib_metadata/__init__.py#L809

distributions(**kwargs) calls Distribution.discover(**kwargs) which expects either a Context object or its args for creating one (see https://github.com/python/importlib_metadata/blob/700f2c7d74543e3695163d5487155b92e6f04d65/importlib_metadata/__init__.py#L387 )

All in all, calling distributions([folder_path]) will retrieve all packages metadata in the given folder_path which could be a CLI parameter.

What do you think ?

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

Successfully merging a pull request may close this issue.

1 participant