Skip to content

bpo-43307: sync sysconfig and site with PyPy to add an implementation key - #24628

Closed
mattip wants to merge 8 commits into
python:mainfrom
mattip:sysconfig-sync
Closed

bpo-43307: sync sysconfig and site with PyPy to add an implementation key#24628
mattip wants to merge 8 commits into
python:mainfrom
mattip:sysconfig-sync

Conversation

@mattip

@mattip mattip commented Feb 23, 2021

Copy link
Copy Markdown
Contributor

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

Comment thread Lib/site.py Outdated
Comment thread Lib/sysconfig.py Outdated
# 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

mattip commented Feb 24, 2021

Copy link
Copy Markdown
Contributor Author

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

@merwok

merwok commented Feb 24, 2021

Copy link
Copy Markdown
Member

I would disagree, this change should be in what’s new so that interested parties can be notified.

Comment thread Lib/site.py Outdated
Comment thread Lib/sysconfig.py Outdated
# 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
Copy Markdown
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"?

Comment thread 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
Copy Markdown
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
Copy Markdown
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.

Comment thread Lib/sysconfig.py Outdated
Comment thread Lib/site.py Outdated
@mattip

mattip commented Mar 1, 2021

Copy link
Copy Markdown
Contributor Author

CI is passing. This is ready for another review.

@github-actions

github-actions Bot commented Apr 1, 2021

Copy link
Copy Markdown

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

mattip commented Apr 1, 2021

Copy link
Copy Markdown
Contributor Author

@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 thread Lib/sysconfig.py
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'

@tiran tiran Apr 22, 2021

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

@brettcannon brettcannon left a comment

Copy link
Copy Markdown
Member

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

merwok commented Apr 28, 2021

Copy link
Copy Markdown
Member

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

mattip commented Jun 15, 2021

Copy link
Copy Markdown
Contributor Author

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