Skip to content

Commit baf5905

Browse files
Develop (#9)
rough outline should be ready. Fixes #8, #2
1 parent bd2132d commit baf5905

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
<!-- towncrier release notes start -->
44

5+
## [0.0.4](https://github.com/Nagidal/hatch-semver/tree/0.0.4) - 2022-11-10
6+
7+
8+
### Development Details
9+
10+
- Plugin structure is ready, should know how to bump major, minor, patch [#2](https://github.com/Nagidal/hatch-semver/issues/2)
11+
12+
13+
### Documentation
14+
15+
- Better readme, but not final [#8](https://github.com/Nagidal/hatch-semver/issues/8)
16+
17+
518
## [0.0.3](https://github.com/Nagidal/hatch-semver/tree/0.0.3) - 2022-11-10
619

720

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@
33
A plugin for [hatch][hatch] to support [semantic versioning][semver].
44

55

6+
## Usage
7+
8+
Introduce *hatch-semver* as a build-dependency to your project (in `pyproject.toml`):
9+
10+
```toml
11+
[build-system]
12+
requires = [
13+
"hatchling>=1.8.0",
14+
"hatch-semver",
15+
]
16+
build-backend = "hatchling.build"
17+
```
18+
19+
Further down in `pyproject.toml`, where you specify your project's version, set version scheme
20+
to `semver`:
21+
```toml
22+
[tool.hatch.version]
23+
path = "src/<your_project>/__about__.py"
24+
scheme = "semver"
25+
```
26+
27+
You can then use hatch's usual [versioning commands][hatch_versioning] to bump your project's
28+
version in a semver-compliant way.
629

730
[hatch]: hatch.pypa.io/
831
[semver]: https://semver.org/
32+
[hatch_versioning]: https://hatch.pypa.io/latest/version/#updating

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ exclude_lines = [
116116
line-length = 102
117117

118118
[tool.towncrier]
119-
name = "hatch_semver"
119+
name = "hatch-semver"
120120
package = "hatch_semver"
121121
package_dir = "src"
122122
directory = "changelog.d"

src/hatch_semver/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
__maintainer__ = __author__
99
__maintainer_email__ = __author_email__
1010
__release_date__ = date(year=2022, month=11, day=10)
11-
__version__ = "0.0.3"
11+
__version__ = "0.0.4"
1212

src/hatch_semver/semver_scheme.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,37 @@ class SemverScheme(VersionSchemeInterface):
1010
- https://semver.org/
1111
- https://hatch.pypa.io/latest/plugins/version-scheme/reference/
1212
"""
13+
1314
PLUGIN_NAME = "semver"
1415

1516
def update(self, desired_version, original_version, version_data) -> str:
16-
return str("test_version")
17+
from semver import VersionInfo
18+
19+
original = VersionInfo(original_version)
20+
parts = desired_version.replace("micro", "patch").replace("fix", "patch").split(",")
21+
22+
for part in parts:
23+
next_version = getattr(original, "bump_" + part)()
24+
original = next_version
25+
if part == "minor":
26+
next_version = original.bump_minor()
27+
original = next_version
28+
elif part in ("post", "rev", "r"):
29+
raise ValeError(f"Semver has no concept of a post-release. Use 'build' instead")
30+
elif version == "dev":
31+
raise ValeError(f"Semver has no concept of a dev-release. Use 'build' instead")
32+
else:
33+
if len(parts) > 1:
34+
raise ValueError(
35+
"Cannot specify multiple update operations with an explicit version"
36+
)
37+
38+
next_version = VersionInfo.parse(part)
39+
if self.config.get("validate-bump", True) and next_version <= original:
40+
raise ValueError(
41+
f"Version `{part}` is not higher than the original version `{original_version}`"
42+
)
43+
else:
44+
return str(next_version)
45+
46+
return str(original)

0 commit comments

Comments
 (0)