Skip to content

Commit 2b53f77

Browse files
authored
[DEV] Dynamic package version based on git history (#500)
* DEV: Use setuptools-scm for setting dynamic package version Related to #488 * DEV: Pull __version__ attribute from package metadata Related to #488 * DOC: Pull serpentTools version data using package metadata Inspired by setuptools-scm docs * DOC: Explicit english language parameter Silences a sphinx doc warning * DOC: Update release procedure to avoid changing version strings * DOC: Add explainer on new version strings They can get a bit complex when working off releases, so some explanation is helpful
1 parent 07b503d commit 2b53f77

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

docs/conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
# |version| and |release|, also used in various other places throughout the
5353
# built documents.
5454

55-
version = "0.9.5"
55+
from importlib.metadata import version
56+
release = version("serpentTools")
57+
version = release
5658

5759
# General information about the project.
5860
project = 'serpentTools'
@@ -70,7 +72,7 @@
7072
#
7173
# This is also used if you do content translation via gettext catalogs.
7274
# Usually you set "language" from the command line for these cases.
73-
language = None
75+
language = "english"
7476

7577
# List of patterns, relative to source directory, that match files and
7678
# directories to ignore when looking for source files.

docs/develop/git.rst

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ Version Control
88
code can be found at https://github.com/CORE-GATECH-GROUP/serpent-tools.
99

1010
``serpentTools`` follows the `semantic versioning <https://semver.org/>`_
11-
system, where the version number as found in ``setup.py``,
12-
``serpentTools/__init__.py``, and ``docs/conf.py`` has the following form:
13-
``major.minor.patch``, e.g. ``0.8.0`` or ``1.1.20``. Each of the numbers
14-
should be incremented prior to new releases with the following designation:
11+
system, where the released versions have the following form
12+
``{major}.{minor}.{patch}``, where
1513

1614
1. Changes that are not backwards compatible should be denoted by
1715
incrementing the major number.
@@ -20,10 +18,23 @@ should be incremented prior to new releases with the following designation:
2018
3. Changes that are largely internal and not recognizable by end-users should
2119
be denoted by incrementing the patch number
2220

23-
.. note::
21+
Prior to a release, there may be pre-releases made signified with a "release candidate"
22+
label. These can be identified with a trailing ``.rc.{N}`` e.g., ``0.10.0.rc.5`` would be
23+
the fifth release candidate for version ``0.10.0``.
2424

25-
Until a stable 1.0.0 release, the positions are essentially shifted,
26-
e.g. the version is ``0.major.minor``
25+
For developers and users who are using the "bleeding edge" version straight from source
26+
between releases, the version string may be more complex. As this is being written,
27+
the version string is ``0.9.6.dev14+g0d7b6d6.d20230811``. The most recent release
28+
from the time of this writing was ``0.9.5``, so the first part ``0.9.6.dev`` means
29+
we are ahead of version ``0.9.5``, and does not mean the next version **must** be
30+
``0.9.6``.
31+
32+
The ``.dev14+g0d7b6b6`` indicates we are currently ``14`` commits ahead of the last
33+
tag, and the content following the ``+g`` is the SHA-1 hash of the most recent
34+
commit.
35+
36+
Finally, if we have any uncommitted changes, the version string will conclude with
37+
an indicator of the installed date. Which in this case is August 11th, 2023.
2738

2839
.. _dev-release:
2940

@@ -44,15 +55,8 @@ of a painless release.
4455
Updating the package version
4556
----------------------------
4657

47-
Before and after a release, the project version number should be updated in the
48-
following places:
49-
50-
1. ``setup.py``
51-
2. ``serpentTools/__init__.py``
52-
3. ``docs/conf.py``
53-
54-
The new version should be indicative of the changes introduced between this release
55-
and the previous release.
58+
Package version is pulled using ``setuptools-scm`` based on git tags. Therefore nothing
59+
is needed to be changed in order to change the version. Only the creation of new tags.
5660

5761
Generating distributions
5862
------------------------

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
[build-system]
2-
requires = ["setuptools>=61.0"]
2+
requires = ["setuptools>=61.0", "setuptools_scm[toml]>=6.2"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "serpentTools"
7-
version = "0.9.5"
7+
# Let setuptools-scm pick up version data
8+
dynamic = ["version"]
89
maintainers = [
910
{name="Dan Kotlyar"},
1011
{name="Drew Johnson"},
@@ -51,6 +52,10 @@ serpentTools = ["variables.yaml"]
5152
[tool.setuptools.packages.find]
5253
where = ["serpentTools"]
5354

55+
# This is okay to be empty, but we need a section here
56+
# in order to trigger it's usage when setting version data
57+
[tool.setuptools_scm]
58+
5459
[tool.pytest.ini_options]
5560
markers = [
5661
"plot: tests involving plotting capabilities",

serpentTools/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# flake8: noqa
2+
from importlib.metadata import version, PackageNotFoundError
3+
try:
4+
__version__ = version(__package__)
5+
except PackageNotFoundError:
6+
__version__ = "ERROR"
7+
8+
del PackageNotFoundError, version
9+
210
from serpentTools.detectors import *
311
from serpentTools.parsers import *
412
from serpentTools.messages import *
513
from serpentTools.data import *
614
from serpentTools.samplers import *
715
from serpentTools.seed import *
8-
from serpentTools.xs import *
9-
10-
__version__ = "0.9.5"
16+
from serpentTools.xs import *

0 commit comments

Comments
 (0)