diff --git a/dedalus/__init__.py b/dedalus/__init__.py index 558bf364..4e6e3200 100644 --- a/dedalus/__init__.py +++ b/dedalus/__init__.py @@ -5,7 +5,7 @@ # have been included in the file 'LICENSE.txt', and is also available # online at . -__version__ = "3.0.2" +from .version import __version__ # Import custom logging to setup rootlogger from .tools import logging as _logging_setup @@ -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__"] diff --git a/pyproject.toml b/pyproject.toml index 216345bc..8a5dff1b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = "keaton.burns@gmail.com" } +] +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" + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..713f5602 --- /dev/null +++ b/requirements.txt @@ -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 diff --git a/setup.py b/setup.py index 1cf1d9dd..9779ee4f 100644 --- a/setup.py +++ b/setup.py @@ -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 @@ -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 @@ -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="keaton.burns@gmail.com", - 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})