diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4afb4c1ca..de5601ebf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -161,6 +161,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 # fetch tags for setuptools-scm - name: Set up Python uses: actions/setup-python@v5 with: diff --git a/can/__init__.py b/can/__init__.py index 53aec7160..324803b9e 100644 --- a/can/__init__.py +++ b/can/__init__.py @@ -5,10 +5,11 @@ messages on a can bus. """ +import contextlib import logging +from importlib.metadata import PackageNotFoundError, version from typing import Any, Dict -__version__ = "4.4.2" __all__ = [ "ASCReader", "ASCWriter", @@ -124,6 +125,9 @@ from .thread_safe_bus import ThreadSafeBus from .util import set_logging_level +with contextlib.suppress(PackageNotFoundError): + __version__ = version("python-can") + log = logging.getLogger("can") rc: Dict[str, Any] = {} diff --git a/doc/conf.py b/doc/conf.py index 54318883f..1322a2f83 100755 --- a/doc/conf.py +++ b/doc/conf.py @@ -9,6 +9,7 @@ import ctypes import os import sys +from importlib.metadata import version as get_version from unittest.mock import MagicMock # If extensions (or modules to document with autodoc) are in another directory, @@ -16,7 +17,6 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath("..")) -import can # pylint: disable=wrong-import-position from can import ctypesutil # pylint: disable=wrong-import-position # -- General configuration ----------------------------------------------------- @@ -27,9 +27,10 @@ # |version| and |release|, also used in various other places throughout the # built documents. # +# The full version, including alpha/beta/rc tags. +release: str = get_version("python-can") # The short X.Y version. -version = can.__version__.split("-", maxsplit=1)[0] -release = can.__version__ +version = ".".join(release.split(".")[:2]) # General information about the project. project = "python-can" diff --git a/doc/development.rst b/doc/development.rst index f635ffc06..c83f0f213 100644 --- a/doc/development.rst +++ b/doc/development.rst @@ -129,7 +129,7 @@ Manual release steps (deprecated) --------------------------------- - Create a temporary virtual environment. +- Create a new tag in the repository. Use `semantic versioning `__. - Build with ``pipx run build`` -- Create and upload the distribution: ``python setup.py sdist bdist_wheel``. - Sign the packages with gpg ``gpg --detach-sign -a dist/python_can-X.Y.Z-py3-none-any.whl``. - Upload with twine ``twine upload dist/python-can-X.Y.Z*``. diff --git a/pyproject.toml b/pyproject.toml index 08b501c60..99a54a5df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools >= 67.7"] +requires = ["setuptools >= 67.7", "setuptools_scm>=8"] build-backend = "setuptools.build_meta" [project] @@ -84,8 +84,6 @@ mf4 = ["asammdf>=6.0.0"] [tool.setuptools.dynamic] readme = { file = "README.rst" } -version = { attr = "can.__version__" } - [tool.setuptools.package-data] "*" = ["README.rst", "CONTRIBUTORS.txt", "LICENSE.txt", "CHANGELOG.md"] doc = ["*.*"] @@ -95,6 +93,9 @@ can = ["py.typed"] [tool.setuptools.packages.find] include = ["can*"] +[tool.setuptools_scm] +# can be empty if no extra settings are needed, presence enables setuptools_scm + [tool.mypy] warn_return_any = true warn_unused_configs = true