Skip to content

Commit 78e4f81

Browse files
authored
use setuptools_scm (#1810)
1 parent acc90c6 commit 78e4f81

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ jobs:
161161
runs-on: ubuntu-latest
162162
steps:
163163
- uses: actions/checkout@v4
164+
with:
165+
fetch-depth: 0 # fetch tags for setuptools-scm
164166
- name: Set up Python
165167
uses: actions/setup-python@v5
166168
with:

can/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
messages on a can bus.
66
"""
77

8+
import contextlib
89
import logging
10+
from importlib.metadata import PackageNotFoundError, version
911
from typing import Any, Dict
1012

11-
__version__ = "4.4.2"
1213
__all__ = [
1314
"ASCReader",
1415
"ASCWriter",
@@ -124,6 +125,9 @@
124125
from .thread_safe_bus import ThreadSafeBus
125126
from .util import set_logging_level
126127

128+
with contextlib.suppress(PackageNotFoundError):
129+
__version__ = version("python-can")
130+
127131
log = logging.getLogger("can")
128132

129133
rc: Dict[str, Any] = {}

doc/conf.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
import ctypes
1010
import os
1111
import sys
12+
from importlib.metadata import version as get_version
1213
from unittest.mock import MagicMock
1314

1415
# If extensions (or modules to document with autodoc) are in another directory,
1516
# add these directories to sys.path here. If the directory is relative to the
1617
# documentation root, use os.path.abspath to make it absolute, like shown here.
1718
sys.path.insert(0, os.path.abspath(".."))
1819

19-
import can # pylint: disable=wrong-import-position
2020
from can import ctypesutil # pylint: disable=wrong-import-position
2121

2222
# -- General configuration -----------------------------------------------------
@@ -27,9 +27,10 @@
2727
# |version| and |release|, also used in various other places throughout the
2828
# built documents.
2929
#
30+
# The full version, including alpha/beta/rc tags.
31+
release: str = get_version("python-can")
3032
# The short X.Y version.
31-
version = can.__version__.split("-", maxsplit=1)[0]
32-
release = can.__version__
33+
version = ".".join(release.split(".")[:2])
3334

3435
# General information about the project.
3536
project = "python-can"

doc/development.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Manual release steps (deprecated)
129129
---------------------------------
130130

131131
- Create a temporary virtual environment.
132+
- Create a new tag in the repository. Use `semantic versioning <http://semver.org>`__.
132133
- Build with ``pipx run build``
133-
- Create and upload the distribution: ``python setup.py sdist bdist_wheel``.
134134
- Sign the packages with gpg ``gpg --detach-sign -a dist/python_can-X.Y.Z-py3-none-any.whl``.
135135
- Upload with twine ``twine upload dist/python-can-X.Y.Z*``.

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools >= 67.7"]
2+
requires = ["setuptools >= 67.7", "setuptools_scm>=8"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
@@ -84,8 +84,6 @@ mf4 = ["asammdf>=6.0.0"]
8484

8585
[tool.setuptools.dynamic]
8686
readme = { file = "README.rst" }
87-
version = { attr = "can.__version__" }
88-
8987
[tool.setuptools.package-data]
9088
"*" = ["README.rst", "CONTRIBUTORS.txt", "LICENSE.txt", "CHANGELOG.md"]
9189
doc = ["*.*"]
@@ -95,6 +93,9 @@ can = ["py.typed"]
9593
[tool.setuptools.packages.find]
9694
include = ["can*"]
9795

96+
[tool.setuptools_scm]
97+
# can be empty if no extra settings are needed, presence enables setuptools_scm
98+
9899
[tool.mypy]
99100
warn_return_any = true
100101
warn_unused_configs = true

0 commit comments

Comments
 (0)