From b3b770d5072744c32067b84a2ca2b22e52c6b7e9 Mon Sep 17 00:00:00 2001 From: Patrick Kunzmann Date: Thu, 13 Jun 2024 11:39:57 +0200 Subject: [PATCH] Move build backend to 'hatch' --- .gitignore | 3 ++ MANIFEST.in | 3 -- pyproject.toml | 41 +++++++++++++----- setup.py | 93 ----------------------------------------- src/biotite/__init__.py | 2 +- tests/test_version.py | 9 ++++ 6 files changed, 43 insertions(+), 108 deletions(-) delete mode 100644 MANIFEST.in delete mode 100644 setup.py create mode 100644 tests/test_version.py diff --git a/.gitignore b/.gitignore index c0281a26f..b27dbe7e1 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,9 @@ htmlcov .eggs .cache +# Ignore version file created by hatch-vcs +/src/biotite/version.py + # Ignore autogenerated API reference /doc/apidoc diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 118291c1c..000000000 --- a/MANIFEST.in +++ /dev/null @@ -1,3 +0,0 @@ -include README.rst -include LICENSE.rst -include pyproject.toml \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 912abe6fe..9f348b932 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,6 @@ description = "A comprehensive library for computational molecular biology" readme = "README.rst" authors = [{name = "The Biotite contributors"}] license = {"file" = "LICENSE.rst"} - classifiers = [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", @@ -19,7 +18,6 @@ classifiers = [ "Programming Language :: Python :: Implementation :: CPython", "Topic :: Scientific/Engineering :: Bio-Informatics", ] - # Based on https://github.com/scipy/oldest-supported-numpy/blob/main/setup.cfg # When updating our minimum supported python version follow minimums set in this setup.cfg # as of 2022-01 for 3.7 "numpy >= 1.14.5", for 3.8 "numpy >= 1.17.3", for 3.9 "numpy >= 1.19.3" @@ -32,22 +30,43 @@ dependencies = [ ] dynamic = ["version"] +[project.optional-dependencies] +test = [ + "pytest", +] + [project.urls] homepage = "https://www.biotite-python.org" repository = "https://github.com/biotite-dev/biotite" documentation = "https://www.biotite-python.org" +[tool.hatch.build.targets.sdist] +exclude = [ + "tests", + "doc", + "environment.yml", + "setup_ccd.py" +] + +[tool.hatch.version] +source = "vcs" + +[tool.hatch.build.hooks.vcs] +version-file = "src/biotite/version.py" + +[tool.hatch.build.targets.wheel.hooks.cython] +dependencies = ["hatch-cython"] + +[tool.hatch.build.targets.wheel.hooks.cython.options] +include_numpy = true +compile_py = false [build-system] requires = [ - "setuptools >= 0.30", - "wheel >= 0.30", + "hatchling", + "hatch-vcs == 0.4", + "hatch-cython == 0.5", "oldest-supported-numpy", - "cython >= 3.0" -] -build-backend = "setuptools.build_meta" - -[project.optional-dependencies] -test = [ - "pytest", + "cython >= 3.0", ] +build-backend = "hatchling.build" diff --git a/setup.py b/setup.py deleted file mode 100644 index 4d3ec7944..000000000 --- a/setup.py +++ /dev/null @@ -1,93 +0,0 @@ -# This source code is part of the Biotite package and is distributed -# under the 3-Clause BSD License. Please see 'LICENSE.rst' for further -# information. - -import re -from os.path import join, abspath, dirname, normpath -import fnmatch -import os -from setuptools import setup, find_packages, Extension -import numpy -from Cython.Build import cythonize - -original_wd = os.getcwd() -# Change directory to setup directory to ensure correct file identification -os.chdir(dirname(abspath(__file__))) - -# Parse the top level package for the version -# Do not use an import to prevent side effects -# e.g. required runtime dependencies -version = None -with open(join("src", "biotite", "__init__.py")) as init_file: - for line in init_file.read().splitlines(): - if line.lstrip().startswith("__version__"): - version_match = re.search('".*"', line) - if version_match: - # Remove quotes - version = version_match.group(0)[1 : -1] - else: - raise ValueError("No version is specified in '__init__.py'") -if version is None: - raise ValueError("Unable to identify 'version' in __init__.py") - -# Compile Cython into C -try: - cythonize( - "src/**/*.pyx", - include_path=[numpy.get_include()], - language_level=3 - ) -except ValueError: - # This is a source distribution and the directory already contains - # only C/C++ files - pass - - -def get_extensions(): - ext_sources = [] - for dirpath, _, filenames in os.walk(normpath("src/biotite")): - for filename in ( - fnmatch.filter(filenames, "*.c") + - fnmatch.filter(filenames, "*.cpp") - ): - ext_sources.append(os.path.join(dirpath, filename)) - ext_names = [source - .replace("src"+normpath("/"), "") - .replace(".cpp", "") - .replace(".c", "") - .replace(normpath("/"), ".") - for source in ext_sources] - ext_modules = [Extension(ext_names[i], [ext_sources[i]], - include_dirs=[numpy.get_include()]) - for i in range(len(ext_sources))] - return ext_modules - - -setup( - version = version, - zip_safe = False, - packages = find_packages("src"), - package_dir = {"" : "src"}, - - ext_modules = get_extensions(), - - # Including additional data - package_data = { - "biotite.sequence.align" : [ - # Substitution matrices - "matrix_data/*.mat", - # Prime hash table sizes - "primes.txt" - ], - # Color schmemes - "biotite.sequence.graphics" : ["color_schemes/*.json"], - # Codon tables - "biotite.sequence" : ["codon_tables.txt"], - # Structure data (masses, bonds, etc.) - "biotite.structure.info" : ["atom_masses.json", "ccd/*"] - }, -) - - -# Return to original directory -os.chdir(original_wd) diff --git a/src/biotite/__init__.py b/src/biotite/__init__.py index e95f230fd..b2b83467d 100644 --- a/src/biotite/__init__.py +++ b/src/biotite/__init__.py @@ -9,7 +9,6 @@ modules. """ -__version__ = "0.41.0" __name__ = "biotite" __author__ = "Patrick Kunzmann" @@ -17,3 +16,4 @@ from .temp import * from .copyable import * from .visualize import * +from .version import __version__, __version_tuple__ diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 000000000..5f11daa2a --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,9 @@ +from importlib.metadata import version +import biotite + + +def test_version(): + """ + Check if version imported from version.py is correct. + """ + assert biotite.__version__ == version("biotite") \ No newline at end of file