Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
45 lines (34 loc) · 1.59 KB
/
Copy pathsetup.py
File metadata and controls
45 lines (34 loc) · 1.59 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
"""Package a prebuilt native executable into a platform wheel.
Editable and source installs are Python-only. scripts/release.py supplies the binary
and build metadata after verification. Installing never downloads executables.
"""
import os
import shutil
from pathlib import Path
from setuptools import Distribution, setup
from setuptools.command.bdist_wheel import bdist_wheel
from setuptools.command.build_py import build_py
class BundleBuild(build_py):
def run(self):
super().run()
destination = Path(self.build_lib) / "leanguard" / "bin"
if binary := os.environ.get("LEANGUARD_BUNDLE_BINARY"):
destination.mkdir(parents=True, exist_ok=True)
shutil.copy2(binary, destination / "leanguard")
(destination / "leanguard").chmod(0o755)
metadata = Path(os.environ["LEANGUARD_BUILD_METADATA"])
for name in ("build-details.json", "proof-audit.txt", "THIRD_PARTY_NOTICES"):
shutil.copy2(metadata / name, destination / name)
elif destination.exists():
# Reusing a build directory must not leak a previous platform binary.
shutil.rmtree(destination)
class NativeDistribution(Distribution):
def has_ext_modules(self):
return bool(os.environ.get("LEANGUARD_BUNDLE_BINARY"))
class PlatformWheel(bdist_wheel):
def get_tag(self):
python, abi, platform = super().get_tag()
return ("py3", "none", platform) if not self.root_is_pure else (python, abi, platform)
setup(
distclass=NativeDistribution, cmdclass={"build_py": BundleBuild, "bdist_wheel": PlatformWheel}
)