Skip to content

Commit 759c2a4

Browse files
authored
Plumb scie.jump.hash for scie-jump >= 1.11.0. (#196)
1 parent 31b741b commit 759c2a4

File tree

5 files changed

+56
-23
lines changed

5 files changed

+56
-23
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Release Notes
22

3+
## 0.18.1
4+
5+
This release passes the `scie_jump.digest.fingerprint` through to the `scie.jump.hash` lift manifest
6+
field when building scies using a scie-jump version 1.11.0 or newer.
7+
38
## 0.18.0
49

510
This release adds a `science lift run` command for running lift manifests directly. This can be

science/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
from packaging.version import Version
55

6-
__version__ = "0.18.0"
6+
__version__ = "0.18.1"
77

88
VERSION = Version(__version__)

science/commands/lift.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from typing import Any, Iterable, Iterator, Mapping, TextIO
1414
from zipfile import ZipInfo
1515

16+
from packaging.version import Version
17+
1618
from science import a_scie, providers
1719
from science.build_info import BuildInfo
1820
from science.errors import InputError
@@ -303,8 +305,10 @@ def maybe_invert_lazy(file: File) -> File:
303305
)
304306
if load_result.version:
305307
scie_jump = ScieJump(version=load_result.version, digest=load_result.digest)
308+
elif platform_spec == CURRENT_PLATFORM_SPEC:
309+
scie_jump = ScieJump.load(scie_jump_path=load_result.path, digest=load_result.digest)
306310
else:
307-
scie_jump = ScieJump()
311+
scie_jump = ScieJump(digest=load_result.digest)
308312

309313
with open(lift_manifest, "w") as lift_manifest_output:
310314
_emit_manifest(
@@ -435,6 +439,10 @@ def render_commands(cmds: Iterable[Command]) -> dict[str, dict[str, Any]]:
435439
scie_jump_data = dict[str, Any]()
436440
if (scie_jump_version := scie_jump.version) and (scie_jump_digest := scie_jump.digest):
437441
scie_jump_data.update(version=str(scie_jump_version), size=scie_jump_digest.size)
442+
if scie_jump.version >= Version("1.11.0"):
443+
# N.B.: scie.jump.hash support was added in 1.11.0:
444+
# https://github.com/a-scie/jump/releases/tag/v1.11.0
445+
scie_jump_data.update(hash=scie_jump.digest.fingerprint)
438446
if scie_jump_data:
439447
scie_data.update(jump=scie_jump_data)
440448

science/model.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44

55
import dataclasses
6+
import logging
67
import os.path
78
import re
9+
import subprocess
810
import urllib.parse
911
from collections import Counter, defaultdict
1012
from dataclasses import dataclass
@@ -36,6 +38,8 @@
3638
from science.hashing import Digest, ExpectedDigest
3739
from science.platform import CURRENT_PLATFORM_SPEC, PlatformSpec
3840

41+
logger = logging.getLogger(__name__)
42+
3943

4044
class FileType(Enum):
4145
@classmethod
@@ -267,6 +271,22 @@ def rel_path(self) -> PurePath:
267271

268272
@documented_dataclass(frozen=True, alias="scie_jump")
269273
class ScieJump:
274+
@classmethod
275+
def load(cls, scie_jump_path: Path, digest: Digest | None = None) -> ScieJump:
276+
version: Version | None = None
277+
process = subprocess.Popen(
278+
args=[scie_jump_path, "-V"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
279+
)
280+
stdout, _ = process.communicate()
281+
if process.returncode == 0:
282+
version = Version(stdout.decode("utf-8").strip())
283+
else:
284+
logger.warning(
285+
f"The scie-jump at {scie_jump_path} does not support `-V` / `--version`. "
286+
f"Some science operations may not work as expected."
287+
)
288+
return cls(version=version, digest=digest or Digest.hash(scie_jump_path))
289+
270290
_DEFAULT_BASE_URL: ClassVar[Url] = Url("https://github.com/a-scie/jump/releases")
271291

272292
version: Version | None = dataclasses.field(default=None, metadata=metadata(reference=True))

tests/test_exe.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ def science_exe(
5252
subprocess.run(
5353
args=[
5454
sys.executable,
55-
str(science_pyz),
55+
science_pyz,
5656
"lift",
5757
"--file",
5858
f"science.pyz={science_pyz}",
5959
"--file",
6060
f"docsite={docsite}",
6161
"build",
6262
"--dest-dir",
63-
str(dest),
63+
dest,
6464
],
6565
check=True,
6666
cwd=build_root,
@@ -77,15 +77,15 @@ def test_use_platform_suffix(
7777
assert not expected_executable.exists()
7878
subprocess.run(
7979
args=[
80-
str(science_exe),
80+
science_exe,
8181
"lift",
8282
"--file",
8383
f"science.pyz={science_pyz}",
8484
"--file",
8585
f"docsite={docsite}",
8686
"build",
8787
"--dest-dir",
88-
str(tmp_path),
88+
tmp_path,
8989
"--use-platform-suffix",
9090
config,
9191
],
@@ -104,7 +104,7 @@ def test_no_use_platform_suffix(
104104
assert not expected_executable.exists()
105105
subprocess.run(
106106
args=[
107-
str(science_exe),
107+
science_exe,
108108
"lift",
109109
"--file",
110110
f"science.pyz={science_pyz}",
@@ -114,7 +114,7 @@ def test_no_use_platform_suffix(
114114
foreign_platform.value,
115115
"build",
116116
"--dest-dir",
117-
str(tmp_path),
117+
tmp_path,
118118
"--no-use-platform-suffix",
119119
config,
120120
],
@@ -157,15 +157,15 @@ def test_hash(
157157

158158
subprocess.run(
159159
args=[
160-
str(science_exe),
160+
science_exe,
161161
"lift",
162162
"--file",
163163
f"science.pyz={science_pyz}",
164164
"--file",
165165
f"docsite={docsite}",
166166
"build",
167167
"--dest-dir",
168-
str(tmp_path),
168+
tmp_path,
169169
*itertools.chain.from_iterable(("--hash", algorithm) for algorithm in algorithms),
170170
config,
171171
],
@@ -176,7 +176,7 @@ def test_hash(
176176
if shasum:
177177
subprocess.run(
178178
args=[shasum, "-c", *(checksum_file.name for checksum_file in expected_checksum_paths)],
179-
cwd=str(tmp_path),
179+
cwd=tmp_path,
180180
check=True,
181181
)
182182
else:
@@ -200,7 +200,7 @@ def test_dogfood(
200200
dest = tmp_path / "dest"
201201
subprocess.run(
202202
args=[
203-
str(science_exe),
203+
science_exe,
204204
"lift",
205205
"--file",
206206
f"science.pyz={science_pyz}",
@@ -250,7 +250,7 @@ def test_nested_filenames(
250250
(tmp_path / "docsite").mkdir()
251251
dest1 = tmp_path / "dest1"
252252
subprocess.run(
253-
args=[str(science_exe), "lift", "build", "--dest-dir", str(dest1)], check=True, cwd=tmp_path
253+
args=[science_exe, "lift", "build", "--dest-dir", str(dest1)], check=True, cwd=tmp_path
254254
)
255255
science_exe1 = dest1 / science_exe.name
256256
assert science_exe1.is_file()
@@ -382,7 +382,7 @@ def create_url_source_scie(
382382

383383
scie = dest / CURRENT_PLATFORM.binary_name(expected_name)
384384
result = subprocess.run(
385-
args=[str(science_exe), "lift", *extra_lift_args, "build", "--dest-dir", str(dest), "-"],
385+
args=[science_exe, "lift", *extra_lift_args, "build", "--dest-dir", str(dest), "-"],
386386
input=lift_toml_content,
387387
stdout=subprocess.PIPE,
388388
stderr=subprocess.PIPE,
@@ -766,7 +766,7 @@ def test_pypy_provider(tmp_path: Path, science_exe: Path, version: str) -> None:
766766
chroot.mkdir(parents=True, exist_ok=True)
767767

768768
subprocess.run(
769-
args=[str(science_exe), "lift", "build", "--dest-dir", str(dest), "-"],
769+
args=[science_exe, "lift", "build", "--dest-dir", str(dest), "-"],
770770
input=dedent(
771771
f"""\
772772
[lift]
@@ -815,7 +815,7 @@ def test_scie_name_collision_with_file(tmp_path: Path, science_exe: Path) -> Non
815815

816816
subprocess.run(
817817
args=[
818-
str(science_exe),
818+
science_exe,
819819
"lift",
820820
"--file",
821821
f"exe={exe}",
@@ -877,7 +877,7 @@ def test_pbs_provider_pre_releases(tmp_path: Path, science_exe: Path) -> None:
877877

878878
subprocess.run(
879879
args=[
880-
str(science_exe),
880+
science_exe,
881881
"lift",
882882
"--file",
883883
f"exe={exe}",
@@ -952,7 +952,7 @@ def test_pbs_provider_freethreaded_builds(tmp_path: Path, science_exe: Path) ->
952952

953953
subprocess.run(
954954
args=[
955-
str(science_exe),
955+
science_exe,
956956
"lift",
957957
"--file",
958958
f"exe={exe}",
@@ -1026,7 +1026,7 @@ def test_pbs_provider_version_suffix(tmp_path: Path, science_exe: Path) -> None:
10261026
chroot.mkdir(parents=True, exist_ok=True)
10271027

10281028
result = subprocess.run(
1029-
args=[str(science_exe), "lift", "build", "--dest-dir", str(dest), "-"],
1029+
args=[science_exe, "lift", "build", "--dest-dir", str(dest), "-"],
10301030
input=dedent(
10311031
"""\
10321032
[lift]
@@ -1160,7 +1160,7 @@ def test_pbs_provider_version_suffix(tmp_path: Path, science_exe: Path) -> None:
11601160

11611161
subprocess.run(
11621162
args=[
1163-
str(science_exe),
1163+
science_exe,
11641164
"lift",
11651165
"--file",
11661166
f"exe={exe}",
@@ -1222,7 +1222,7 @@ def test_load_dotenv(tmp_path: Path, science_exe: Path) -> None:
12221222
chroot.mkdir(parents=True, exist_ok=True)
12231223

12241224
subprocess.run(
1225-
args=[str(science_exe), "lift", "build", "--dest-dir", str(dest), "-"],
1225+
args=[science_exe, "lift", "build", "--dest-dir", str(dest), "-"],
12261226
input=dedent(
12271227
"""\
12281228
[lift]
@@ -1296,7 +1296,7 @@ def test_custom_jump_nominal(tmp_path: Path, science_exe: Path, version: str) ->
12961296

12971297
cache_dir = tmp_path / "cache"
12981298
subprocess.run(
1299-
args=[str(science_exe), "lift", "build", "--dest-dir", str(dest), lift_manifest],
1299+
args=[science_exe, "lift", "build", "--dest-dir", str(dest), lift_manifest],
13001300
env={**os.environ, "SCIENCE_CACHE_DIR": str(cache_dir)},
13011301
check=True,
13021302
)
@@ -1443,7 +1443,7 @@ def test_custom_jump_invalid(tmp_path: Path, science_exe: Path, digest: Digest)
14431443

14441444
cache_dir = tmp_path / "cache"
14451445
result = subprocess.run(
1446-
args=[str(science_exe), "lift", "build", "--dest-dir", str(dest)],
1446+
args=[science_exe, "lift", "build", "--dest-dir", str(dest)],
14471447
env={**os.environ, "SCIENCE_CACHE_DIR": str(cache_dir)},
14481448
cwd=chroot,
14491449
stderr=subprocess.PIPE,

0 commit comments

Comments
 (0)