-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
139 lines (98 loc) · 4.47 KB
/
setup.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import sys
import re
import warnings
from setuptools import setup, Extension
import setuptools
FULLVERSION = "2.1.0"
PYTHON_REQUIRES = (3, 8)
RUNTIME_LIBRARY_DIRS = []
def check_version():
python_major = sys.version_info[0]
python_minor = sys.version_info[1]
# Capture the version string:
# 1.22.0.dev0+ ... -> ISRELEASED == False, VERSION == 1.22.0
# 1.22.0rc1+ ... -> ISRELEASED == False, VERSION == 1.22.0
# 1.22.0 ... -> ISRELEASED == True, VERSION == 1.22.0
# 1.22.0rc1 ... -> ISRELEASED == True, VERSION == 1.22.0
is_released = re.search(r'(dev|\+)', FULLVERSION) is None
_V_MATCH = re.match(r'(\d+)\.(\d+)\.(\d+)', FULLVERSION)
if _V_MATCH is None:
raise RuntimeError(f'Cannot parse version {FULLVERSION}')
major, minor, micro = _V_MATCH.groups()
version = f"{major}.{minor}.{micro}"
# Python supported version checks
if (python_major, python_minor) < PYTHON_REQUIRES:
raise RuntimeError(f"Python version >= {PYTHON_REQUIRES[0]}.{PYTHON_REQUIRES[1]} required.")
if (python_major, python_minor) > (3, 11):
warnings.warn(f"goopylib {version} may not yet support Python {python_major}.{python_minor}.", RuntimeWarning)
# Update the pyproject.toml file with these version details
with open("pyproject.toml", "r") as f:
content = f.read()
content = re.sub("version = [\",'].*[\",']",
f"version = \"{FULLVERSION}\"", content)
content = re.sub("requires-python = [\",'].*[\",']",
f"requires-python = \">={PYTHON_REQUIRES[0]}.{PYTHON_REQUIRES[1]}\"", content)
with open("pyproject.toml", "w") as f:
f.write(content)
# Update the setup.cfg file with these version details
with open("setup.cfg", "r") as f:
content = f.read()
content = re.sub("version = .*",
f"version = {FULLVERSION}", content)
content = re.sub("python_requires = .*",
f"python_requires = >={PYTHON_REQUIRES[0]}.{PYTHON_REQUIRES[1]}", content)
with open("setup.cfg", "w") as f:
f.write(content)
# Update the __init__.py file with these version details
with open("goopylib/__init__.py", "r") as f:
content = f.read()
content = re.sub("__version__ = \".*\"",
f"__version__ = \"{FULLVERSION}\"", content)
with open("goopylib/__init__.py", "w") as f:
f.write(content)
if sys.platform == "darwin":
compile_args = ["-std=c++20", "-Wno-macro-redefined", "-Wno-unused-function", "-Wno-unknown-pragmas",
"-Wno-self-assign-overloaded"]
compile_args += ["-Wno-deprecated-volatile"] # suppress warnings caused by glm
library_dirs = ["binaries/lib-macos"]
data_files = []
elif sys.platform == "win32":
compile_args = ["/std:c++20", "/wd4005", "/wd4068"] # suppress macro-redefinition & unknown pragma warnings
library_dirs = ["binaries/lib-vc2022/Release/"] # TODO figure out how to remove Release folder
data_files = [("goopylib", ["binaries/lib-vc2022/Release/goopylib.dll"])]
else:
compile_args = []
library_dirs = []
data_files = []
ext_kwargs = {"include_dirs": [".", "src", "vendor", "vendor/glad", "vendor/glm",
"vendor/spdlog/include", "vendor/GLFW/include", "vendor/pybind11/include"],
"library_dirs": library_dirs,
"runtime_library_dirs": RUNTIME_LIBRARY_DIRS,
"libraries": ["goopylib"],
"extra_compile_args": compile_args}
def get_extension(path: str):
return Extension(name=f"goopylib.{path}",
sources=[f"goopylib/{path.replace('.', '/')}.cpp"],
**ext_kwargs)
def find_extensions():
return [
get_extension("color.color"),
get_extension("core.core"),
get_extension("core.window"),
get_extension("maths.easing"),
get_extension("objects.renderable"),
get_extension("objects.triangle"),
get_extension("objects.quad"),
get_extension("objects.rectangle"),
get_extension("objects.line"),
get_extension("objects.ellipse"),
get_extension("objects.circle"),
get_extension("objects.image"),
get_extension("scene.camera"),
get_extension("scene.camera_controller"),
]
if __name__ == "__main__":
check_version()
setup(packages=setuptools.find_packages(),
ext_modules=find_extensions(),
data_files=data_files)