Skip to content

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

Closed
wants to merge 8 commits into from

Conversation

mattip
Copy link
Contributor

@mattip mattip commented Feb 23, 2021

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

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()
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Member

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"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adopted impllibdir

@mattip
Copy link
Contributor Author

mattip commented Feb 24, 2021

I think this can get a "skip news" label.

@merwok
Copy link
Member

merwok commented Feb 24, 2021

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()
Copy link
Member

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
Comment on lines 134 to 139
# 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'
Copy link
Member

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()?

Copy link
Contributor Author

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.

@mattip
Copy link
Contributor Author

mattip commented Mar 1, 2021

CI is passing. This is ready for another review.

@github-actions
Copy link

github-actions bot commented Apr 1, 2021

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Apr 1, 2021
@mattip
Copy link
Contributor Author

mattip commented Apr 1, 2021

@tiran, @merwok is there something I should do here?

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Apr 2, 2021
Comment on lines +62 to +75
_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'

Copy link
Member

@tiran tiran Apr 22, 2021

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.

Suggested change
_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'

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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).

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

@tiran tiran requested review from brettcannon and methane April 22, 2021 17:40
Copy link
Member

@brettcannon brettcannon left a 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.

@merwok merwok changed the title bpo-43307: sync sysconfig/site.py with PyPy to add an implementation key bpo-43307: sync sysconfig and site with PyPy to add an implementation key Apr 28, 2021
@merwok
Copy link
Member

merwok commented Apr 28, 2021

A small question: is the PR title (which will become the commit message) still accurate?
With the new implibdir variable and the requested changes, is this still a sync/port, or is it a new version that could be used by CPython and PyPy?

@mattip
Copy link
Contributor Author

mattip commented Jun 15, 2021

Closing this, a PR is not the right place to get a consensus across

  • cpython, pypy, ...
  • distros: windows, debian, bsd, gentoo, darwin, ...
  • installers such as virtualenv/venv, conda, ...
  • desires for custom schema for performance and out-of-interpreter use in places like site.py, cross-compiling, conda installations, ...

I thought I could reduce the dimensionality of the problem by removing the implementation from the equation but it seems not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants