From 7b08597aac5d789c5d526474e44d5c96d53404de Mon Sep 17 00:00:00 2001 From: Sandor Kertesz Date: Tue, 7 May 2024 12:00:14 +0100 Subject: [PATCH] Use pyproject.toml instead of setup.py --- .gitignore | 3 ++ pyproject.toml | 44 ++++++++++++++++- setup.cfg | 6 +-- setup.py | 48 +------------------ {pdbufr => src/pdbufr}/__init__.py | 12 ++++- {pdbufr => src/pdbufr}/__main__.py | 0 {pdbufr => src/pdbufr}/bufr_filters.py | 0 {pdbufr => src/pdbufr}/bufr_read.py | 0 {pdbufr => src/pdbufr}/bufr_structure.py | 0 .../pdbufr}/high_level_bufr/__init__.py | 0 .../pdbufr}/high_level_bufr/bufr.py | 0 .../pdbufr}/high_level_bufr/codesfile.py | 0 .../pdbufr}/high_level_bufr/codesmessage.py | 0 tests/test_00_version.py | 5 ++ 14 files changed, 64 insertions(+), 54 deletions(-) rename {pdbufr => src/pdbufr}/__init__.py (64%) rename {pdbufr => src/pdbufr}/__main__.py (100%) rename {pdbufr => src/pdbufr}/bufr_filters.py (100%) rename {pdbufr => src/pdbufr}/bufr_read.py (100%) rename {pdbufr => src/pdbufr}/bufr_structure.py (100%) rename {pdbufr => src/pdbufr}/high_level_bufr/__init__.py (100%) rename {pdbufr => src/pdbufr}/high_level_bufr/bufr.py (100%) rename {pdbufr => src/pdbufr}/high_level_bufr/codesfile.py (100%) rename {pdbufr => src/pdbufr}/high_level_bufr/codesmessage.py (100%) create mode 100644 tests/test_00_version.py diff --git a/.gitignore b/.gitignore index a0cfe38..e50e501 100644 --- a/.gitignore +++ b/.gitignore @@ -93,3 +93,6 @@ _dev # docs docs/examples/*.bufr + +# generated version +src/pdbufr/version.py diff --git a/pyproject.toml b/pyproject.toml index b184c58..df2d356 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,40 @@ [build-system] -requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"] +build-backend = "setuptools.build_meta" +requires = ["setuptools>=61", "setuptools_scm[toml]>=8"] + +[project] +authors = [ + {name = "European Centre for Medium-Range Weather Forecasts (ECMWF)", email = "software.support@ecmwf.int"} +] +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: Implementation :: CPython", + "Operating System :: OS Independent" +] +dependencies = ["attrs", "eccodes", "pandas"] +description = "Pandas reader for the BUFR format using ecCodes." +dynamic = ["version"] +keywords = ["eccodes", "bufr", "pandas"] +license = {text = "Apache License Version 2.0"} +name = "pdbufr" +readme = "README.md" +requires-python = ">= 3.6" + +[project.optional-dependencies] +tests = ["flake8", "pytest", "pytest-cov", "requests"] + +[project.urls] +Documentation = "https://pdbufr.readthedocs.io/en/latest/" +Homepage = "https://github.com/ecmwf/pdbufr" [tool.coverage.run] branch = true @@ -10,3 +45,10 @@ profile = "black" [tool.pydocstyle] add_ignore = ["D1", "D200", "D205", "D400", "D401", "D403"] convention = "numpy" + +[tool.setuptools_scm] +write_to = "src/pdbufr/version.py" +write_to_template = ''' +# Do not change! Do not track in version control! +__version__ = "{version}" +''' diff --git a/setup.cfg b/setup.cfg index 4b61401..fe42d05 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,3 @@ -[zest.releaser] -python-file-with-version = pdbufr/__init__.py - - [flake8] -max-line-length = 110 extend-ignore = E203, W503 +max-line-length = 110 diff --git a/setup.py b/setup.py index 7f96c44..f147c9a 100644 --- a/setup.py +++ b/setup.py @@ -8,52 +8,6 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. -import os -import re - import setuptools # type: ignore - -def read(path: str) -> str: - file_path = os.path.join(os.path.dirname(__file__), *path.split("/")) - return open(file_path).read() - - -# single-sourcing the package version using method 1 of: -# https://packaging.python.org/guides/single-sourcing-package-version/ -def parse_version_from(path: str) -> str: - version_file = read(path) - version_match = re.search('^__version__ = "(.*)"', version_file, re.M) - if version_match is None or len(version_match.groups()) > 1: - raise ValueError("couldn't parse version") - return version_match.group(1) - - -setuptools.setup( - name="pdbufr", - version=parse_version_from("pdbufr/__init__.py"), - description="Pandas reader for the BUFR format using ecCodes.", - long_description=read("README.rst"), - author="European Centre for Medium-Range Weather Forecasts (ECMWF)", - author_email="software.support@ecmwf.int", - license="Apache License Version 2.0", - url="https://github.com/ecmwf/pdbufr", - packages=setuptools.find_packages(), - include_package_data=True, - install_requires=["attrs", "eccodes", "pandas"], - extras_require={"tests": ["flake8", "pytest", "pytest-cov", "requests"]}, - zip_safe=True, - keywords="eccodes bufr pandas", - classifiers=[ - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: Implementation :: CPython", - "Operating System :: OS Independent", - ], -) +setuptools.setup() diff --git a/pdbufr/__init__.py b/src/pdbufr/__init__.py similarity index 64% rename from pdbufr/__init__.py rename to src/pdbufr/__init__.py index 527b898..fd5d371 100644 --- a/pdbufr/__init__.py +++ b/src/pdbufr/__init__.py @@ -6,6 +6,16 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. + +try: + # NOTE: the `version.py` file must not be present in the git repository + # as it is generated by setuptools at install time + from .version import __version__ +except ImportError: # pragma: no cover + # Local copy or not installed with setuptools + __version__ = "999" + + from .bufr_structure import stream_bufr __all__ = ["stream_bufr"] @@ -17,4 +27,4 @@ except ModuleNotFoundError: # pragma: no cover pass -__version__ = "0.11.0" +__all__ += ["__version__"] diff --git a/pdbufr/__main__.py b/src/pdbufr/__main__.py similarity index 100% rename from pdbufr/__main__.py rename to src/pdbufr/__main__.py diff --git a/pdbufr/bufr_filters.py b/src/pdbufr/bufr_filters.py similarity index 100% rename from pdbufr/bufr_filters.py rename to src/pdbufr/bufr_filters.py diff --git a/pdbufr/bufr_read.py b/src/pdbufr/bufr_read.py similarity index 100% rename from pdbufr/bufr_read.py rename to src/pdbufr/bufr_read.py diff --git a/pdbufr/bufr_structure.py b/src/pdbufr/bufr_structure.py similarity index 100% rename from pdbufr/bufr_structure.py rename to src/pdbufr/bufr_structure.py diff --git a/pdbufr/high_level_bufr/__init__.py b/src/pdbufr/high_level_bufr/__init__.py similarity index 100% rename from pdbufr/high_level_bufr/__init__.py rename to src/pdbufr/high_level_bufr/__init__.py diff --git a/pdbufr/high_level_bufr/bufr.py b/src/pdbufr/high_level_bufr/bufr.py similarity index 100% rename from pdbufr/high_level_bufr/bufr.py rename to src/pdbufr/high_level_bufr/bufr.py diff --git a/pdbufr/high_level_bufr/codesfile.py b/src/pdbufr/high_level_bufr/codesfile.py similarity index 100% rename from pdbufr/high_level_bufr/codesfile.py rename to src/pdbufr/high_level_bufr/codesfile.py diff --git a/pdbufr/high_level_bufr/codesmessage.py b/src/pdbufr/high_level_bufr/codesmessage.py similarity index 100% rename from pdbufr/high_level_bufr/codesmessage.py rename to src/pdbufr/high_level_bufr/codesmessage.py diff --git a/tests/test_00_version.py b/tests/test_00_version.py new file mode 100644 index 0000000..ae7c7bc --- /dev/null +++ b/tests/test_00_version.py @@ -0,0 +1,5 @@ +import pdbufr + + +def test_version() -> None: + assert pdbufr.__version__ != "999"