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
|
#!/usr/bin/env python3
import argparse
import glob
import os
import shutil
import tarfile
import tempfile
from pathlib import Path
from subprocess import check_call
REPO_ROOT = Path(__file__).parents[2]
os.chdir(REPO_ROOT)
def run(command, cwd=None):
print(f"Running command: {command}")
return check_call(command, shell=True, cwd=cwd)
def main(sdist_path=None):
run("pip install --no-build-isolation -r requirements-dev-lock.txt")
run(
"pip install --no-build-isolation -r requirements/download-deps/bootstrap-lock.txt"
)
if sdist_path is None:
wheel_dist = _build_sdist_and_wheel()
else:
wheel_dist = _build_wheel(sdist_path)
run("pip install %s" % wheel_dist)
def _build_wheel(sdist_path):
build_dir = REPO_ROOT / "dist"
with tempfile.TemporaryDirectory() as tempdir:
with tarfile.open(sdist_path, "r:gz") as tar:
tar.extractall(tempdir)
unpacked_sdist = os.path.join(tempdir, os.listdir(tempdir)[0])
run(f"python -m build -w -o {build_dir}", cwd=unpacked_sdist)
return _find_wheel_file()
return wheel_dist
def _build_sdist_and_wheel():
if os.path.isdir("dist") and os.listdir("dist"):
shutil.rmtree("dist")
run("python -m build")
return _find_wheel_file()
def _find_wheel_file():
return glob.glob(os.path.join("dist", "*.whl"))[0]
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--use-sdist", default=None, type=os.path.abspath)
args = parser.parse_args()
main(args.use_sdist)
|