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

refactor the non_host part for not injecting to custom env #346

Merged
merged 3 commits into from
Apr 10, 2024

Conversation

xiacunshun
Copy link
Collaborator

fix: #343

We can get the sitepackages directory from the given interpreter directly instead of running our code again with it.

@xiacunshun
Copy link
Collaborator Author

I think the result of this method is the same with the original one. Please take a look if you have time. @kemzeb

gaborbernat
gaborbernat previously approved these changes Apr 6, 2024
src/pipdeptree/_discovery.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@kemzeb kemzeb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I noticed that when we're using a venv that has system site packages enabled (i.e. I did python -m venv --system-site-packages venv), running the following:

pipdeptree --python path/to/python --local-only

...would cause us to hit the else branch (since I am not running in a virtual environment). We don't want this since we will use paths to metadata from the entire environment.

I think what we need to do here is if --python and --local are given, we should grab the result of:

"str(py_path), "-c", "import sys, site; print(site.getsitepackages([sys.prefix]))"

...and pass it to distributions(). Otherwise, use sys.path.

src/pipdeptree/_discovery.py Outdated Show resolved Hide resolved
@xiacunshun
Copy link
Collaborator Author

Hmm, I noticed that when we're using a venv that has system site packages enabled (i.e. I did python -m venv --system-site-packages venv), running the following:

pipdeptree --python path/to/python --local-only

...would cause us to hit the else branch (since I am not running in a virtual environment). We don't want this since we will use paths to metadata from the entire environment.

I think what we need to do here is if --python and --local are given, we should grab the result of:

"str(py_path), "-c", "import sys, site; print(site.getsitepackages([sys.prefix]))"

...and pass it to distributions(). Otherwise, use sys.path.

That's a really good situation which I didn't notice. I will add some tests to cover this too.

@xiacunshun xiacunshun force-pushed the fix_non_host_env branch 3 times, most recently from acbf7af to 8c54c10 Compare April 7, 2024 01:35
src/pipdeptree/_discovery.py Outdated Show resolved Hide resolved
src/pipdeptree/_discovery.py Outdated Show resolved Hide resolved
tests/test_non_host.py Show resolved Hide resolved
tests/test_non_host.py Outdated Show resolved Hide resolved
@xiacunshun xiacunshun force-pushed the fix_non_host_env branch 4 times, most recently from a1b013d to 76ff513 Compare April 8, 2024 13:12
src/pipdeptree/_discovery.py Outdated Show resolved Hide resolved
@kemzeb
Copy link
Collaborator

kemzeb commented Apr 8, 2024

FYI once we merge this I'll make a 2.18.0 release.

@xiacunshun xiacunshun force-pushed the fix_non_host_env branch 2 times, most recently from d11e5e2 to 6432873 Compare April 9, 2024 02:57
tests/test_non_host.py Outdated Show resolved Hide resolved
tests/test_discovery.py Outdated Show resolved Hide resolved
@kemzeb
Copy link
Collaborator

kemzeb commented Apr 9, 2024

Can't see any other issues, so it looks like this is good to go. Will release 2.18.0 after merging

kemzeb
kemzeb previously approved these changes Apr 9, 2024
src/pipdeptree/_discovery.py Outdated Show resolved Hide resolved
@gaborbernat gaborbernat merged commit 25cbb6f into tox-dev:main Apr 10, 2024
10 checks passed
@kemzeb
Copy link
Collaborator

kemzeb commented Apr 10, 2024

Looks like we're good to go, releasing 2.18.0

@xiacunshun xiacunshun deleted the fix_non_host_env branch April 10, 2024 17:02
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 this pull request may close these issues.

test_custom_interpreter fails
3 participants