Skip to content

Commit

Permalink
build: add scripts directly to the moonraker package
Browse files Browse the repository at this point in the history
Per maintainers setuptool maintainers, the use of the "shared data"
path is deprecated and no longer recommended.

Signed-off-by:  Eric Callahan <[email protected]>
  • Loading branch information
Arksine committed Sep 5, 2024
1 parent f735c04 commit 8df9890
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 36 deletions.
41 changes: 10 additions & 31 deletions pdm_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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))
6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 8df9890

Please sign in to comment.