From 12e2246a05e16616a48f2678e53fade1e58b322d Mon Sep 17 00:00:00 2001 From: John Sirois Date: Mon, 18 Sep 2023 12:25:15 -0700 Subject: [PATCH] Add command descriptions to JSON lift manifest. Previously these were gathered from the TOML lift manifest but not propagated to the JSON lift manifest in the built scie. Fixes #43 --- CHANGES.md | 4 ++++ science/__init__.py | 2 +- science/commands/lift.py | 3 +++ tests/data/command-descriptions.toml | 36 ++++++++++++++++++++++++++++ tests/test_config.py | 28 ++++++++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/data/command-descriptions.toml diff --git a/CHANGES.md b/CHANGES.md index c107d03..e8695d1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Release Notes +## 0.2.1 + +Fix command descriptions not being rendered in the JSON lift manifest of built scies. + ## 0.2.0 Add support for specifying a custom base `nce` cache dir and upgrade the internal [PBS]( diff --git a/science/__init__.py b/science/__init__.py index 51f1935..c992efe 100644 --- a/science/__init__.py +++ b/science/__init__.py @@ -3,6 +3,6 @@ from packaging.version import Version -__version__ = "0.2.0" +__version__ = "0.2.1" VERSION = Version(__version__) diff --git a/science/commands/lift.py b/science/commands/lift.py index 4b67ab7..bf50d5f 100644 --- a/science/commands/lift.py +++ b/science/commands/lift.py @@ -280,6 +280,9 @@ def expand_placeholders(text: str) -> str: if env: cmd["env"] = env + if description := command.description: + cmd["description"] = description + return command.name or "", cmd diff --git a/tests/data/command-descriptions.toml b/tests/data/command-descriptions.toml new file mode 100644 index 0000000..6cc4ad3 --- /dev/null +++ b/tests/data/command-descriptions.toml @@ -0,0 +1,36 @@ +[lift] +name = "command-descriptions" +description = "Test command decription propagation." + +[[lift.interpreters]] +id = "cpython" +provider = "PythonBuildStandalone" +version = "3.10" +lazy = true + +[[lift.commands]] +description = "Print a JSON object of command descriptions by name." +exe = "#{cpython:python}" +args = [ + "-c", + """ +import json +import sys + + +with open("{scie.lift}") as fp: + data = json.load(fp) + +def get_description(command_name: str) -> str | None: + return data["scie"]["lift"]["boot"]["commands"][command_name].get("description") + +json.dump( + {{command_name: get_description(command_name) for command_name in ("", "version")}, sys.stdout +) + """ +] + +[[lift.commands]] +name = "version" +exe = "#{cpython:python}" +args = ["-V"] diff --git a/tests/test_config.py b/tests/test_config.py index e1c6097..e32db52 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -122,3 +122,31 @@ def test_scie_base(tmp_path: Path, science_pyz: Path) -> None: ) finally: shutil.rmtree(expanded_base, ignore_errors=True) + + +def test_command_descriptions(tmp_path: Path, science_pyz: Path) -> None: + with resources.as_file(resources.files("data") / "command-descriptions.toml") as config: + subprocess.run( + args=[ + sys.executable, + str(science_pyz), + "lift", + "build", + "--dest-dir", + str(tmp_path), + config, + ], + check=True, + ) + + exe_path = tmp_path / Platform.current().binary_name("command-descriptions") + scie_base = tmp_path / "scie-base" + data = json.loads( + subprocess.run( + args=[exe_path], + env={**os.environ, "PYTHON": "cpython310", "SCIE_BASE": str(scie_base)}, + stdout=subprocess.PIPE, + check=True, + ).stdout + ) + assert {"": "Print a JSON object of command descriptions by name.", "version": None} == data