diff --git a/CHANGELOG.md b/CHANGELOG.md index 43f3b2a3..42c2de2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## Changed + +- The `pyodide config list` command now displays additional config variables + derived from the Python `sysconfig` module. These variables may also be accessed + through `pyodide config get ` for use in out-of-tree builds. + [#14](https://github.com/pyodide/pyodide-build/pull/14) + ## [0.27.3] - 2024/07/17 - It is now possible to override `_f2c_fixes.py` file, with `_f2c_fixes_wrapper` variable. diff --git a/pyodide_build/cli/config.py b/pyodide_build/cli/config.py index fa481385..69d189ae 100644 --- a/pyodide_build/cli/config.py +++ b/pyodide_build/cli/config.py @@ -1,3 +1,5 @@ +import sysconfig + import typer from ..build_env import get_build_environment_vars, get_pyodide_root, init_environment @@ -19,6 +21,13 @@ "meson_cross_file": "MESON_CROSS_FILE", } +# Load the values of sysconfig.get_paths() with a +# "pyodide_sysconfig_" prefix to differentiate them +# from other configuration variables +PYODIDE_CONFIGS.update( + {f"pyodide_sysconfig_{k}": v for k, v in sysconfig.get_paths().items()} +) + @app.callback(no_args_is_help=True) def callback() -> None: @@ -52,7 +61,7 @@ def get_config( ), ) -> None: """ - Get a value of a single config variable used in pyodide + Get a value of a single config variable used in Pyodide """ configs = _get_configs() diff --git a/pyodide_build/config.py b/pyodide_build/config.py index b4b71765..3f4feab3 100644 --- a/pyodide_build/config.py +++ b/pyodide_build/config.py @@ -1,5 +1,6 @@ import os import subprocess +import sysconfig from collections.abc import Mapping from pathlib import Path from types import MappingProxyType @@ -29,8 +30,15 @@ def __init__(self, pyodide_root: Path): **self._load_makefile_envs(), **self._load_config_file(Path.cwd(), os.environ), **self._load_config_from_env(os.environ), + **self._load_sysconfig_paths(), } + def _load_sysconfig_paths(self) -> Mapping[str, str]: + # Load the values of sysconfig.get_paths() with a + # "pyodide_sysconfig_" prefix to differentiate them + # from other configuration variables + return {f"pyodide_sysconfig_{k}": v for k, v in sysconfig.get_paths().items()} + def _load_default_config(self) -> Mapping[str, str]: return { k: _environment_substitute_str( @@ -173,6 +181,10 @@ def to_env(self) -> dict[str, str]: "_f2c_fixes_wrapper": "_F2C_FIXES_WRAPPER", } +BUILD_KEY_TO_VAR.update( + {f"pyodide_sysconfig_{k}": v for k, v in sysconfig.get_paths().items()} +) + BUILD_VAR_TO_KEY = {v: k for k, v in BUILD_KEY_TO_VAR.items()} # Configuration keys that can be overridden by the user. @@ -205,6 +217,10 @@ def to_env(self) -> dict[str, str]: "_f2c_fixes_wrapper": "", } +DEFAULT_CONFIG.update( + {f"pyodide_sysconfig_{k}": v for k, v in sysconfig.get_paths().items()} +) + # Default configs that are computed from other values (often from Makefile.envs) # TODO: Remove dependency on Makefile.envs DEFAULT_CONFIG_COMPUTED: dict[str, str] = {