MCPcopy
hub / github.com/astral-sh/python-build-standalone / derive_setup_local

Function derive_setup_local

pythonbuild/cpython.py:249–707  ·  view source on GitHub ↗

Derive the content of the Modules/Setup.local file.

(
    cpython_source_archive,
    python_version,
    target_triple,
    build_options,
    extension_modules,
)

Source from the content-addressed store, hash-verified

247
248
249def derive_setup_local(
250 cpython_source_archive,
251 python_version,
252 target_triple,
253 build_options,
254 extension_modules,
255):
256 """Derive the content of the Modules/Setup.local file."""
257
258 # The first part of this function validates that our extension modules YAML
259 # based metadata is in sync with the various files declaring extension
260 # modules in the Python distribution.
261
262 disabled = set()
263 ignored = set()
264 setup_enabled_wanted = set()
265 config_c_only_wanted = set()
266
267 # Collect metadata about our extension modules as they relate to this
268 # Python target.
269 for name, info in sorted(extension_modules.items()):
270 python_min_match = meets_python_minimum_version(
271 python_version, info.get("minimum-python-version", "1.0")
272 )
273 python_max_match = meets_python_maximum_version(
274 python_version, info.get("maximum-python-version", "100.0")
275 )
276
277 if info.get("build-mode") not in (
278 None,
279 "shared",
280 "static",
281 "shared-or-disabled",
282 ):
283 raise Exception("unsupported build-mode for extension module %s" % name)
284
285 if not (python_min_match and python_max_match):
286 log(f"ignoring extension module {name} because Python version incompatible")
287 ignored.add(name)
288 continue
289
290 if targets := info.get("disabled-targets"):
291 if any(re.match(p, target_triple) for p in targets):
292 log(
293 "disabling extension module %s because disabled for this target triple"
294 % name
295 )
296 disabled.add(name)
297
298 # Extension is demanding it be built as shared. If this isn't possible due to
299 # a static build, disable the extension.
300 if info.get("build-mode") == "shared-or-disabled" and "static" in build_options:
301 disabled.add(name)
302
303 if info.get("setup-enabled", False):
304 setup_enabled_wanted.add(name)
305
306 for entry in info.get("setup-enabled-conditional", []):

Callers 1

build_cpythonFunction · 0.90

Calls 6

logFunction · 0.90
parse_config_cFunction · 0.85
link_for_targetFunction · 0.85
parse_setup_lineFunction · 0.85

Tested by

no test coverage detected