-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Prototype support for PEP 739 #13945
base: master
Are you sure you want to change the base?
Conversation
ea9aed7
to
697e20c
Compare
Rebased on |
64f9781
to
e9deda3
Compare
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.
This is starting to look quite nice! \o/ How close are we to getting the PEP approved and deployed (e.g. in a cpython alpha)?
Thanks! I have requested a review for the PEP, so hopefully we should hear something soon. If it gets accepted, I'll add the file to CPython as soon as possible, so it should be available on the following release. I'll also publish a package to generate the build config file to PyPI, so that we can use it on older Python versions, or Python implementations that do not ship it, as long as you are able to run code on the target. Afterwards, in a followup to PEP 739, I also want to standardize a file for the installation environment, which will provide the installation paths. We'll ship a file for the default environment, and unless we run into some issue, I'll also get |
e3b2bfb
to
7ca5393
Compare
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
7ca5393
to
43fcae5
Compare
…figDependency Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
43fcae5
to
f30406d
Compare
The PEP has been accepted. https://peps.python.org/pep-0739/ I'll add support for it in Python 3.14, and then come back to this PR. |
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.
Fantastic news! Looking forward to local testing as soon as the backportable version exists. Some more quick comments.
if mesonlib.version_compare(schema_version, f'> {self.IMPLEMENTED_VERSION}'): | ||
mlog.log( | ||
f'python.build_config has schema_version {schema_version!r}, ' | ||
f'but we only implement suport for {self.IMPLEMENTED_VERSION!r}, ' |
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.
f'but we only implement suport for {self.IMPLEMENTED_VERSION!r}, ' | |
f'but we only implement support for {self.IMPLEMENTED_VERSION!r}, ' |
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.
And a few lines up as well.
mlog.debug( | ||
f'{pkg_name!r} could not be found in {pkg_libdir_origin}, ' | ||
'this is likely due to a relocated python installation' | ||
) |
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 if we end up line-breaking we would usually do it like:
mlog.debug(f'{pkg_name!r} could not be found in {pkg_libdir_origin}, '
'this is likely due to a relocated python installation')
extra_paths: T.List[str] = self.env.coredata.optstore.get_value(key)[:] | ||
extra_paths: T.List[str] = self.env.coredata.optstore.get_value(key)[:] + self.extra_paths |
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.
Hmm, I see what you're doing here. You allow a PkgConfigDependency to take an additional PKG_CONFIG_PATH which is joined to the one in the cross file, which also means we don't need to push/pop os.environ.
On the flip side, the way we previously used it was via PKG_CONFIG_LIBDIR which was more narrowly scoped. I suspect this change means we can accidentally fall back to a different python than the one we were searching for (but still the same major.minor version at least)...
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.
Ah hold on, we anyways fall back to checking for pkg-config without the internal LIBPC which means this is actually doing exactly what we want with one less check. Heh. :)
@@ -256,7 +262,7 @@ def _check_pkgconfig(self, pkgbin: ExternalProgram) -> T.Optional[str]: | |||
def _get_env(self, uninstalled: bool = False) -> EnvironmentVariables: | |||
env = EnvironmentVariables() | |||
key = OptionKey('pkg_config_path', machine=self.for_machine) | |||
extra_paths: T.List[str] = self.env.coredata.optstore.get_value(key)[:] | |||
extra_paths: T.List[str] = self.env.coredata.optstore.get_value(key)[:] + self.extra_paths |
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.
We don't need the cryptic copy of the first list anymore, right?
if sys.version_info >= (3, 8): | ||
from functools import cached_property | ||
else: | ||
cached_property = property |
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.
We have a lazy_property
in utils somewhere now. It's provides more or less what cached_property does (although it's simpler and expects the attribute to be write once)
with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as python_build_config_file: | ||
json.dump(python_build_config, fp=python_build_config_file) | ||
|
||
with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as cross_file: |
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.
Neither of these get cleaned up right now, do they?
The overall goal is to support targeting Python installations without need for introspection, given all necessary information is given externally.
This is built upon:
_sysconfigdata
to a JSON file python/cpython#127178, forpy_installation.get_variable
/py_installation.has_variable
supportThis PR is just a prototype, as I work to get all necessary pieces finalized.