Skip to content
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

python: add limited_api kwarg to find_installation() #14176

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mesonbuild/dependencies/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def __init__(self, python_holder: 'BasicPythonExternalProgram', embed: bool):
if mesonlib.is_windows() and self.is_freethreaded:
self.compile_args += ['-DPy_GIL_DISABLED']

self.limited_api: str = ''

def find_libpy(self, environment: 'Environment') -> None:
if self.is_pypy:
if self.major_version == 3:
Expand Down
21 changes: 20 additions & 1 deletion mesonbuild/modules/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ def _convert_api_version_to_py_version_hex(self, api_version: str, detected_vers
return '0x{:02x}{:02x}0000'.format(major, minor)

def _dependency_method_impl(self, kwargs: TYPE_kwargs) -> Dependency:

# Need to early resolve an inherited limited_api to an actual version
# for cache key purposes
limited_api_version = kwargs.get('limited_api', '')
if limited_api_version == 'inherit':
limited_api_version = self.limited_api
kwargs = kwargs.copy()
kwargs['limited_api'] = limited_api_version

for_machine = self.interpreter.machine_from_native_kwarg(kwargs)
identifier = get_dep_identifier(self._full_path(), kwargs)

Expand All @@ -263,14 +272,24 @@ def _dependency_method_impl(self, kwargs: TYPE_kwargs) -> Dependency:
candidates = python_factory(self.interpreter.environment, for_machine, new_kwargs, self.held_object)
dep = find_external_dependency('python', self.interpreter.environment, new_kwargs, candidates)

allow_limited_api = self.interpreter.environment.coredata.get_option(OptionKey('python.allow_limited_api'))
if limited_api_version != '' and allow_limited_api:
limited_api_version_hex = self._convert_api_version_to_py_version_hex(limited_api_version, dep.version)
dep.limited_api = limited_api_version
dep.compile_args.append(f'-DPy_LIMITED_API={limited_api_version_hex}')

self.interpreter.coredata.deps[for_machine].put(identifier, dep)
return dep

@disablerIfNotFound
@permittedKwargs(permitted_dependency_kwargs | {'embed'})
@permittedKwargs(permitted_dependency_kwargs | {'embed', 'limited_api'})
@FeatureNewKwargs('python_installation.dependency', '0.53.0', ['embed'])
@FeatureNewKwargs('python_installation.dependency', '1.7.0', ['limited_api'])
@noPosargs
def dependency_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> 'Dependency':
if 'limited_api' not in kwargs:
kwargs['limited_api'] = 'inherit'
Comment on lines +278 to +279
Copy link
Member

@eli-schwartz eli-schwartz Feb 5, 2025

Choose a reason for hiding this comment

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

Is it possible to use None as a sentinel here instead? Or did you intentionally want people to be able to do:

pydep = py.dependency(limited_api: 'inherit')


disabled, required, feature = extract_required_kwarg(kwargs, self.subproject)
if disabled:
mlog.log('Dependency', mlog.bold('python'), 'skipped: feature', mlog.bold(feature), 'disabled')
Expand Down