Skip to content

Commit

Permalink
Use pyproject.toml instead of setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sandorkertesz committed May 7, 2024
1 parent b03160c commit 7b08597
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ _dev

# docs
docs/examples/*.bufr

# generated version
src/pdbufr/version.py
44 changes: 43 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"}
]
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
Expand All @@ -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}"
'''
6 changes: 1 addition & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
48 changes: 1 addition & 47 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
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()
12 changes: 11 additions & 1 deletion pdbufr/__init__.py → src/pdbufr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -17,4 +27,4 @@
except ModuleNotFoundError: # pragma: no cover
pass

__version__ = "0.11.0"
__all__ += ["__version__"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/test_00_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pdbufr


def test_version() -> None:
assert pdbufr.__version__ != "999"

0 comments on commit 7b08597

Please sign in to comment.