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 <arksine.code@gmail.com>
This commit is contained in:
41
pdm_build.py
41
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"
|
cmd = f"git -C {source_path} describe --always --tags --long --dirty"
|
||||||
return _run_git_command(cmd)
|
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:
|
def pdm_build_initialize(context: Context) -> None:
|
||||||
context.ensure_build_dir()
|
context.ensure_build_dir()
|
||||||
proj_name: str = context.config.metadata['name']
|
proj_name: str = context.config.metadata['name']
|
||||||
build_dir = pathlib.Path(context.build_dir)
|
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 = build_dir.joinpath(__package_name__)
|
||||||
pkg_path.mkdir(parents=True, exist_ok=True)
|
pkg_path.mkdir(parents=True, exist_ok=True)
|
||||||
rinfo_path: pathlib.Path = pkg_path.joinpath("release_info")
|
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
|
# Write the release info to both the package and the data path
|
||||||
rinfo_data = json.dumps(release_info, indent=4)
|
rinfo_data = json.dumps(release_info, indent=4)
|
||||||
rinfo_path.write_text(rinfo_data)
|
rinfo_path.write_text(rinfo_data)
|
||||||
else:
|
scripts_path: pathlib.Path = context.root.joinpath("scripts")
|
||||||
rinfo_path = context.root.joinpath(f"{proj_name}/release_info")
|
scripts_dest: pathlib.Path = pkg_path.joinpath("scripts")
|
||||||
if rinfo_path.is_file():
|
scripts_dest.mkdir()
|
||||||
rinfo_data = rinfo_path.read_text()
|
for item in scripts_path.iterdir():
|
||||||
else:
|
if item.name in ("__pycache__", "python_wheels"):
|
||||||
rinfo_data = ""
|
continue
|
||||||
data_path.mkdir(parents=True, exist_ok=True)
|
if item.is_dir():
|
||||||
if rinfo_data:
|
shutil.copytree(str(item), str(scripts_dest.joinpath(item.name)))
|
||||||
data_path.joinpath("release_info").write_text(rinfo_data)
|
else:
|
||||||
scripts_path: pathlib.Path = context.root.joinpath("scripts")
|
shutil.copy2(str(item), str(scripts_dest))
|
||||||
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))
|
|
||||||
git_ignore = build_dir.joinpath(".gitignore")
|
git_ignore = build_dir.joinpath(".gitignore")
|
||||||
if git_ignore.is_file():
|
if git_ignore.is_file():
|
||||||
git_ignore.unlink()
|
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))
|
|
||||||
|
@@ -67,16 +67,12 @@ write_template = "__version__ = '{}'\n"
|
|||||||
[tool.pdm.build]
|
[tool.pdm.build]
|
||||||
excludes = ["./**/.git", "moonraker/moonraker.py"]
|
excludes = ["./**/.git", "moonraker/moonraker.py"]
|
||||||
includes = ["moonraker"]
|
includes = ["moonraker"]
|
||||||
source-includes = ["scripts"]
|
|
||||||
editable-backend = "path"
|
editable-backend = "path"
|
||||||
custom-hook = "pdm_build.py"
|
custom-hook = "pdm_build.py"
|
||||||
|
|
||||||
[tool.pdm.build.wheel-data]
|
|
||||||
data = [{path = "share/moonraker/**/*", relative-to = "."}]
|
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
moonraker = "moonraker.server:main"
|
moonraker = "moonraker.server:main"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["pdm-backend"]
|
requires = ["pdm-backend==2.3.3"]
|
||||||
build-backend = "pdm.backend"
|
build-backend = "pdm.backend"
|
||||||
|
Reference in New Issue
Block a user