-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsetup.py
More file actions
109 lines (84 loc) · 3.01 KB
/
setup.py
File metadata and controls
109 lines (84 loc) · 3.01 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
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
import os
import sys
from pathlib import Path
from setuptools import find_packages, setup
from setuptools.dist import Distribution
cmdclass = {}
try:
from wheel.bdist_wheel import bdist_wheel as _base_bdist_wheel
class bdist_wheel(_base_bdist_wheel):
"""Always build platform wheels (never py3-none-any)."""
def finalize_options(self):
super().finalize_options()
self.root_is_pure = False
cmdclass = {"bdist_wheel": bdist_wheel}
except ImportError: # pragma: no cover
pass
PACKAGE_DIR = Path(__file__).parent / "phreeqpython"
def _candidate_libraries_for_target(target):
if target == "windows":
return ["lib/viphreeqc.dll", "lib/VIPhreeqc.dll"]
if target == "linux":
return ["lib/viphreeqc.so"]
if target == "macos":
return ["lib/viphreeqc.dylib"]
if target == "wasm":
return [".libs/viphreeqc.so", "lib/viphreeqcwasm.so"]
raise ValueError("Unsupported PHREEQPYTHON_TARGET: %s" % target)
def _resolve_target():
explicit_target = os.environ.get("PHREEQPYTHON_TARGET", "").strip().lower()
if explicit_target:
return explicit_target
if sys.platform == "win32":
return "windows"
if "linux" in sys.platform:
return "linux"
if sys.platform == "darwin":
return "macos"
if "emscripten" in sys.platform:
return "wasm"
raise RuntimeError("Unsupported platform for wheel build: %s" % sys.platform)
def _select_native_library(target):
candidates = _candidate_libraries_for_target(target)
for relative_path in candidates:
if (PACKAGE_DIR / relative_path).exists():
return relative_path
raise FileNotFoundError(
"No native library found for target '%s'. Expected one of: %s"
% (target, ", ".join(candidates))
)
TARGET = _resolve_target()
NATIVE_LIBRARY = _select_native_library(TARGET)
PACKAGE_DATA = ["database/*.dat", NATIVE_LIBRARY]
def _resolve_version():
base_version = "1.6.2"
local_version = os.environ.get("PHREEQPYTHON_LOCAL_VERSION", "").strip()
if local_version:
normalized = local_version.replace("-", ".").replace("_", ".").lower()
return f"{base_version}+{normalized}"
return base_version
class BinaryDistribution(Distribution):
"""Force wheel contents into platlib for bundled shared libs."""
def is_pure(self):
return False
def has_ext_modules(self):
return True
setup(
name="phreeqpython",
version=_resolve_version(),
description="Vitens viphreeqc wrapper and utilities",
url="https://github.com/Vitens/phreeqpython",
author="Abel Heinsbroek",
author_email="abel.heinsbroek@vitens.nl",
license="Apache Licence 2.0",
packages=find_packages(exclude=("tests", "tests.*")),
package_data={"phreeqpython": PACKAGE_DATA},
include_package_data=False,
zip_safe=False,
install_requires=["periodictable", "numpy"],
extras_require={
"kinetics": ["scipy"],
},
cmdclass=cmdclass,
distclass=BinaryDistribution,
)