11import os
2+ import shutil
23import tarfile
34from copy import deepcopy
45from importlib .resources import as_file , files
@@ -48,25 +49,26 @@ def build_template_tarball() -> None:
4849def 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
6569def _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
0 commit comments