Skip to content

Commit 13c8cd9

Browse files
committed
Modernize python build configuration
1 parent d83755b commit 13c8cd9

File tree

4 files changed

+87
-55
lines changed

4 files changed

+87
-55
lines changed

dedalus/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# have been included in the file 'LICENSE.txt', and is also available
66
# online at <http://www.gnu.org/licenses/gpl-3.0.html>.
77

8-
__version__ = "3.0.2"
8+
from .version import __version__
99

1010
# Import custom logging to setup rootlogger
1111
from .tools import logging as _logging_setup
@@ -22,3 +22,5 @@
2222
# Could remove pending https://github.com/pydata/numexpr/issues/344
2323
if os.getenv("NUMEXPR_MAX_THREADS") is None and os.getenv("OMP_NUM_THREADS") is not None:
2424
os.environ["NUMEXPR_MAX_THREADS"] = os.environ["OMP_NUM_THREADS"]
25+
26+
__all__ = ["__version__"]

pyproject.toml

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
[build-system]
2-
requires = ["cython >= 3.0.5",
3-
"mpi4py >= 2.0.0",
4-
"numpy >= 1.20.0",
5-
"setuptools",
6-
"wheel"]
2+
requires = [
3+
"Cython >= 3.0.5",
4+
"mpi4py >= 2.0.0",
5+
"numpy >= 1.20.0",
6+
"setuptools",
7+
"wheel"
8+
]
9+
build-backend = "setuptools.build_meta"
10+
11+
[project]
12+
name = "dedalus"
13+
version = "3.0.2"
14+
authors = [
15+
{ name = "Keaton J. Burns", email = "[email protected]" }
16+
]
17+
description = "A flexible framework for solving PDEs with modern spectral methods."
18+
long-description = { file = "README.md", content-type = "text/markdown" }
19+
readme = { file = "README.md", content-type = "text/markdown" }
20+
license = { file = "LICENSE", content-type = "text/plain" }
21+
classifiers = ["Programming Language :: Python :: 3"]
22+
requires-python = ">=3.9"
23+
dynamic = ["dependencies"]
24+
25+
[project.urls]
26+
homepage = "http://dedalus-project.org"
27+
28+
[project.entry-points."xarray.backends"]
29+
dedalus = "dedalus.tools.post:DedalusXarrayBackend"
30+
31+
[tool.setuptools]
32+
packages = ["dedalus"]
33+
package-data = { dedalus = ["dedalus.cfg", "examples.tar.gz"] }
34+
35+
[tool.setuptools.dynamic]
36+
dependencies = {file = "requirements.txt"}
37+
38+
[project.optional-dependencies]
39+
xarray = ["xarray"]
40+
41+
[project.scripts]
42+
dedalus = "dedalus.tools.post:DedalusXarrayBackend"
43+

requirements.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
docopt
2+
h5py >= 3.0.0
3+
matplotlib
4+
mpi4py >= 2.0.0
5+
numexpr
6+
numpy >= 1.20.0
7+
py
8+
pytest
9+
pytest-benchmark
10+
pytest-cov
11+
pytest-parallel
12+
scipy >= 1.4.0

setup.py

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,6 @@ def get_lib(name):
8282
if prefix := get_library_prefix(name):
8383
return os.path.join(prefix, "lib")
8484

85-
def get_version(rel_path):
86-
"""Read version from a file via text parsing, following PyPA guide."""
87-
def read(rel_path):
88-
here = os.path.abspath(os.path.dirname(__file__))
89-
with codecs.open(os.path.join(here, rel_path), "r") as fp:
90-
return fp.read()
91-
for line in read(rel_path).splitlines():
92-
if line.startswith("__version__"):
93-
delim = '"' if '"' in line else "'"
94-
return line.split(delim)[1]
95-
else:
96-
raise RuntimeError("Unable to find version string.")
97-
9885
# Configuratin
9986
INCLUDE_MPI = True
10087
INCLUDE_FFTW = True
@@ -179,26 +166,6 @@ def read(rel_path):
179166
extra_compile_args=extra_compile_args,
180167
extra_link_args=extra_link_args))
181168

182-
# Runtime requirements
183-
install_requires = [
184-
"docopt",
185-
"h5py >= 3.0.0",
186-
"matplotlib",
187-
"mpi4py >= 2.0.0",
188-
"numexpr",
189-
"numpy >= 1.20.0",
190-
"py",
191-
"pytest",
192-
"pytest-benchmark",
193-
"pytest-cov",
194-
"pytest-parallel",
195-
"scipy >= 1.4.0",
196-
"xarray"]
197-
198-
# Grab long_description from README
199-
with open("README.md") as f:
200-
long_description = f.read()
201-
202169
# Cython directives
203170
compiler_directives = {}
204171
compiler_directives["language_level"] = 3
@@ -217,24 +184,38 @@ def run(self):
217184
# Run the original build command
218185
_build.run(self)
219186

187+
# Set version
188+
if os.path.exists(".git"):
189+
# If on a git repository, we can
190+
# get the version from the commit sha
191+
kwargs = {
192+
"use_scm_version": {
193+
"write_to": "pysr/version.py",
194+
},
195+
"setup_requires": ["setuptools", "setuptools_scm"],
196+
}
197+
else:
198+
# As a backup, we read from the pyproject.toml
199+
import re
200+
201+
with open(os.path.join(os.path.dirname(__file__), "pyproject.toml")) as f:
202+
data = f.read()
203+
version = re.search(r'version = "(.*)"', data).group(1)
204+
# TODO: When limited to Python 3.11, can use tomllib from the standard library
205+
206+
# Write the version to version.py
207+
with open(os.path.join(os.path.dirname(__file__), "dedalus", "version.py"), "w") as f:
208+
f.write(f'__version__ = "{version}"')
209+
210+
kwargs = {
211+
"use_scm_version": False,
212+
"version": version,
213+
}
214+
215+
220216
# Setup
221217
print()
222218
setup(
223-
name="dedalus",
224-
version=get_version("dedalus/__init__.py"),
225-
author="Keaton J. Burns",
226-
author_email="[email protected]",
227-
description="A flexible framework for solving PDEs with modern spectral methods.",
228-
long_description=long_description,
229-
long_description_content_type="text/markdown",
230-
url="http://dedalus-project.org",
231-
classifiers=["Programming Language :: Python :: 3"],
232-
python_requires=">=3.9",
233-
install_requires=install_requires,
234-
license="GPL3",
235-
packages=setuptools.find_packages(),
236-
package_data={"": ["dedalus.cfg", "examples.tar.gz"]},
237219
ext_modules=cythonize(extensions, compiler_directives=compiler_directives),
238-
cmdclass={"build": build},
239-
entry_points={"xarray.backends": ["dedalus=dedalus.tools.post:DedalusXarrayBackend"]})
220+
cmdclass={"build": build})
240221

0 commit comments

Comments
 (0)