-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix broken installation on Windows in virtualenv #4149
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
Conversation
@ethanhs Can you review/test this? |
mypy/build.py
Outdated
@@ -229,7 +229,7 @@ def default_data_dir(bin_dir: Optional[str]) -> str: | |||
""" | |||
if not bin_dir: | |||
if os.name == 'nt': | |||
prefixes = [os.path.join(sys.prefix, 'Lib'), os.path.join(site.getuserbase(), 'lib')] | |||
prefixes = [os.path.join(sys.prefix, 'Lib'), os.path.join(get_python_lib(), 'lib')] |
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.
Sadly, this will not work on pip's --user
installs. It might be better to trysite.getuserbase()
, then fall back on sysconfig's get_python_lib, so it is only invoked in virtualenvs.
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.
That is too bad.
Do you think that the following solution could do the trick?
getattr(site, 'getuserbase', None)
prefixes = [
os.path.join(sys.prefix, 'Lib'),
os.path.join(getattr(site, 'getuserbase', get_python_lib)(), 'lib')
]
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.
Hm, I think the getattr call, while concise, is a bit opaque and not obvious. I think
prefixes = [os.path.join(sys.prefix, 'Lib')]
try:
prefixes.append(os.path.join(site.getuserbase(), 'lib')
except AttributeError:
prefixes.append(os.path.join(get_python_lib(), 'lib')
or perhaps
prefixes = [os.path.join(sys.prefix, 'Lib')]
if hasattr(site, 'getuserbase'):
prefixes.append(os.path.join(site.getuserbase(), 'lib')
else:
prefixes.append(os.path.join(get_python_lib(), 'lib')
would be much more readable.
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.
Your suggestion looks way more readable, thanks!
Will implement it soonTM (in about 12 hours).
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.
Also, if you could, explain why we fall back on get_python_lib
please. eg in the except/else branch
# getuserbase not available in virtualenvs
Thanks so much for fixing this!
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.
No problem, glad to help and thanks for your quick feedback!
Fixes python#4142. Python `site.py` from any virtualenv does not contain many functions added in python 2.7 (see: pypa/virtualenv#355), which results in method `site.getsitepackages` being absent. This commit replaces getsitepackages call with equivalent of `distutils.sysconfig.get_python_lib` which is supported in virtualenv.
6a52d4a
to
ed244b7
Compare
Ping |
Ping what?
…On Oct 25, 2017 3:19 AM, "Aleksander Gondek" ***@***.***> wrote:
Ping
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4149 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACwrMm2p-kg9z8UwTHiHv9uzBoEJCs1hks5svwshgaJpZM4QB-yG>
.
|
I was just wondering if we could merge the change - I have adjusted it accordingly to ethanhs advice. |
We're all volunteers here -- Ethan will get to it when he gets to it, and
it will make it into the release that follows. (So yes, a bit too pushy.)
|
Apologies - I have not intended to be disrespectful. I fully appreciate free time put into the project. I will now cease to spam and thanks for clarifying things for me . |
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.
Thank you for fixing this.
Fixes #4142. Python `site.py` from any virtualenv does not contain many functions added in python 2.7 (see: pypa/virtualenv#355), which results in method `site.getsitepackages` being absent. This commit replaces getsitepackages call with equivalent of `distutils.sysconfig.get_python_lib` which is supported in virtualenv.
Fixes #4142
Python
site.py
from any virtualenv does not contain many functions added in python 2.7 (see: pypa/virtualenv#355), which results in methodsite.getsitepackages
being absent.This commit replaces getsitepackages call with equivalent of
distutils.sysconfig.get_python_lib
which is supported in virtualenv.