Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
53 lines (42 loc) · 1.65 KB
/
Copy pathsetup.py
File metadata and controls
53 lines (42 loc) · 1.65 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
"""Bundle the canonical public skills with binary distributions."""
from __future__ import annotations
import shutil
from pathlib import Path
from setuptools import setup
from setuptools.command.build_py import build_py
class BuildPy(build_py):
"""Copy public workflow documentation without a second maintained copy."""
_IGNORE_PATTERNS = ("__pycache__", "*.pyc")
def _skill_files(self) -> list[Path]:
"""Return canonical skill files excluding Python bytecode caches."""
source = Path(__file__).parent / "skills"
if not source.is_dir():
return []
return sorted(
path
for path in source.rglob("*")
if path.is_file()
and "__pycache__" not in path.parts
and path.suffix != ".pyc"
)
def get_outputs(self, include_bytecode: bool = True) -> list[str]:
"""Report copied ``dpdata/_skills`` files as build outputs."""
outputs = super().get_outputs(include_bytecode)
source = Path(__file__).parent / "skills"
destination = Path(self.build_lib) / "dpdata" / "_skills"
outputs.extend(
str(destination / path.relative_to(source)) for path in self._skill_files()
)
return outputs
def run(self):
super().run()
source = Path(__file__).parent / "skills"
destination = Path(self.build_lib) / "dpdata" / "_skills"
if destination.exists():
shutil.rmtree(destination)
shutil.copytree(
source,
destination,
ignore=shutil.ignore_patterns(*self._IGNORE_PATTERNS),
)
setup(cmdclass={"build_py": BuildPy})