Skip to content

Commit e40ea2f

Browse files
committed
fix(datashare-python,worker-template): template package name
1 parent 87f6784 commit e40ea2f

4 files changed

Lines changed: 26 additions & 16 deletions

File tree

datashare-python/datashare_python/template.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import shutil
23
import tarfile
34
from copy import deepcopy
45
from importlib.resources import as_file, files
@@ -48,25 +49,26 @@ def build_template_tarball() -> None:
4849
def init_project(name: str, path: Path) -> None:
4950
destination = path / name
5051
template_tar = files("datashare_python")
52+
package_name = name.replace("-", "_").lower()
5153
with (
5254
as_file(template_tar / "worker-template.tar.gz") as tar_path,
5355
tarfile.open(tar_path, mode="r:gz") as tar,
5456
):
5557
tar.extractall(destination)
58+
package_dir = destination / package_name
59+
shutil.move(destination / "worker_template", package_dir)
5660
pyproject_toml_path = destination / "pyproject.toml"
5761
pyproject_toml = tomlkit.loads(pyproject_toml_path.read_text())
58-
pyproject_toml = _update_pyproject_toml(pyproject_toml, project_name=name)
62+
pyproject_toml = _update_pyproject_toml(pyproject_toml, package_name=package_name)
5963
pyproject_toml_path.write_text(tomlkit.dumps(pyproject_toml))
6064

6165

6266
_BASE_DEPS = {"datashare-python", "icij-common", "temporalio"}
6367

6468

6569
def _update_pyproject_toml(
66-
pyproject_toml: dict[str, Any], *, project_name: str
70+
pyproject_toml: dict[str, Any], *, package_name: str
6771
) -> dict[str, Any]:
68-
lower_snaked = project_name.replace("-", "_").lower()
69-
7072
pyproject_toml = deepcopy(pyproject_toml)
7173

7274
pyproject_toml["tool"]["uv"].pop("sources")
@@ -90,13 +92,19 @@ def _update_pyproject_toml(
9092
entry_points = project["entry-points"]
9193

9294
wf_entry_point = entry_points["datashare.workflows"]["workflows"]
93-
wf_entry_point = wf_entry_point.replace("worker_template", lower_snaked)
95+
wf_entry_point = wf_entry_point.replace("worker_template", package_name)
9496
entry_points["datashare.workflows"]["workflows"] = wf_entry_point
9597

9698
activities_entry_point = entry_points["datashare.activities"]["activities"]
9799
activities_entry_point = activities_entry_point.replace(
98-
"worker_template", lower_snaked
100+
"worker_template", package_name
99101
)
100102
entry_points["datashare.activities"]["activities"] = activities_entry_point
101103

104+
hatch_sdist = pyproject_toml["tool"]["hatch"]["build"]["targets"]["sdist"]
105+
hatch_sdist["only-include"] = [
106+
i if i != "worker_template" else package_name
107+
for i in hatch_sdist["only-include"]
108+
]
109+
102110
return pyproject_toml

datashare-python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "datashare-python"
3-
version = "0.2.20"
3+
version = "0.2.21"
44
description = "Manage Pythoœn tasks and local resources in Datashare"
55
authors = [
66
{ name = "Clément Doumouro", email = "cdoumouro@icij.org" },

datashare-python/tests/test_template.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ async def test_init_project(
1010
) -> None:
1111
# Given
1212
test_worker_project = "test-project"
13+
1314
# When
1415
init_project(test_worker_project, tmp_path)
16+
1517
# Then
1618
project_path = tmp_path / test_worker_project
1719

1820
assert project_path.exists()
1921
pyproject_toml_path = project_path / "pyproject.toml"
20-
2122
assert pyproject_toml_path.exists()
23+
package_path = project_path / "test_project"
24+
assert package_path.exists()
25+
2226
pyproject_toml = tomlkit.loads(pyproject_toml_path.read_text())
2327

2428
project = pyproject_toml["project"]
@@ -38,3 +42,6 @@ async def test_init_project(
3842
assert wf_entrypoints == "test_project.workflows:WORKFLOWS"
3943
acts = entry_points["datashare.activities"]["activities"]
4044
assert acts == "test_project.activities:ACTIVITIES"
45+
46+
hatch_sdist = pyproject_toml["tool"]["hatch"]["build"]["targets"]["sdist"]
47+
assert hatch_sdist["only-include"] == ["test_project"]

worker-template/pyproject.toml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "datashare-worker-template"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
description = "Datashare worker template"
55
authors = [
66
{ name = "Clément Doumouro", email = "cdoumouro@icij.org" },
@@ -60,13 +60,8 @@ requires = ["hatchling"]
6060
build-backend = "hatchling.build"
6161
package = ["worker_template"]
6262

63-
# Include non python files into the source so that we can copy them as template when the package is distributed
64-
[tool.hatch.build.targets.wheel.force-include]
65-
"pyproject.toml" = "worker_template/template/pyproject.toml"
66-
"README.md" = "worker_template/template/README.md"
67-
"tests" = "worker_template/template/tests"
68-
"uv.lock" = "worker_template/template/uv.lock"
69-
"worker_template" = "worker_template/template/worker_template"
63+
[tool.hatch.build.targets.sdist]
64+
only-include = ["worker_template"]
7065

7166
[tool.pytest.ini_options]
7267
asyncio_mode = "auto"

0 commit comments

Comments
 (0)