Skip to content

Commit

Permalink
Modernize python build configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Apr 29, 2024
1 parent d83755b commit 8265162
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 55 deletions.
4 changes: 3 additions & 1 deletion dedalus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# have been included in the file 'LICENSE.txt', and is also available
# online at <http://www.gnu.org/licenses/gpl-3.0.html>.

__version__ = "3.0.2"
from .version import __version__

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

__all__ = ["__version__"]
47 changes: 42 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
[build-system]
requires = ["cython >= 3.0.5",
"mpi4py >= 2.0.0",
"numpy >= 1.20.0",
"setuptools",
"wheel"]
requires = [
"Cython >= 3.0.5",
"mpi4py >= 2.0.0",
"numpy >= 1.20.0",
"setuptools",
"wheel"
]
build-backend = "setuptools.build_meta"

[project]
name = "dedalus"
version = "3.0.2"
authors = [
{ name = "Keaton J. Burns", email = "[email protected]" }
]
description = "A flexible framework for solving PDEs with modern spectral methods."
long-description = { file = "README.md", content-type = "text/markdown" }
readme = { file = "README.md", content-type = "text/markdown" }
license = { file = "LICENSE", content-type = "text/plain" }
classifiers = ["Programming Language :: Python :: 3"]
requires-python = ">=3.9"
dynamic = ["dependencies"]

[project.urls]
homepage = "http://dedalus-project.org"

[project.entry-points."xarray.backends"]
dedalus = "dedalus.tools.post:DedalusXarrayBackend"

[tool.setuptools]
packages = ["dedalus"]
package-data = { dedalus = ["dedalus.cfg", "examples.tar.gz"] }

[tool.setuptools.dynamic]
dependencies = {file = "requirements.txt"}

[project.optional-dependencies]
xarray = ["xarray"]

[project.scripts]
dedalus = "dedalus.tools.post:DedalusXarrayBackend"

12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
docopt
h5py >= 3.0.0
matplotlib
mpi4py >= 2.0.0
numexpr
numpy >= 1.20.0
py
pytest
pytest-benchmark
pytest-cov
pytest-parallel
scipy >= 1.4.0
79 changes: 30 additions & 49 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,6 @@ def get_lib(name):
if prefix := get_library_prefix(name):
return os.path.join(prefix, "lib")

def get_version(rel_path):
"""Read version from a file via text parsing, following PyPA guide."""
def read(rel_path):
here = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(here, rel_path), "r") as fp:
return fp.read()
for line in read(rel_path).splitlines():
if line.startswith("__version__"):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
else:
raise RuntimeError("Unable to find version string.")

# Configuratin
INCLUDE_MPI = True
INCLUDE_FFTW = True
Expand Down Expand Up @@ -179,26 +166,6 @@ def read(rel_path):
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args))

# Runtime requirements
install_requires = [
"docopt",
"h5py >= 3.0.0",
"matplotlib",
"mpi4py >= 2.0.0",
"numexpr",
"numpy >= 1.20.0",
"py",
"pytest",
"pytest-benchmark",
"pytest-cov",
"pytest-parallel",
"scipy >= 1.4.0",
"xarray"]

# Grab long_description from README
with open("README.md") as f:
long_description = f.read()

# Cython directives
compiler_directives = {}
compiler_directives["language_level"] = 3
Expand All @@ -217,24 +184,38 @@ def run(self):
# Run the original build command
_build.run(self)

# Set version
if os.path.exists(".git"):
# If on a git repository, we can
# get the version from the commit sha
kwargs = {
"use_scm_version": {
"write_to": "dedalus/version.py",
},
"setup_requires": ["setuptools", "setuptools_scm"],
}
else:
# As a backup, we read from the pyproject.toml
import re

with open(os.path.join(os.path.dirname(__file__), "pyproject.toml")) as f:
data = f.read()
version = re.search(r'version = "(.*)"', data).group(1)
# TODO: When limited to Python 3.11, can use tomllib from the standard library

# Write the version to version.py
with open(os.path.join(os.path.dirname(__file__), "dedalus", "version.py"), "w") as f:
f.write(f'__version__ = "{version}"')

kwargs = {
"use_scm_version": False,
"version": version,
}


# Setup
print()
setup(
name="dedalus",
version=get_version("dedalus/__init__.py"),
author="Keaton J. Burns",
author_email="[email protected]",
description="A flexible framework for solving PDEs with modern spectral methods.",
long_description=long_description,
long_description_content_type="text/markdown",
url="http://dedalus-project.org",
classifiers=["Programming Language :: Python :: 3"],
python_requires=">=3.9",
install_requires=install_requires,
license="GPL3",
packages=setuptools.find_packages(),
package_data={"": ["dedalus.cfg", "examples.tar.gz"]},
ext_modules=cythonize(extensions, compiler_directives=compiler_directives),
cmdclass={"build": build},
entry_points={"xarray.backends": ["dedalus=dedalus.tools.post:DedalusXarrayBackend"]})
cmdclass={"build": build})

0 comments on commit 8265162

Please sign in to comment.