|
53 | 53 | load_environments, |
54 | 54 | load_python_tools, |
55 | 55 | load_providers, |
| 56 | + load_setup_metadata, |
56 | 57 | load_tool, |
57 | 58 | resolve_lockfile, |
58 | 59 | ) |
@@ -429,56 +430,19 @@ def _apply_environment(args, selection, definitions, setup_scripts) -> int: |
429 | 430 | # Pass variables to the setup processes. Python cannot change the |
430 | 431 | # environment of the shell that launched this installer. |
431 | 432 | if "setup" in args.providers and setup_scripts: |
432 | | - environment = {**os.environ, **_metadata_values()} |
| 433 | + environment = {**os.environ, **load_setup_metadata()} |
433 | 434 | environment["SCORE_TOOL_ENVIRONMENT"] = args.environment |
434 | 435 | environment["SCORE_TOOLS_INSTALLER"] = str(Path(__file__).resolve()) |
435 | 436 | for script in setup_scripts: |
436 | 437 | subprocess.run(["bash", str(script)], check=True, env=environment) |
437 | 438 | return 0 |
438 | 439 |
|
439 | 440 |
|
440 | | -def _metadata_values() -> dict[str, str]: |
441 | | - """Turn definition fields into variables such as codeql_version for setup and tests.""" |
442 | | - import re |
443 | | - |
444 | | - values: dict[str, str] = {} |
445 | | - |
446 | | - def emit(name, value): |
447 | | - if not re.fullmatch(r"[a-zA-Z_][a-zA-Z0-9_]*", name): |
448 | | - raise SystemExit(f"Invalid metadata variable: {name}") |
449 | | - if isinstance(value, dict): |
450 | | - for key, child in value.items(): |
451 | | - emit(name + "_" + key, child) |
452 | | - elif isinstance(value, str): |
453 | | - values[name] = value |
454 | | - |
455 | | - for name, definition in load_providers().items(): |
456 | | - # Use only version and checksum fields. Other data, such as platform |
457 | | - # names containing slashes, cannot be used as shell variable names. |
458 | | - for field in ("version", "compatibility_version", "amd64", "arm64"): |
459 | | - if field in definition: |
460 | | - emit(name.replace("-", "_") + "_" + field, definition[field]) |
461 | | - # Unpinned APT tools can still have expected versions for feature tests. |
462 | | - # Give these expectations the same _version names as pinned tools. |
463 | | - if "compatibility_version" in definition: |
464 | | - emit( |
465 | | - name.replace("-", "_") + "_version", definition["compatibility_version"] |
466 | | - ) |
467 | | - # Native and Python command versions use the same variable names as the |
468 | | - # other definitions, so feature tests need just one metadata query. |
469 | | - for name, version in load_catalog_versions().items(): |
470 | | - emit(name.replace("-", "_") + "_version", version) |
471 | | - # Python package and entrypoint metadata is also available to setup scripts. |
472 | | - for name, definition in load_python_tools().items(): |
473 | | - emit(name.replace("-", "_"), definition) |
474 | | - return values |
475 | | - |
476 | | - |
477 | 441 | def _cmd_shell_metadata(args: argparse.Namespace) -> int: |
478 | 442 | """Print shell-quoted exports so feature tests can read versions in their shell.""" |
479 | 443 | import shlex |
480 | 444 |
|
481 | | - for name, value in _metadata_values().items(): |
| 445 | + for name, value in load_setup_metadata().items(): |
482 | 446 | print("export " + name + "=" + shlex.quote(value)) |
483 | 447 | return 0 |
484 | 448 |
|
|
0 commit comments