-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add --python
option
#150
Add --python
option
#150
Conversation
here is how you can use it if you want licenses (and version numbers) from another environment. This would be particularly useful in a CI where you want exact license and versions of your project dependencies, which could be clashing with pip-licenses's dependencies (even though they are minimal) source /path/to/venv/bin/activate
/path/to/pip-licenses --path $(python -c "import sys; print(','.join(filter(bool, sys.path)))") this would be particularly interesting with pip-licenses installed in you system python example with poetry pip install pip-licences
source `poetry env info --path`/bin/activate
pip-licenses --path $(python -c "import sys; print(','.join(filter(bool, sys.path)))") |
I've seen other tools allow for a |
So I guess launching another python from subprocess ? and then getting back the printed sys.path ? That would be possible indeed ! I'll try to come up with something that uses both |
@ClementPinard I read #149 and using |
I am not sure if I should merge this PR and include it in the next release 4.2.0. Is the implementation of the |
Hey, From that we can work on potential review comments, and I think the feature will be complete. |
So I said I would keep both I you need to get licenses from an extra folder, you might as well install the package with As a result, I decided to only keep the @raimon49 I now think this PR is finished, and open for review. |
Codecov Report
@@ Coverage Diff @@
## master #150 +/- ##
==========================================
- Coverage 99.74% 99.50% -0.24%
==========================================
Files 1 1
Lines 392 408 +16
==========================================
+ Hits 391 406 +15
- Misses 1 2 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
#### Option: python | ||
|
||
By default, this tools finds the packages from the environment pip-licenses is launched from, by searching in current python's `sys.path` folders. In the case you want to search for packages in an other environment (e.g. if you want to run pip-licenses from its own isolated environment), you can specify a path to a python executable. The packages will be searched for in the given python's `sys.path`, free of pip-licenses dependencies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also checked the importlib_metadata source code. It was using sys.path
by default as you described 👍
There is a ToC at the top of the README document. Could you also add a link to "Option: python"?
if args.python == sys.executable: | ||
search_paths = sys.path | ||
else: | ||
search_paths = get_python_sys_path(args.python) | ||
|
||
pkgs = importlib_metadata.distributions(path=search_paths) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To resolve the points that Codecov points out, we need a test case that mocks the call to importlib_metadata.distributions()
, for example. Any ideas on how to do this?
Of course, it is preferable to have test cases, but if it is too difficult, I will merge the PR as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting to that L203 is not covered, I would have thought that the L202 would not be covered since we don't test other python environments
I add a test that creates a temporary empty virtual env, and thus should only find pip and setuptools. I had some troubles figuring out why it still found all packages in main virtual environment, and solved this problem by calling the alternative python executable with empty environment variables for output = subprocess.run(
[executable, "-c", script],
capture_output=True,
env={**os.environ, "PYTHONPATH": "", "VIRTUAL_ENV": ""},
) Would there be some usecase where keeping them is actually important ? FYI, not resetting |
Oh, it had never occurred to me that this was the way to do it. I consider it a good enough test case. Why are CI tests failing only in the Python 3.8 environment? |
Looks like I was not typehinting the right way. The venvBuilder context is a I put back the original type in the typehinbt and we should be good to go. If not, I'll just remove the typehint altogether. |
@ClementPinard Thank you for your great contribution! I will merge this PR into the next release candidate version. |
pip-licenses version 4.2.0 RC2 is now available. This PR includes. If you have any concerns about the actual use of the system, please provide feedback. Thanks. $ pip install "pip-licenses==4.2.0rc2" |
Fixes #149
Still Work in Progress, happy to receive feedback !
Not particularly happy with the fact that you have to specify until the
site-packages
folder and not just the venv folder. suggestions welcome.