diff --git a/.gitignore b/.gitignore index d26b5515..6c2913af 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ __pycache__/ # C extensions *.so +# API documentation generated by pdoc3 +api-docs/ + # Distribution / packaging .Python build/ diff --git a/changelog.d/373.trivial.rst b/changelog.d/373.trivial.rst new file mode 100644 index 00000000..0093c3bb --- /dev/null +++ b/changelog.d/373.trivial.rst @@ -0,0 +1 @@ +Changed build backend to hatchling diff --git a/changelog.d/374.trivial.rst b/changelog.d/374.trivial.rst new file mode 100644 index 00000000..1aa19937 --- /dev/null +++ b/changelog.d/374.trivial.rst @@ -0,0 +1 @@ +Updated format of Towncrier's configuration in ``pyproject.toml`` diff --git a/docs/advanced/coerce.py b/docs/advanced/coerce.py index 7da20315..38bd6caf 100644 --- a/docs/advanced/coerce.py +++ b/docs/advanced/coerce.py @@ -1,7 +1,7 @@ import re -from semver import Version from typing import Optional, Tuple +from semver import Version BASEVERSION = re.compile( r"""[vV]? diff --git a/docs/conf.py b/docs/conf.py index ed888361..b5f040bc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,10 +17,10 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. # import codecs -from datetime import date import os import re import sys +from datetime import date SRC_DIR = os.path.abspath("../src/") sys.path.insert(0, SRC_DIR) diff --git a/pyproject.toml b/pyproject.toml index ba4be51b..4c9d4b08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,34 +1,184 @@ -# -# -# See also https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html -# -# General idea taken from -# https://godatadriven.com/blog/a-practical-guide-to-setuptools-and-pyproject-toml/ - [build-system] requires = [ - # sync with setup.py until we discard non-pep-517/518 - "setuptools", - "setuptools-scm", - "wheel", - "build", + "hatchling>=1.8.0", +] +build-backend = "hatchling.build" + +[project] +name = "semver" +description = "Python helper for Semantic Versioning (https://semver.org)" +readme = "README.rst" +requires-python = ">=3.7" +authors = [ + { name = "Kostiantyn Rybnikov", email = "k-bx@k-bx.com" }, +] +maintainers = [ + { name = "Sebastien Celles", email = "s.celles@gmail.com" }, + { name = "Tom Schraitle" }, +] +keywords = [ + "python", + "version", + "semver", + "versioning", + "version", + "semantic-versioning", + "release", + "semver-format", + "semver-tag", + "semver-release", + "semver-cli", +] +classifiers = [ + # I think python-semver is more "Console" than "Web Environment" + #"Environment :: Web Environment", + "Environment :: Console", + "Development Status :: 5 - Production/Stable", + "Topic :: Software Development", + "Intended Audience :: Developers", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "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", + "Topic :: Software Development :: Libraries :: Python Modules", ] -build-backend = "setuptools.build_meta" +dependencies = [] +dynamic = [ + "version", +] + +[project.urls] +Homepage = "https://github.com/python-semver/python-semver" +Changelog = "https://python-semver.readthedocs.io/en/latest/changelog.html" +Documentation = "https://python-semver.rtfd.io" +Releases = "https://github.com/python-semver/python-semver/releases" +Issues = "https://github.com/python-semver/python-semver/issues" + +[project.license] +file = "LICENSE.txt" + +[project.scripts] +pysemver = "semver.cli:main" + +[tool.hatch.version] +path = "src/semver/__about__.py" +[tool.hatch.build] +include = [ + "src/semver/*.py", + "src/semver/py.typed", +] + +[tool.hatch.envs.default] +dependencies = [ + "towncrier", + "wheel", +] + +[tool.hatch.envs.style] +dependencies = [ + "black", + "isort", + "flake8", + "pycodestyle", +] + +[tool.hatch.envs.style.scripts] +fmt = [ + "black .", + "isort .", +] +lint = [ + "flake8 --exit-zero", + "pycodestyle", +] + +[tool.hatch.envs.docs] +dependencies = [ + "pdoc3" +] +[tool.hatch.envs.docs.scripts] +build = "pdoc --html --output-dir api-docs src/semver --force" +serve = "pdoc --http : python-semver" + +[tool.hatch.envs.test] +dependencies = [ + "pytest-cov", + "tox", +] + +[tool.hatch.envs.test.scripts] +cov = "pytest -vx" +no-cov = "cov --no-cov" +tox_test = "tox" + +[[tool.hatch.envs.test.matrix]] +python = ["310", "311"] + +[tool.coverage.run] +branch = true +parallel = true +omit = [ + # add files to exclude them from the coverage report, e.g. + # "src/semver/__about__.py" +] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] + +[tool.mypy] +# the mypy settings go here +# To have the `py.typed` file installed with the package we had to include it +# in the build metadata (see [tool.hatch.build]) + +[tool.pytest.ini_options] +norecursedirs = ".git build .env/ env/ .pyenv/ .tmp/ .eggs/ venv/" +testpaths = "tests docs" +filterwarnings = [ + "ignore::DeprecationWarning", + 'ignore:Function semver.*:DeprecationWarning', +] +addopts = """ + --no-cov-on-fail + --cov=semver + --cov-report=term-missing + --doctest-glob='*.rst' + --doctest-modules + --doctest-report ndiff +""" + +# flake8 does not support configuration in pyproject.toml +# see https://github.com/PyCQA/flake8/issues/234 +# (there are alternatives, e.g. https://github.com/john-hen/Flake8-pyproject) +# we stick to the original flake8 with configuration +# in the `[flake8]` section of setup.cfg + +# pycodestyle does not support configuration in pyproject.toml +# We stick to the original pycodestyle configuration +# in the `[pycodestyle]` section of setup.cfg [tool.black] line-length = 88 -target-version = ['py36', 'py37', 'py38', 'py39', 'py310'] +target-version = ['py37', 'py38', 'py39', 'py310'] # diff = true -extend-exclude = ''' +extend-exclude = """ # A regex preceded with ^/ will apply only to files and directories # in the root of the project. ^/*.py -''' -include = ''' +""" +include = """ ^/setup.py -''' +""" [tool.towncrier] package = "semver" @@ -40,42 +190,29 @@ template = "changelog.d/_template.rst" # issue_format = "`#{issue} `_" # issue_format = ":gh:`{issue}`" - # [[tool.towncrier.type]] - # directory = "breaking" - # name = "Breaking Changes" - # showcontent = true - - [[tool.towncrier.type]] - directory = "deprecation" - name = "Deprecations" - showcontent = true - - [[tool.towncrier.type]] - directory = "feature" - name = "Features" - showcontent = true - - # [[tool.towncrier.type]] - # directory = "improvement" - # name = "Improvements" - # showcontent = true - - [[tool.towncrier.type]] - directory = "bugfix" - name = "Bug Fixes" - showcontent = true - - [[tool.towncrier.type]] - directory = "doc" - name = "Improved Documentation" - showcontent = true - - [[tool.towncrier.type]] - directory = "trivial" - name = "Trivial/Internal Changes" - showcontent = true - - [[tool.towncrier.type]] - directory = "removal" - name = "Removals" - showcontent = true +# [tool.towncrier.fragment.breaking] +# name = "Breaking Changes" +# showcontent = true + +[tool.towncrier.fragment.deprecation] +name = "Deprecations" + +[tool.towncrier.fragment.feature] +directory = "feature" +name = "Features" + +# [tool.towncrier.fragment.improvement] +# name = "Improvements" +# showcontent = true + +[tool.towncrier.fragment.bugfix] +name = "Bug Fixes" + +[tool.towncrier.fragment.doc] +name = "Improved Documentation" + +[tool.towncrier.fragment.trivial] +name = "Trivial/Internal Changes" + +[tool.towncrier.fragment.removal] +name = "Removals" diff --git a/setup.cfg b/setup.cfg index 4087e787..25e61ce6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,71 +1,3 @@ -# -# Metadata for setup.py -# -# See https://setuptools.rtfd.io/en/latest/userguide/declarative_config.html - -[metadata] -name = semver -version = attr: semver.__about__.__version__ -description = Python helper for Semantic Versioning (https://semver.org) -long_description = file: README.rst -long_description_content_type = text/x-rst -author = Kostiantyn Rybnikov -author_email = k-bx@k-bx.com -maintainer = Sebastien Celles, Tom Schraitle -maintainer_email = s.celles@gmail.com -url = https://github.com/python-semver/python-semver -project_urls = - Changelog = https://python-semver.readthedocs.io/en/latest/changelog.html - Documentation = https://python-semver.rtfd.io - Releases = https://github.com/python-semver/python-semver/releases - Bug Tracker = https://github.com/python-semver/python-semver/issues -classifiers = - Environment :: Web Environment - Intended Audience :: Developers - License :: OSI Approved :: BSD License - Operating System :: OS Independent - Programming Language :: Python - 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 - Topic :: Software Development :: Libraries :: Python Modules -license = BSD - -[options] -package_dir = - =src -packages = find: -python_requires = >=3.6.* -include_package_data = True - -[options.entry_points] -console_scripts = - pysemver = semver.cli:main - -[options.packages.find] -where = src - -[options.package_data] -semver = py.typed - -[tool:pytest] -norecursedirs = .git build .env/ env/ .pyenv/ .tmp/ .eggs/ venv/ -testpaths = tests docs -filterwarnings = - ignore:Function 'semver.*:DeprecationWarning - # ' <- This apostroph is just to fix syntax highlighting -addopts = - --no-cov-on-fail - --cov=semver - --cov-report=term-missing - --doctest-glob='*.rst' - --doctest-modules - --doctest-report ndiff - [flake8] max-line-length = 88 ignore = F821,W503 diff --git a/src/semver/__init__.py b/src/semver/__init__.py index c6726f2e..98e0ca24 100644 --- a/src/semver/__init__.py +++ b/src/semver/__init__.py @@ -4,36 +4,12 @@ A Python module for semantic versioning. Simplifies comparing versions. """ -from ._deprecated import ( - bump_build, - bump_major, - bump_minor, - bump_patch, - bump_prerelease, - compare, - finalize_version, - format_version, - match, - max_ver, - min_ver, - parse, - parse_version_info, - replace, - cmd_bump, - cmd_compare, - cmd_nextver, - cmd_check, - createparser, - process, - main, -) +from .__about__ import (SEMVER_SPEC_VERSION, __author__, __author_email__, + __description__, __maintainer__, __maintainer_email__, + __version__) +from ._deprecated import (bump_build, bump_major, bump_minor, bump_patch, + bump_prerelease, cmd_bump, cmd_check, cmd_compare, + cmd_nextver, compare, createparser, finalize_version, + format_version, main, match, max_ver, min_ver, parse, + parse_version_info, process, replace) from .version import Version, VersionInfo -from .__about__ import ( - __version__, - __author__, - __maintainer__, - __author_email__, - __description__, - __maintainer_email__, - SEMVER_SPEC_VERSION, -) diff --git a/src/semver/_deprecated.py b/src/semver/_deprecated.py index 5f51c8f3..5407781a 100644 --- a/src/semver/_deprecated.py +++ b/src/semver/_deprecated.py @@ -7,11 +7,11 @@ import warnings from functools import partial, wraps from types import FrameType -from typing import Type, Callable, Optional, cast +from typing import Callable, Optional, Type, cast from . import cli -from .version import Version from ._types import Decorator, F, String +from .version import Version def deprecated( diff --git a/src/semver/_types.py b/src/semver/_types.py index 7afb6ff0..0678042d 100644 --- a/src/semver/_types.py +++ b/src/semver/_types.py @@ -1,7 +1,7 @@ """Typing for semver.""" from functools import partial -from typing import Union, Optional, Tuple, Dict, Iterable, Callable, TypeVar +from typing import Callable, Dict, Iterable, Optional, Tuple, TypeVar, Union VersionPart = Union[int, Optional[str]] VersionTuple = Tuple[int, int, int, Optional[str], Optional[str]] diff --git a/src/semver/cli.py b/src/semver/cli.py index 3c573d63..7de2ffb4 100644 --- a/src/semver/cli.py +++ b/src/semver/cli.py @@ -12,10 +12,10 @@ import argparse import sys -from typing import cast, List, Optional +from typing import List, Optional, cast -from .version import Version from .__about__ import __version__ +from .version import Version def cmd_bump(args: argparse.Namespace) -> str: diff --git a/src/semver/version.py b/src/semver/version.py index 04e7faae..53ef275a 100644 --- a/src/semver/version.py +++ b/src/semver/version.py @@ -3,26 +3,11 @@ import collections import re from functools import wraps -from typing import ( - Any, - Dict, - Iterable, - Optional, - SupportsInt, - Tuple, - Union, - cast, - Callable, - Collection, -) - -from ._types import ( - VersionTuple, - VersionDict, - VersionIterator, - String, - VersionPart, -) +from typing import (Any, Callable, Collection, Dict, Iterable, Optional, + SupportsInt, Tuple, Union, cast) + +from ._types import (String, VersionDict, VersionIterator, VersionPart, + VersionTuple) # These types are required here because of circular imports Comparable = Union["Version", Dict[str, VersionPart], Collection[VersionPart], str] diff --git a/tests/coerce.py b/tests/coerce.py index e79106a2..75eaff06 120000 --- a/tests/coerce.py +++ b/tests/coerce.py @@ -1 +1 @@ -../docs/advanced/coerce.py \ No newline at end of file +../docs/advanced/coerce.py diff --git a/tests/conftest.py b/tests/conftest.py index beecffc9..548afc07 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,15 +1,14 @@ import sys +import packaging.version import pytest +from coerce import coerce # noqa:E402 +from semverwithvprefix import SemVerWithVPrefix # noqa:E402 import semver # sys.path.insert(0, "docs/usage") -from coerce import coerce # noqa:E402 -from semverwithvprefix import SemVerWithVPrefix # noqa:E402 -import packaging.version - @pytest.fixture(autouse=True) def add_semver(doctest_namespace): diff --git a/tests/test_bump.py b/tests/test_bump.py index c28e1905..6e652ca7 100644 --- a/tests/test_bump.py +++ b/tests/test_bump.py @@ -1,13 +1,7 @@ import pytest -from semver import ( - bump_build, - bump_major, - bump_minor, - bump_patch, - bump_prerelease, - parse_version_info, -) +from semver import (bump_build, bump_major, bump_minor, bump_patch, + bump_prerelease, parse_version_info) def test_should_bump_major(): diff --git a/tests/test_deprecated_functions.py b/tests/test_deprecated_functions.py index 0b5123cc..59863b01 100644 --- a/tests/test_deprecated_functions.py +++ b/tests/test_deprecated_functions.py @@ -2,29 +2,11 @@ import pytest -from semver import ( - parse, - parse_version_info, - compare, - match, - max_ver, - min_ver, - format_version, - bump_major, - bump_minor, - bump_patch, - bump_prerelease, - bump_build, - finalize_version, - replace, - cmd_bump, - cmd_compare, - cmd_check, - cmd_nextver, - createparser, - process, - main, -) +from semver import (bump_build, bump_major, bump_minor, bump_patch, + bump_prerelease, cmd_bump, cmd_check, cmd_compare, + cmd_nextver, compare, createparser, finalize_version, + format_version, main, match, max_ver, min_ver, parse, + parse_version_info, process, replace) from semver._deprecated import deprecated diff --git a/tests/test_pysemver-cli.py b/tests/test_pysemver-cli.py index e783a0b4..2f365f59 100644 --- a/tests/test_pysemver-cli.py +++ b/tests/test_pysemver-cli.py @@ -4,15 +4,8 @@ import pytest -from semver import ( - cmd_bump, - cmd_check, - cmd_compare, - cmd_nextver, - createparser, - main, - __main__, -) +from semver import (__main__, cmd_bump, cmd_check, cmd_compare, cmd_nextver, + createparser, main) @contextmanager diff --git a/tests/test_typeerror-274.py b/tests/test_typeerror-274.py index 326304b8..9a84ff5a 100644 --- a/tests/test_typeerror-274.py +++ b/tests/test_typeerror-274.py @@ -1,4 +1,5 @@ import pytest + import semver