Skip to content

Commit ba07baa

Browse files
authored
Merge pull request #438 from jumpstarter-dev/backport-435-to-release-0.6
[Backport release-0.6] Init hatch-pin-jumpstarter hook
2 parents 1b9a55c + 6c1e0e1 commit ba07baa

File tree

38 files changed

+277
-32
lines changed

38 files changed

+277
-32
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ docs-linkcheck:
2424
uv run --isolated --all-packages --group docs $(MAKE) -C docs linkcheck
2525

2626
pkg-test-%: packages/%
27-
uv run --isolated --directory $< pytest
27+
uv run --isolated --directory $< pytest || [ $$? -eq 5 ]
2828

2929
pkg-mypy-%: packages/%
3030
uv run --isolated --directory $< mypy .

__templates__/driver/pyproject.toml.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ testpaths = ["jumpstarter_driver_${DRIVER_NAME}"]
2929
asyncio_mode = "auto"
3030

3131
[build-system]
32-
requires = ["hatchling", "hatch-vcs"]
32+
requires = ["hatchling", "hatch-vcs", "hatch-pin-jumpstarter"]
3333
build-backend = "hatchling.build"
3434

35+
[tool.hatch.build.hooks.pin_jumpstarter]
36+
name = "pin_jumpstarter"
37+
3538
[dependency-groups]
3639
dev = [
3740
"pytest-cov>=6.0.0",

packages/hatch-pin-jumpstarter/README.md

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[project]
2+
name = "hatch-pin-jumpstarter"
3+
version = "0.1.0"
4+
description = "Hatch plugin that pins jumpstarter packages in the monorepo"
5+
readme = "README.md"
6+
authors = [
7+
{ name = "Nick Cao", email = "[email protected]" }
8+
]
9+
requires-python = ">=3.11"
10+
dependencies = [
11+
"hatchling>=1.27.0",
12+
"packaging>=24.2",
13+
"tomli>=2.2.1",
14+
"tomli-w>=1.2.0",
15+
]
16+
17+
[build-system]
18+
requires = ["hatchling"]
19+
build-backend = "hatchling.build"
20+
21+
[dependency-groups]
22+
dev = [
23+
"pytest>=8.3.5",
24+
"pytest-cov>=6.1.1",
25+
]
26+
27+
[project.entry-points.hatch]
28+
pin_jumpstarter = "hatch_pin_jumpstarter"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
from pathlib import Path
3+
from tempfile import NamedTemporaryFile
4+
5+
import tomli
6+
import tomli_w
7+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
8+
from hatchling.plugin import hookimpl
9+
from packaging.requirements import Requirement
10+
from packaging.specifiers import SpecifierSet
11+
12+
13+
class PinJumpstarter(BuildHookInterface):
14+
PLUGIN_NAME = "pin_jumpstarter"
15+
16+
def initialize(self, version, build_data):
17+
if self.target_name != "sdist":
18+
return
19+
20+
pyproject = Path(self.root) / "pyproject.toml"
21+
22+
with pyproject.open("rb") as f:
23+
metadata = tomli.load(f)
24+
25+
if "project" in metadata and "dependencies" in metadata["project"]:
26+
for i, dep in enumerate(metadata["project"]["dependencies"]):
27+
req = Requirement(dep)
28+
if req.name.startswith("jumpstarter"):
29+
req.specifier &= SpecifierSet(f"=={self.metadata.version}")
30+
metadata["project"]["dependencies"][i] = str(req)
31+
32+
f = NamedTemporaryFile(delete=False)
33+
tomli_w.dump(metadata, f)
34+
f.close()
35+
36+
build_data["__hatch_pin_jumpstarter_tempfile"] = f
37+
build_data["force_include"][f.name] = "pyproject.toml"
38+
39+
def finalize(self, version, build_data, artifact_path):
40+
if self.target_name != "sdist":
41+
return
42+
43+
f = build_data["__hatch_pin_jumpstarter_tempfile"]
44+
os.unlink(f.name)
45+
46+
47+
@hookimpl
48+
def hatch_register_build_hook():
49+
return PinJumpstarter

packages/hatch-pin-jumpstarter/src/hatch_pin_jumpstarter/py.typed

Whitespace-only changes.

packages/jumpstarter-all/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@ source = "vcs"
5050
raw-options = { 'root' = '../../' }
5151

5252
[build-system]
53-
requires = ["hatchling", "hatch-vcs"]
53+
requires = ["hatchling", "hatch-vcs", "hatch-pin-jumpstarter"]
5454
build-backend = "hatchling.build"
55+
56+
[tool.hatch.build.hooks.pin_jumpstarter]
57+
name = "pin_jumpstarter"

packages/jumpstarter-cli-admin/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ source = "vcs"
3131
raw-options = { 'root' = '../../' }
3232

3333
[build-system]
34-
requires = ["hatchling", "hatch-vcs"]
34+
requires = ["hatchling", "hatch-vcs", "hatch-pin-jumpstarter"]
3535
build-backend = "hatchling.build"
36+
37+
[tool.hatch.build.hooks.pin_jumpstarter]
38+
name = "pin_jumpstarter"

packages/jumpstarter-cli-common/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@ source = "vcs"
3636
raw-options = { 'root' = '../../' }
3737

3838
[build-system]
39-
requires = ["hatchling", "hatch-vcs"]
39+
requires = ["hatchling", "hatch-vcs", "hatch-pin-jumpstarter"]
4040
build-backend = "hatchling.build"
41+
42+
[tool.hatch.build.hooks.pin_jumpstarter]
43+
name = "pin_jumpstarter"

packages/jumpstarter-cli-driver/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ source = "vcs"
3535
raw-options = { 'root' = '../../' }
3636

3737
[build-system]
38-
requires = ["hatchling", "hatch-vcs"]
38+
requires = ["hatchling", "hatch-vcs", "hatch-pin-jumpstarter"]
3939
build-backend = "hatchling.build"
40+
41+
[tool.hatch.build.hooks.pin_jumpstarter]
42+
name = "pin_jumpstarter"

0 commit comments

Comments
 (0)