Skip to content

Commit

Permalink
Support specifying a custom base nce cache dir. (#41)
Browse files Browse the repository at this point in the history
This should be the last missing scie-jump manifest pass-through field.
  • Loading branch information
jsirois authored Sep 6, 2023
1 parent b3cb0ea commit 3150a4a
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

## 0.2.0

Add support for specifying a custom base `nce` cache dir and upgrade the internal [PBS](
https://github.com/indygreg/python-build-standalone/) CPython 3.11.5.

## 0.1.3

Update the science internal Python distribution to [PBS](
Expand Down
4 changes: 2 additions & 2 deletions lift.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ description = "Ship your interpreted executables using science."
[[lift.interpreters]]
id = "cpython"
provider = "PythonBuildStandalone"
release = "20230726"
version = "3.11.4"
release = "20230826"
version = "3.11.5"
# By default science ships as a "thin" scie that fetches CPython 3.11 on first run.
# We use `science lift --invert-lazy cpython ...` when producing "fat" scies.
lazy = true
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.1.3"
__version__ = "0.2.0"

VERSION = Version(__version__)
26 changes: 15 additions & 11 deletions science/commands/lift.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def maybe_invert_lazy(file: File) -> File:
name=application.name,
description=application.description,
load_dotenv=application.load_dotenv,
base=application.base,
scie_jump=application.scie_jump or ScieJump(),
platform=platform,
distributions=distributions,
Expand Down Expand Up @@ -287,6 +288,7 @@ def _emit_manifest(
name: str,
description: str | None,
load_dotenv: bool,
base: str | None,
scie_jump: ScieJump,
platform: Platform,
distributions: Iterable[Distribution],
Expand All @@ -306,18 +308,20 @@ def render_commands(cmds: Iterable[Command]) -> dict[str, dict[str, Any]]:
_render_command(cmd, platform, distributions, interpreter_groups) for cmd in cmds
)

scie_data = {
"lift": {
"name": name,
"description": description,
"load_dotenv": load_dotenv,
"files": render_files(),
"boot": {
"commands": render_commands(commands),
"bindings": render_commands(bindings),
},
}
lift_data = {
"name": name,
"description": description,
"load_dotenv": load_dotenv,
"files": render_files(),
"boot": {
"commands": render_commands(commands),
"bindings": render_commands(bindings),
},
}
if base:
lift_data.update(base=base)

scie_data = {"lift": lift_data}
data = dict[str, Any](scie=scie_data)
if build_info:
data.update(science=build_info.to_dict(**(app_info or {})))
Expand Down
4 changes: 4 additions & 0 deletions science/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ class Application(Dataclass):
load_dotenv: bool = False
build_info: BuildInfo | None = dataclasses.field(default=None, metadata=metadata(inline=True))
platforms: frozenset[Platform] = frozenset([Platform.current()])
base: str | None = dataclasses.field(
default=None,
metadata=metadata("An alternate path to use for the scie base `nce` CAS."),
)
interpreters: tuple[Interpreter, ...] = ()
interpreter_groups: tuple[InterpreterGroup, ...] = ()
files: tuple[File, ...] = ()
Expand Down
17 changes: 17 additions & 0 deletions tests/data/scie-base.unix.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[lift]
name = "custom-base"
description = "Test custom scie base configuration."
base = "/tmp/custom-base"

[[lift.interpreters]]
id = "cpython"
provider = "PythonBuildStandalone"
version = "3.10"
lazy = true

[[lift.commands]]
exe = "#{cpython:python}"
args = [
"-c",
"print('Hello from {scie.base}!')"
]
17 changes: 17 additions & 0 deletions tests/data/scie-base.windows.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[lift]
name = "custom-base"
description = "Test custom scie base configuration."
base = "~\\AppData\\Local\\Temp\\custom-base"

[[lift.interpreters]]
id = "cpython"
provider = "PythonBuildStandalone"
version = "3.10"
lazy = true

[[lift.commands]]
exe = "#{cpython:python}"
args = [
"-c",
"print(r'Hello from {scie.base}!')"
]
48 changes: 48 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import json
import os.path
import shutil
import subprocess
import sys
from importlib import resources
Expand Down Expand Up @@ -74,3 +75,50 @@ def test_interpreter_groups(tmp_path: Path, science_pyz: Path) -> None:
assert (scie_base / data2["hash"]).is_dir()

assert data1["hash"] != data2["hash"]


def test_scie_base(tmp_path: Path, science_pyz: Path) -> None:
current_platform = Platform.current()
match current_platform:
case Platform.Windows_x86_64:
config_name = "scie-base.windows.toml"
expected_base = "~\\AppData\\Local\\Temp\\custom-base"
case _:
config_name = "scie-base.unix.toml"
expected_base = "/tmp/custom-base"

with resources.as_file(resources.files("data") / config_name) as config:
subprocess.run(
args=[
sys.executable,
str(science_pyz),
"lift",
"build",
"--dest-dir",
str(tmp_path),
config,
],
check=True,
)

exe_path = tmp_path / current_platform.binary_name("custom-base")

data = json.loads(
subprocess.run(
args=[exe_path],
env={**os.environ, "SCIE": "inspect"},
stdout=subprocess.PIPE,
check=True,
).stdout
)
assert expected_base == data["scie"]["lift"]["base"]
expanded_base = os.path.expanduser(expected_base)
try:
assert (
f"Hello from {expanded_base}!"
== subprocess.run(
args=[exe_path], stdout=subprocess.PIPE, text=True, check=True
).stdout.strip()
)
finally:
shutil.rmtree(expanded_base, ignore_errors=True)

0 comments on commit 3150a4a

Please sign in to comment.