-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_wheel.py
53 lines (36 loc) · 1.48 KB
/
build_wheel.py
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
"""Build wheel ensuring Windows OS and python >=3.10."""
import os
import re
import subprocess
import sys
import warnings
def update_pyproject_version():
"""Get version from version.py and update pyproject.toml."""
with open("ripple1d/version.py", "r") as f:
version_file_content = f.read()
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file_content, re.M)
if version_match:
version = version_match.group(1)
else:
raise RuntimeError("Unable to find version string in version.py")
with open("pyproject.toml", "r") as f:
pyproject_content = f.read()
pyproject_content = re.sub(r'^version = ".*"$', f'version = "{version}"', pyproject_content, flags=re.M)
with open("pyproject.toml", "w") as f:
f.write(pyproject_content)
update_pyproject_version()
if os.name != "nt":
warnings.warn("Windows OS is required to run ripple1d. Many features will not work on other OS's.")
if sys.version_info < (3, 10):
sys.exit("Python 3.10 or greater is required to build this package.")
platform_tag = "win_amd64"
subprocess.check_call([os.sys.executable, "-m", "build"])
dist_dir = "dist"
for filename in os.listdir(dist_dir):
if filename.endswith(".whl"):
parts = filename.split("-")
parts[2] = "py310"
parts[-1] = platform_tag + ".whl"
new_filename = "-".join(parts)
os.rename(os.path.join(dist_dir, filename), os.path.join(dist_dir, new_filename))
break