-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_package.py
More file actions
25 lines (22 loc) · 883 Bytes
/
build_package.py
File metadata and controls
25 lines (22 loc) · 883 Bytes
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
"""
This script builds a Python package using the `build` module.
It allows for passing additional arguments to the build command and
supports specifying a version number via command line arguments.
It also sets the `PACKAGE_VERSION` environment variable if a version is provided.
"""
import os
import subprocess
import sys
if "--version" in sys.argv:
idx = sys.argv.index("--version")
version = sys.argv[idx + 1]
os.environ["PACKAGE_VERSION"] = version
sys.argv.pop(idx) # remove --version
sys.argv.pop(idx) # remove version value
print(f"{sys.executable} -m build {' '.join(sys.argv[1:])}")
try:
subprocess.run([sys.executable, "-m", "build"] + sys.argv[1:],
check=True, stderr=sys.stderr, stdout=sys.stdout)
except subprocess.CalledProcessError as e:
print(f"Build failed with error code {e.returncode}")
sys.exit(e.returncode)