Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize python build configuration #290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
MilesCranmer marked this conversation as resolved.
Show resolved Hide resolved
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,
}

Comment on lines +188 to +214
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(The same one I use for PySR, so I can confirm this works!)


# 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})