Skip to content

Commit

Permalink
Add command descriptions to JSON lift manifest.
Browse files Browse the repository at this point in the history
Previously these were gathered from the TOML lift manifest but not
propagated to the JSON lift manifest in the built scie.

Fixes #43
  • Loading branch information
jsirois committed Sep 18, 2023
1 parent 3150a4a commit 12e2246
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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](
Expand Down
2 changes: 1 addition & 1 deletion science/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

from packaging.version import Version

__version__ = "0.2.0"
__version__ = "0.2.1"

VERSION = Version(__version__)
3 changes: 3 additions & 0 deletions science/commands/lift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
36 changes: 36 additions & 0 deletions tests/data/command-descriptions.toml
Original file line number Diff line number Diff line change
@@ -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"]
28 changes: 28 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 12e2246

Please sign in to comment.