2023-01-14 13:59:42 +00:00
|
|
|
import typer
|
2022-12-23 08:20:23 +00:00
|
|
|
|
2023-06-26 12:20:12 +00:00
|
|
|
from ..build_env import get_build_environment_vars, init_environment
|
2022-12-23 08:20:23 +00:00
|
|
|
|
|
|
|
app = typer.Typer(help="Manage config variables used in pyodide")
|
|
|
|
|
|
|
|
|
|
|
|
# A dictionary of config variables {key: env_var_in_makefile}
|
|
|
|
PYODIDE_CONFIGS = {
|
|
|
|
"emscripten_version": "PYODIDE_EMSCRIPTEN_VERSION",
|
|
|
|
"python_version": "PYVERSION",
|
2023-10-28 12:37:55 +00:00
|
|
|
"rustflags": "RUSTFLAGS",
|
|
|
|
"cmake_toolchain_file": "CMAKE_TOOLCHAIN_FILE",
|
|
|
|
"pyo3_config_file": "PYO3_CONFIG_FILE",
|
|
|
|
"rust_toolchain": "RUST_TOOLCHAIN",
|
|
|
|
"cflags": "SIDE_MODULE_CFLAGS",
|
|
|
|
"cxxflags": "SIDE_MODULE_CXXFLAGS",
|
|
|
|
"ldflags": "SIDE_MODULE_LDFLAGS",
|
|
|
|
"meson_cross_file": "MESON_CROSS_FILE",
|
2022-12-23 08:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-06 21:21:03 +00:00
|
|
|
@app.callback(no_args_is_help=True)
|
2022-12-23 08:20:23 +00:00
|
|
|
def callback() -> None:
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def _get_configs() -> dict[str, str]:
|
2023-06-05 08:34:07 +00:00
|
|
|
init_environment(quiet=True)
|
2022-12-23 08:20:23 +00:00
|
|
|
|
2023-05-06 08:17:22 +00:00
|
|
|
configs: dict[str, str] = get_build_environment_vars()
|
2022-12-23 08:20:23 +00:00
|
|
|
|
|
|
|
configs_filtered = {k: configs[v] for k, v in PYODIDE_CONFIGS.items()}
|
|
|
|
return configs_filtered
|
|
|
|
|
|
|
|
|
|
|
|
@app.command("list")
|
|
|
|
def list_config():
|
|
|
|
"""
|
|
|
|
List config variables used in pyodide
|
|
|
|
"""
|
|
|
|
configs = _get_configs()
|
|
|
|
|
|
|
|
for k, v in configs.items():
|
|
|
|
typer.echo(f"{k}={v}")
|
|
|
|
|
|
|
|
|
2023-06-06 21:21:03 +00:00
|
|
|
@app.command("get")
|
2022-12-23 08:20:23 +00:00
|
|
|
def get_config(
|
|
|
|
config_var: str = typer.Argument(
|
|
|
|
..., help="A config variable to get. Use `list` to see all possible values."
|
|
|
|
),
|
|
|
|
) -> None:
|
|
|
|
"""
|
|
|
|
Get a value of a single config variable used in pyodide
|
|
|
|
"""
|
|
|
|
configs = _get_configs()
|
|
|
|
|
|
|
|
if config_var not in configs:
|
|
|
|
typer.echo(f"Config variable {config_var} not found.")
|
|
|
|
typer.Exit(1)
|
|
|
|
|
|
|
|
typer.echo(configs[config_var])
|