-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix site.getsitepackages() broken on python2 on debian #2108
Conversation
Can you rebase on the master and fix the merge conflict? Thanks! |
sitepackages = orig_getsitepackages() | ||
for prefix in (sys.prefix, sys.exec_prefix): | ||
# os is not defined here, but will be in site.py, where we monkey-patch this function. | ||
path = os.path.join(prefix, "lib", "python" + sys.version[:3], "site-packages") # noqa: F821 |
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.
You can't write code like this, that's platform dependent. You must detect if you're on debian and execute this only then.
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.
Oh. Right. I forgot the check. I think checking for linux should be enough though, as non debian linux will already contain the path, so if path not in sitepackages
will be False.
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.
The code now does the same check the debians patched site.py does. This prevents the code from running on systems where it would break.
It will still run on non-debian systems, but shouldn't have any effect there. I don't think specifically detecting debian would be practical.
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.
Oh. Right. I forgot the check. I think checking for linux should be enough though, as non debian linux will already contain the path, so
if path not in sitepackages
will be False.
That's some very presumptions statement there. What stops macOS from patching similarly as does Debian? Or any other distribution? We really must restrict this to Debian only.
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 think that this should also handle all cases where an OS patches python in a way similar to debian.
The added path isn't debian specific. It is virtualenv specific and should always be in getsitepackages. The problem is just that because of debians patches it isn't.
The only thing I would have to fix is use ___EXPECTED_SITE_PACKAGES___
instead of hardcoding "site-packages".
I can however try restricting it to debian to be save.
Detecting debian and it derivatives isn't easy though. Just checking if platform.dist
is debian isn't enough as we also need to detect Ubuntu and other derivatives.
After looking through all the debian patches I think the best way would be to detect the "deb_system" key in distutils.command.install.INSTALL_SCHEMES
.
Alternatively it would be possible to search for occurrences of "dist-packages" in the source of getsitepackages.
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.
The only thing I would have to fix is use
___EXPECTED_SITE_PACKAGES___
instead of hardcoding "site-packages".
This might suffice.
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.
If you can do this then 👍
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 just pushed a new version. I pulled some code from load_host_site
into a new function to reuse it in rewrite_getsitepackages
.
Because the code now makes no assumptions about the operating system other than what is already assumed by load_host_site
I removed the os check.
6f50ebf
to
40c2751
Compare
Codecov Report
@@ Coverage Diff @@
## main #2108 +/- ##
=======================================
Coverage 93.70% 93.70%
=======================================
Files 88 88
Lines 4385 4385
=======================================
Hits 4109 4109
Misses 276 276
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
59e206c
to
87ba615
Compare
sitepackages = orig_getsitepackages() | ||
for prefix in (sys.prefix, sys.exec_prefix): | ||
# os is not defined here, but will be in site.py, where we monkey-patch this function. | ||
path = os.path.join(prefix, "lib", "python" + sys.version[:3], "site-packages") # noqa: F821 |
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.
Oh. Right. I forgot the check. I think checking for linux should be enough though, as non debian linux will already contain the path, so
if path not in sitepackages
will be False.
That's some very presumptions statement there. What stops macOS from patching similarly as does Debian? Or any other distribution? We really must restrict this to Debian only.
sitepackages = orig_getsitepackages() | ||
for prefix in (sys.prefix, sys.exec_prefix): | ||
# os is not defined here, but will be in site.py, where we monkey-patch this function. | ||
path = os.path.join(prefix, "lib", "python" + sys.version[:3], "site-packages") # noqa: F821 |
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.
If you can do this then 👍
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'll approve if you manage to get the CI working.
I'm currently looking into it. It seems to be a kind of bootstrap problem, where currently it only fails if the tests are run inside a virtualenv that already contains this PR, due to the way I get the system site-packages to test against. |
CI should pass now. Looks like one of the runs is locked up though. |
38e2050
to
b5a3948
Compare
I retriggered the CI with an empty commit and everything works now. |
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.
Released via https://pypi.org/project/virtualenv/20.4.6/ |
Thanks! |
Fixes #2105.
This PR also adds a regression test.
There might be a merge conflict between this PR and #2107, because they both add a test to the end of tests/unit/create/test_creator.py