build: shared data fix
Make sure the scripts directory is included in the "data/share" folder in the wheel. In addition, remove the stray .gitignore that is included when building a wheel from an sdist. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
83371cf135
commit
c2409e813e
|
@ -11,3 +11,4 @@ start_moonraker
|
||||||
.pdm-python
|
.pdm-python
|
||||||
build
|
build
|
||||||
dist
|
dist
|
||||||
|
share
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
# Wheel Setup Script for generating metadata
|
||||||
|
#
|
||||||
|
# Copyright (C) 2023 Eric Callahan <arksine.code@gmail.com>
|
||||||
|
#
|
||||||
|
# This file may be distributed under the terms of the GNU GPLv3 license
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import pathlib
|
||||||
|
import subprocess
|
||||||
|
import shlex
|
||||||
|
import json
|
||||||
|
import shutil
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from typing import Dict, Any, TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from pdm.backend.hooks.base import Context
|
||||||
|
|
||||||
|
__package_name__ = "moonraker"
|
||||||
|
__dependencies__ = "scripts/system-dependencies.json"
|
||||||
|
|
||||||
|
def _run_git_command(cmd: str) -> str:
|
||||||
|
prog = shlex.split(cmd)
|
||||||
|
process = subprocess.Popen(
|
||||||
|
prog, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||||
|
)
|
||||||
|
ret, err = process.communicate()
|
||||||
|
retcode = process.wait()
|
||||||
|
if retcode == 0:
|
||||||
|
return ret.strip().decode()
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def get_commit_sha(source_path: pathlib.Path) -> str:
|
||||||
|
cmd = f"git -C {source_path} rev-parse HEAD"
|
||||||
|
return _run_git_command(cmd)
|
||||||
|
|
||||||
|
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")
|
||||||
|
rinfo_data: str = ""
|
||||||
|
if context.root.joinpath(".git").exists():
|
||||||
|
build_ver: str = context.config.metadata['version']
|
||||||
|
build_time = datetime.now(timezone.utc)
|
||||||
|
urls: Dict[str, str] = context.config.metadata['urls']
|
||||||
|
release_info: Dict[str, Any] = {
|
||||||
|
"project_name": proj_name,
|
||||||
|
"package_name": __package_name__,
|
||||||
|
"urls": {key.lower(): val for key, val in urls.items()},
|
||||||
|
"package_version": build_ver,
|
||||||
|
"git_version": retrieve_git_version(context.root),
|
||||||
|
"commit_sha": get_commit_sha(context.root),
|
||||||
|
"build_time": datetime.isoformat(build_time, timespec="seconds")
|
||||||
|
}
|
||||||
|
if __dependencies__:
|
||||||
|
deps = pathlib.Path(context.root).joinpath(__dependencies__)
|
||||||
|
if deps.is_file():
|
||||||
|
dep_info: Dict[str, Any] = json.loads(deps.read_bytes())
|
||||||
|
release_info["system_dependencies"] = dep_info
|
||||||
|
# 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))
|
||||||
|
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))
|
|
@ -67,8 +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 = "scripts/pdm_build_dist.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"
|
||||||
|
|
|
@ -1,80 +0,0 @@
|
||||||
# Wheel Setup Script for generating metadata
|
|
||||||
#
|
|
||||||
# Copyright (C) 2023 Eric Callahan <arksine.code@gmail.com>
|
|
||||||
#
|
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
import pathlib
|
|
||||||
import subprocess
|
|
||||||
import shlex
|
|
||||||
import json
|
|
||||||
import shutil
|
|
||||||
from datetime import datetime, timezone
|
|
||||||
from typing import Dict, Any, TYPE_CHECKING
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from pdm.backend.hooks.base import Context
|
|
||||||
|
|
||||||
__package_name__ = "moonraker"
|
|
||||||
__dependencies__ = "scripts/system-dependencies.json"
|
|
||||||
|
|
||||||
def _run_git_command(cmd: str) -> str:
|
|
||||||
prog = shlex.split(cmd)
|
|
||||||
process = subprocess.Popen(
|
|
||||||
prog, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
|
||||||
)
|
|
||||||
ret, err = process.communicate()
|
|
||||||
retcode = process.wait()
|
|
||||||
if retcode == 0:
|
|
||||||
return ret.strip().decode()
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def get_commit_sha(source_path: pathlib.Path) -> str:
|
|
||||||
cmd = f"git -C {source_path} rev-parse HEAD"
|
|
||||||
return _run_git_command(cmd)
|
|
||||||
|
|
||||||
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_initialize(context: Context) -> None:
|
|
||||||
context.ensure_build_dir()
|
|
||||||
build_ver: str = context.config.metadata['version']
|
|
||||||
proj_name: str = context.config.metadata['name']
|
|
||||||
urls: Dict[str, str] = context.config.metadata['urls']
|
|
||||||
build_dir = pathlib.Path(context.build_dir)
|
|
||||||
rel_dpath = f"{__package_name__}-{build_ver}.data/data/share/{proj_name}"
|
|
||||||
data_path = build_dir.joinpath(rel_dpath)
|
|
||||||
pkg_path = build_dir.joinpath(__package_name__)
|
|
||||||
build_time = datetime.now(timezone.utc)
|
|
||||||
release_info: Dict[str, Any] = {
|
|
||||||
"project_name": proj_name,
|
|
||||||
"package_name": __package_name__,
|
|
||||||
"urls": {key.lower(): val for key, val in urls.items()},
|
|
||||||
"package_version": build_ver,
|
|
||||||
"git_version": retrieve_git_version(context.root),
|
|
||||||
"commit_sha": get_commit_sha(context.root),
|
|
||||||
"build_time": datetime.isoformat(build_time, timespec="seconds")
|
|
||||||
}
|
|
||||||
if __dependencies__:
|
|
||||||
deps = pathlib.Path(context.root).joinpath(__dependencies__)
|
|
||||||
if deps.is_file():
|
|
||||||
dep_info: Dict[str, Any] = json.loads(deps.read_bytes())
|
|
||||||
release_info["system_dependencies"] = dep_info
|
|
||||||
# Write the release info to both the package and the data path
|
|
||||||
rinfo_data = json.dumps(release_info, indent=4)
|
|
||||||
data_path.mkdir(parents=True, exist_ok=True)
|
|
||||||
pkg_path.mkdir(parents=True, exist_ok=True)
|
|
||||||
data_path.joinpath("release_info").write_text(rinfo_data)
|
|
||||||
pkg_path.joinpath("release_info").write_text(rinfo_data)
|
|
||||||
scripts_path = context.root.joinpath("scripts")
|
|
||||||
scripts_dest = data_path.joinpath("scripts")
|
|
||||||
scripts_dest.mkdir()
|
|
||||||
for item in scripts_path.iterdir():
|
|
||||||
if item.name == "__pycache__":
|
|
||||||
continue
|
|
||||||
if item.is_dir():
|
|
||||||
shutil.copytree(str(item), str(scripts_dest.joinpath(item.name)))
|
|
||||||
else:
|
|
||||||
shutil.copy2(str(item), str(scripts_dest))
|
|
Loading…
Reference in New Issue