-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathsetup.py
More file actions
183 lines (152 loc) · 5.56 KB
/
setup.py
File metadata and controls
183 lines (152 loc) · 5.56 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import json
import os
import subprocess
import sys
import setuptools
import skbuild
from setuptools_scm import get_version
version = get_version(relative_to=__file__, write_to="python/resdata/version.py")
# Corporate networks tend to be behind a proxy server with their own non-public
# SSL certificates. Conan keeps its own certificates, whose path we can override
if "CONAN_CACERT_PATH" not in os.environ:
# Look for a RHEL-compatible system-wide file
for file_ in ("/etc/pki/tls/cert.pem",):
if not os.path.isfile(file_):
continue
os.environ["CONAN_CACERT_PATH"] = file_
break
def get_skbuild_dir():
"""Get the scikit-build cmake build directory path."""
import platform as plat
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
return os.path.abspath(
os.path.join(
"_skbuild",
f"{plat.system().lower()}-{plat.machine()}-{python_version}",
"cmake-build",
)
)
def run_conan_install():
"""Run conan install to generate CMake presets and toolchain file for Conan 2."""
import shutil
conan_exe = shutil.which("conan")
subprocess.run(
[conan_exe, "profile", "detect", "--force"],
check=False, # Ignore if profile already exists
)
skbuild_dir = get_skbuild_dir()
os.makedirs(skbuild_dir, exist_ok=True)
subprocess.run(
[
conan_exe,
"install",
".",
f"--output-folder={skbuild_dir}",
"--build=missing",
],
check=True,
)
return skbuild_dir
def get_cmake_args_from_preset(skbuild_dir):
"""Extract CMake arguments from Conan-generated CMakePresets.json."""
presets_file = os.path.join(skbuild_dir, "CMakePresets.json")
cmake_args = []
if os.path.exists(presets_file):
with open(presets_file) as f:
presets = json.load(f)
if presets.get("configurePresets"):
preset = presets["configurePresets"][0]
if "toolchainFile" in preset:
toolchain = preset["toolchainFile"]
if not os.path.isabs(toolchain):
toolchain = os.path.join(skbuild_dir, toolchain)
cmake_args.append(f"-DCMAKE_TOOLCHAIN_FILE='{toolchain}'")
for key, value in preset.get("cacheVariables", {}).items():
if isinstance(value, dict):
value = value.get("value", "")
cmake_args.append(f"-D{key}={value}")
for key, value in preset.get("environment", {}).items():
if "$penv{" in value:
import re
value = re.sub(
r"\$penv\{(\w+)\}",
lambda m: os.environ.get(m.group(1), ""),
value,
)
os.environ[key] = value
return cmake_args
skbuild_dir = run_conan_install()
CMAKE_ARGS_FROM_PRESET = get_cmake_args_from_preset(skbuild_dir)
with open("README.md") as f:
long_description = f.read()
def utility_wrappers():
"""
Wrappers around resdata's "application" utilities. These are only supported on
Linux at this time so only create the wrapper when on Linux.
"""
if sys.platform != "linux":
return []
return [
name + " = resdata.bin:main"
for name in (
"convert.x", # deprecated
"rd_pack.x",
"rd_unpack.x",
"grdecl_test.x", # deprecated
"kw_list.x", # deprecated
"load_test.x", # deprecated
)
] + ["summary.x = view_summary.__main__:main"]
skbuild.setup(
name="resdata",
author="Equinor ASA",
author_email="fg_sib-scout@equinor.com",
description="Package for reading and writing the fortran result files from reservoir simulators",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/equinor/resdata",
packages=setuptools.find_packages(
where="python",
exclude=["*.tests", "*.tests.*", "tests.*", "tests", "ert.*", "ert"],
),
package_dir={"": "python"},
license="GPL-3.0",
platforms="any",
install_requires=[
"cwrap",
"numpy",
"pandas",
"natsort",
"resfo-utilities>=0.4.0",
],
setup_requires=["conan>=2"],
entry_points={"console_scripts": utility_wrappers()},
cmake_args=CMAKE_ARGS_FROM_PRESET
+ [
"-DRD_VERSION=" + version,
"-DBUILD_APPLICATIONS=" + ("ON" if sys.platform == "linux" else "OFF"),
"-DBUILD_TESTS=OFF",
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
"-DCMAKE_INSTALL_BINDIR=python/resdata/.bin",
"-DCMAKE_INSTALL_LIBDIR=python/resdata/.libs",
"-DCMAKE_INSTALL_INCLUDEDIR=python/resdata/.include",
],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Other Environment",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Natural Language :: English",
"Programming Language :: Python",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Software Development :: Libraries",
"Topic :: Utilities",
],
version=version,
)