Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
86 lines (68 loc) · 2.44 KB
/
Copy pathsetup.py
File metadata and controls
86 lines (68 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""Setuptools build hooks for packaging the MaxwellLink workspace payload.
This module customizes ``build_py`` so the source-tree payload used by
``mxl-init`` is copied into ``maxwelllink/_workspace_payload`` in the built
wheel.
"""
from __future__ import annotations
from pathlib import Path
import os
import shutil
import sys
from setuptools import Extension, setup
from setuptools.command.build_py import build_py as _build_py
_WORKSPACE_ITEMS: tuple[tuple[str, str], ...] = (
("AGENTS.md", "AGENTS.md"),
("README.md", "README.md"),
("HPC_PROFILE.json", "HPC_PROFILE.json"),
("src", "src"),
("tests", "tests"),
("skills", "skills"),
("docs/source", "docs/source"),
("media", "media"),
("tutorials", "tutorials"),
)
def _copy_workspace_payload(repo_root: Path, payload_root: Path) -> None:
"""Copy workspace payload files into the wheel build directory.
Parameters
----------
repo_root : pathlib.Path
Repository root containing source payload paths.
payload_root : pathlib.Path
Destination path inside ``build_lib`` where payload files are staged.
Raises
------
FileNotFoundError
If any required payload item is missing in ``repo_root``.
"""
if payload_root.exists():
shutil.rmtree(payload_root)
payload_root.mkdir(parents=True, exist_ok=True)
ignore = shutil.ignore_patterns("__pycache__", "*.pyc", ".DS_Store", "*.egg-info")
for src_rel, dst_rel in _WORKSPACE_ITEMS:
src = repo_root / src_rel
dst = payload_root / dst_rel
if not src.exists():
raise FileNotFoundError(f"Missing required workspace payload path: {src}")
if src.is_dir():
shutil.copytree(src, dst, dirs_exist_ok=True, ignore=ignore)
else:
dst.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(src, dst)
class build_py(_build_py):
"""Custom ``build_py`` command that stages the workspace payload."""
def run(self) -> None:
"""Run standard build and then copy the workspace payload.
Returns
-------
None
This method updates files in ``self.build_lib`` in place.
"""
super().run()
repo_root = Path(__file__).resolve().parent
payload_root = Path(self.build_lib) / "maxwelllink" / "_workspace_payload"
_copy_workspace_payload(repo_root, payload_root)
setup(
cmdclass={
"build_py": build_py,
},
)