From 8df98908ca36f673dcf571997c1e33fd6a4e9ea6 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Thu, 5 Sep 2024 05:40:18 -0400 Subject: [PATCH] build: add scripts directly to the moonraker package Per maintainers setuptool maintainers, the use of the "shared data" path is deprecated and no longer recommended. Signed-off-by: Eric Callahan --- pdm_build.py | 41 ++++++++++------------------------------- pyproject.toml | 6 +----- 2 files changed, 11 insertions(+), 36 deletions(-) diff --git a/pdm_build.py b/pdm_build.py index 47f5f5e..854ec1e 100644 --- a/pdm_build.py +++ b/pdm_build.py @@ -38,17 +38,10 @@ def retrieve_git_version(source_path: pathlib.Path) -> str: cmd = f"git -C {source_path} describe --always --tags --long --dirty" return _run_git_command(cmd) - -def pdm_build_clean(context: Context) -> None: - share_path: pathlib.Path = context.root.joinpath("share") - if share_path.exists(): - shutil.rmtree(str(share_path)) - def pdm_build_initialize(context: Context) -> None: context.ensure_build_dir() proj_name: str = context.config.metadata['name'] build_dir = pathlib.Path(context.build_dir) - data_path = context.root.joinpath(f"share/{proj_name}") pkg_path = build_dir.joinpath(__package_name__) pkg_path.mkdir(parents=True, exist_ok=True) rinfo_path: pathlib.Path = pkg_path.joinpath("release_info") @@ -74,30 +67,16 @@ def pdm_build_initialize(context: Context) -> None: # Write the release info to both the package and the data path rinfo_data = json.dumps(release_info, indent=4) rinfo_path.write_text(rinfo_data) - else: - rinfo_path = context.root.joinpath(f"{proj_name}/release_info") - if rinfo_path.is_file(): - rinfo_data = rinfo_path.read_text() - else: - rinfo_data = "" - data_path.mkdir(parents=True, exist_ok=True) - if rinfo_data: - data_path.joinpath("release_info").write_text(rinfo_data) - scripts_path: pathlib.Path = context.root.joinpath("scripts") - scripts_dest: pathlib.Path = data_path.joinpath("scripts") - scripts_dest.mkdir() - for item in scripts_path.iterdir(): - if item.name in ("__pycache__", "python_wheels"): - continue - if item.is_dir(): - shutil.copytree(str(item), str(scripts_dest.joinpath(item.name))) - else: - shutil.copy2(str(item), str(scripts_dest)) + scripts_path: pathlib.Path = context.root.joinpath("scripts") + scripts_dest: pathlib.Path = pkg_path.joinpath("scripts") + scripts_dest.mkdir() + for item in scripts_path.iterdir(): + if item.name in ("__pycache__", "python_wheels"): + continue + if item.is_dir(): + shutil.copytree(str(item), str(scripts_dest.joinpath(item.name))) + else: + shutil.copy2(str(item), str(scripts_dest)) git_ignore = build_dir.joinpath(".gitignore") if git_ignore.is_file(): git_ignore.unlink() - -def pdm_build_finalize(context: Context, artifact: pathlib.Path) -> None: - share_path: pathlib.Path = context.root.joinpath("share") - if share_path.exists(): - shutil.rmtree(str(share_path)) diff --git a/pyproject.toml b/pyproject.toml index 3356c14..591928b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,16 +67,12 @@ write_template = "__version__ = '{}'\n" [tool.pdm.build] excludes = ["./**/.git", "moonraker/moonraker.py"] includes = ["moonraker"] -source-includes = ["scripts"] editable-backend = "path" custom-hook = "pdm_build.py" -[tool.pdm.build.wheel-data] -data = [{path = "share/moonraker/**/*", relative-to = "."}] - [project.scripts] moonraker = "moonraker.server:main" [build-system] -requires = ["pdm-backend"] +requires = ["pdm-backend==2.3.3"] build-backend = "pdm.backend"