-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-43307: sync sysconfig and site with PyPy to add an implementation key #24628
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
6d67e16
to
9cbdac8
Compare
Lib/sysconfig.py
Outdated
@@ -569,6 +576,8 @@ def get_config_vars(*args): | |||
except AttributeError: | |||
# sys.abiflags may not be defined on all platforms. | |||
_CONFIG_VARS['abiflags'] = '' | |||
_CONFIG_VARS['implementation'] = _get_implementation() | |||
_CONFIG_VARS['implementation_lower'] = _get_implementation().lower() |
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.
Not sure if this is the correct name; we do have sys.implementation
with names like cpython
, jython
, etc. The usage here seems different, more like a directory name to find libraries.
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.
What would be a better name? We need something that maps like CPython -> python
, PyPy -> pypy
. I don't know what Pyston/Jython/Graal python use, maybe some of them want to reuse the python
name?
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.
My point is that cpython
is an implementation name, Python
isn’t.
Better name: any idea if we don’t look at the values but the usage? Isn’t it the name for a directory containing libraries or modules?
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 agree, implementation
does not fit well. There is platlibdir
. How about something like impllibdir
for "implementation library directory"?
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.
Adopted impllibdir
I think this can get a "skip news" label. |
I would disagree, this change should be in what’s new so that interested parties can be notified. |
Lib/sysconfig.py
Outdated
@@ -569,6 +576,8 @@ def get_config_vars(*args): | |||
except AttributeError: | |||
# sys.abiflags may not be defined on all platforms. | |||
_CONFIG_VARS['abiflags'] = '' | |||
_CONFIG_VARS['implementation'] = _get_implementation() | |||
_CONFIG_VARS['implementation_lower'] = _get_implementation().lower() |
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 agree, implementation
does not fit well. There is platlibdir
. How about something like impllibdir
for "implementation library directory"?
Lib/sysconfig.py
Outdated
# NOTE: site.py has copy of this function. | ||
# Sync it when modify this function. | ||
def _get_implementation(): | ||
if '__pypy__' in sys.builtin_module_names: | ||
return 'PyPy' | ||
return 'Python' |
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.
Would it be possible to import site
here and use the site._get_implementation()
?
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 functionality is only in site.py
for a performance tweak.
sysconfig and it's dependencies are relatively large but site module needs very limited part of them. To speedup startup time, we have copy of them.
Maybe we should remove the performance tweak instead? site.py
already imports os, so I wonder if the statement is still true.
CI is passing. This is ready for another review. |
This PR is stale because it has been open for 30 days with no activity. |
_is_pypy = '__pypy__' in sys.builtin_module_names | ||
|
||
# NOTE: site.py has copy of this function. | ||
# Sync it when modify this function. | ||
def _get_impllibdir(os_name): | ||
if not _is_pypy and os_name != 'nt': | ||
return 'python' | ||
elif not _is_pypy and os_name == 'nt': | ||
return 'Python' | ||
elif _is_pypy and os_name != 'nt': | ||
return 'pypy' | ||
elif _is_pypy and os_name == 'nt': | ||
return 'PyPy' | ||
|
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.
Is there any reason why you have duplicated the code instead of importing them from site
? The site module is almost always imported at startup.
_is_pypy = '__pypy__' in sys.builtin_module_names | |
# NOTE: site.py has copy of this function. | |
# Sync it when modify this function. | |
def _get_impllibdir(os_name): | |
if not _is_pypy and os_name != 'nt': | |
return 'python' | |
elif not _is_pypy and os_name == 'nt': | |
return 'Python' | |
elif _is_pypy and os_name != 'nt': | |
return 'pypy' | |
elif _is_pypy and os_name == 'nt': | |
return 'PyPy' | |
_is_pypy = '__pypy__' in sys.builtin_module_names | |
# NOTE: site.py has copy of this function. | |
# Sync it when modify this function. | |
def _get_impllibdir(os_name): | |
if _is_pypy: | |
return 'PyPy' if os_name == 'nt' else 'pypy' | |
else: | |
return 'Python' if os_name == 'nt' else 'python' |
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 the design is that the site module can be overridden by the user, so it cannot be the canonical source of information. I think the sysconfig code was originally copied to prevent site.py importing sysconfig.py during startup, which would slow things down. I was just following that usage pattern.
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.
Do you have references for that? sitecustomize
is for custom behaviour, but I don’t see that site
is meant to be replaced.
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 could see a bootstrap problem though, for example during Python build we may need sysconfig but can’t import site (that needs modules such as io and others).
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be poked with soft cushions! |
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.
Nothing to add beyond what Christian already asked about the code duplication.
A small question: is the PR title (which will become the commit message) still accurate? |
Closing this, a PR is not the right place to get a consensus across
I thought I could reduce the dimensionality of the problem by removing the implementation from the equation but it seems not. |
PyPy has extended the INSTALL_SCHEMA to add handling multiple implementations. This is a backport of these changes. Additionally, tweak the license stanza in site.py (as long as I was syncing).
https://bugs.python.org/issue43307