Skip to content

Commit 1766055

Browse files
committed
feat: determine version from vcs
The `hatch-vcs` is an extension to hatch's build system which automatically determines the current version of the project based on the VCS (i.e., git in this instance). Specifically, it looks for the latest `vX.Y.Z` tag and: - If the current `HEAD` is identical to the tag, sets a nice 'clean' version; - If the current `HEAD` is infront of the tag, uses a dev build versioning of the form `vX.Y.Z.devN` where `N` is the number of commits between `HEAD` and the tag. Signed-off-by: JP-Ellis <josh@jpellis.me>
1 parent 54e75ab commit 1766055

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
pact/bin
55
pact/data
66

7+
# Version is determined from the VCS
8+
pact/__version__.py
9+
710
################################################################################
811
## Standard Templates
912
################################################################################

pact/__init__.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,27 @@
99
from .provider import Provider
1010
from .verifier import Verifier
1111

12-
from .__version__ import __version__ # noqa: F401
12+
from .__version__ import __version__, __version_tuple__
1313

14-
__all__ = ('Broker', 'Consumer', 'EachLike', 'Like',
15-
'MessageConsumer', 'MessagePact', 'MessageProvider',
16-
'Pact', 'Provider', 'SomethingLike', 'Term', 'Format', 'Verifier')
14+
__url__ = "https://github.com/pactflow/accord"
15+
__license__ = "MIT"
16+
17+
__all__ = [
18+
'__version__',
19+
'__version_tuple__',
20+
'__url__',
21+
'__license__',
22+
'Broker',
23+
'Consumer',
24+
'EachLike',
25+
'Like',
26+
'MessageConsumer',
27+
'MessagePact',
28+
'MessageProvider',
29+
'Pact',
30+
'Provider',
31+
'SomethingLike',
32+
'Term',
33+
'Format',
34+
'Verifier',
35+
]

pact/__version__.py

-3
This file was deleted.

pyproject.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,20 @@ dev = ["pact-python[types]", "pact-python[test]", "ruff==0.2.2"]
8484

8585
[build-system]
8686
requires = [
87+
"cffi",
88+
"hatch-vcs",
8789
"hatchling",
8890
"packaging",
8991
"requests",
90-
"cffi",
9192
"setuptools ; python_version >= '3.12'",
9293
]
9394
build-backend = "hatchling.build"
9495

9596
[tool.hatch.version]
96-
path = "pact/__version__.py"
97+
source = "vcs"
98+
99+
[tool.hatch.build.hooks.vcs]
100+
version-file = "pact/__version__.py"
97101

98102
[tool.hatch.build]
99103
include = ["**/py.typed", "**/*.md", "LICENSE", "pact/**/*.py", "pact/**/*.pyi"]

0 commit comments

Comments
 (0)