Skip to content

Commit db2be1e

Browse files
Develop (#65)
fixed #59 fixed #60 fixed #61 fixed #62 fixed #63
1 parent 962431a commit db2be1e

File tree

9 files changed

+140
-20
lines changed

9 files changed

+140
-20
lines changed

CHANGELOG.md

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

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

5+
## [1.0.1](https://github.com/Nagidal/hatch-semver/tree/1.0.1) - 2022-11-17
6+
7+
8+
### Documentation
9+
10+
- Fixed typos and errors in the documentation [#59](https://github.com/Nagidal/hatch-semver/issues/59)
11+
- Set correct project homepage in `pyproject.toml`. It should be now linked from [PyPI](https://pypi.org/project/hatch-semver/). [#64](https://github.com/Nagidal/hatch-semver/issues/64)
12+
13+
14+
### Development Details
15+
16+
- Set current date in `__about__.py` [#61](https://github.com/Nagidal/hatch-semver/issues/61)
17+
- Wrote a test for current date in `__about__.py` [#62](https://github.com/Nagidal/hatch-semver/issues/62)
18+
- Wrote a test for current version in the changelog [#63](https://github.com/Nagidal/hatch-semver/issues/63)
19+
20+
521
## [1.0.0](https://github.com/Nagidal/hatch-semver/tree/1.0.0) - 2022-11-17
622

723

docs/CHANGELOG.md

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

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

5+
## [1.0.1](https://github.com/Nagidal/hatch-semver/tree/1.0.1) - 2022-11-17
6+
7+
8+
### Documentation
9+
10+
- Fixed typos and errors in the documentation [#59](https://github.com/Nagidal/hatch-semver/issues/59)
11+
- Set correct project homepage in `pyproject.toml`. It should be now linked from [PyPI](https://pypi.org/project/hatch-semver/). [#64](https://github.com/Nagidal/hatch-semver/issues/64)
12+
13+
14+
### Development Details
15+
16+
- Set current date in `__about__.py` [#61](https://github.com/Nagidal/hatch-semver/issues/61)
17+
- Wrote a test for current date in `__about__.py` [#62](https://github.com/Nagidal/hatch-semver/issues/62)
18+
- Wrote a test for current version in the changelog [#63](https://github.com/Nagidal/hatch-semver/issues/63)
19+
20+
521
## [1.0.0](https://github.com/Nagidal/hatch-semver/tree/1.0.0) - 2022-11-17
622

723

docs/user_guide/1-commands.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ Same as with pre-releases, this is prone to a [bug in python-semver][bug].
152152
| `1.0.0+fix-docs.2` | `build=docs-fixed` | `1.0.0+fix-docs.3` <sup>[bug][bug]</sup> |
153153

154154
Build versions are all of the same precedence, so technically, a version bump does not occur.
155-
Normally, [bump-validation][validation] checks whether the resulting version is of the same precedence as the old one.
155+
Normally, [bump-validation][validation] checks whether the resulting version is higher than the old one.
156156
However, if all that changes is the build identifier, a version of equal precedence is sufficient to pass the validation.
157157

158-
| Old Version | Command | validate-bump | New Version |
159-
| ---------------------- | ------------------- | ------------- | -------------------- |
158+
| Old Version | Command | validate-bump | New Version |
159+
| ---------------------- | ------------------- | ------------- | ---------------------- |
160160
| `4.8.5-rc.2` | `build=tracing` | True | `4.8.5-rc.2+tracing.1` |
161-
| `4.8.5-rc.2+tracing.2` | `4.8.5-rc.2+debug` | True | `4.8.5-rc.2+debug` |
161+
| `4.8.5-rc.2+tracing.2` | `4.8.5-rc.2+debug` | True | `4.8.5-rc.2+debug` |
162162

163163
### Development Build Shortcut
164164

@@ -177,7 +177,7 @@ Similar to the [alpha and beta][ab-short] shortcuts, `dev` is not an alias, so d
177177

178178
Similar to [python-semver's][python-semver] inability to bump alphanumeric pre-release identifiers, alphanumeric build identifiers will also not be bumped.
179179
The returned result is the exact same version.
180-
A ValidationError is not raised because when bumping or changing build identifiers equal precedece of the old and new version is sufficient.
180+
A ValidationError is not raised because when bumping or changing build identifiers, equal precedece of the old and new version is sufficient.
181181

182182
| Old Version | Command | validate-bump | New Version |
183183
| ---------------------- | ------------------- | ------------- | -------------------- |
@@ -189,7 +189,7 @@ You can chain commands together by comma like this: `<command1>,<command2>,<comm
189189
They are executed one by one in the specified sequence. Some straight-forward and most common examples of chained commands are presented in the [pre-release][chained-pre] section.
190190

191191
The bump validation check is performed only after the last command is executed.
192-
It is therefore OK to temporarily violate the version precedence rule for the intermediate versions as long as the last resulting version passes the validation agains the old version.
192+
It is therefore OK to temporarily violate the version precedence rule for the intermediate versions as long as the last resulting version passes the validation against the old version.
193193

194194
| Old Version | Command | validate-bump | New Version |
195195
| ---------------------- | ------------------- | ------------- | -------------------- |

docs/user_guide/2-migrating-to-semver.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ If you have used the hatch [standard][hatch_versioning] versioning scheme plugin
55

66
### Identical or Similar Behavior
77

8-
| Old version | command | Standard Plugin | Semver Plugin |
8+
| Old version | Command | Standard Plugin | Semver Plugin |
99
| ----------- | --------- | ------------------- | ------------------ |
1010
| `1.0.0` | `major` | `2.0.0` | `2.0.0` |
1111
| `1.0.0` | `minor` | `1.1.0` | `1.1.0` |
@@ -17,15 +17,15 @@ If you have used the hatch [standard][hatch_versioning] versioning scheme plugin
1717
When bumping only the pre-release segment of a version which has not yet any pre-release segment, hatch-semver automatically bumps the patch version.
1818
It also automatically adds a purely numeric identifier *1* through which bumping becomes possible. Without a numeric identifier, this pre-release [could not be bumped][unbumpable].
1919

20-
| Old version | command | Standard Plugin | Semver Plugin | Comment |
20+
| Old version | Command | Standard Plugin | Semver Plugin | Comment |
2121
| ----------- | ------- | ------------------- | ------------------ | -------------------------- |
2222
| `1.0.0` | `alpha` | `1.0.0a0` | `1.0.1-alpha.1` | patch version auto-bumped |
2323
| `1.0.0` | `beta` | `1.1.0b0` | `1.0.1-beta.1` | patch version auto-bumped |
24-
| `1.0.0` | `rc`<br>`pre` | `1.1.0rc0` | `1.0.1-rc.1` | patch version auto-bumped |
24+
| `1.0.0` | `rc` | `1.1.0rc0` | `1.0.1-rc.1` | patch version auto-bumped |
2525

26-
The patch segment of the [version core][bnf] is not bumped, if prerelease is bumped in a [chained command][chain] where a version core bump has occurred before.
26+
The patch segment of the [version core][bnf] is not bumped, if pre-release is bumped in a [chained command][chain] where a version core bump has occurred before.
2727

28-
| Old version | command | Standard Plugin | Semver Plugin | Comment |
28+
| Old version | Command | Standard Plugin | Semver Plugin | Comment |
2929
| ----------- | -------------- | ----------------| --------------- | ------------------------------ |
3030
| `1.0.0` | `patch,alpha` | `1.0.1a0` | `1.0.1-alpha.1` | patch version not auto-bumped |
3131
| `1.0.0` | `minor,beta` | `1.1.0b0` | `1.1.0-beta.1` | patch version not auto-bumped |
@@ -40,21 +40,21 @@ It performs a real bump *to the release version*.
4040
This normally goes along with a [validation][validation] check.
4141
When you try to release version which is not a prerelease, this will raise a ValidationError.
4242

43-
| Old version | command | validate-bump | Standard Plugin | Semver Plugin |
43+
| Old version | Command | validate-bump | Standard Plugin | Semver Plugin |
4444
| ------------- | --------- | ------------- | ------------------- | ------------------ |
45-
| `1.0.0` | `release` | True | `1.0.0` | `ValueError` |
45+
| `1.0.0` | `release` | True | `1.0.0` | `ValidationError` |
4646
| `1.0.0` | `release` | False | `1.0.0` | `1.0.0` |
47-
| `1.0.0+dev.1` | `release` | True | `1.0.0` | `ValueError` |
47+
| `1.0.0+dev.1` | `release` | True | `1.0.0` | `ValidationError` |
4848
| `1.0.0+dev.1` | `release` | False | `1.0.0` | `1.0.0` |
4949

5050
### Unsupported Commands
5151

5252
Hatch's [standard][hatch_versioning]'s versioning scheme's `rev`, `r`, `post` commands are not supported.
5353
There is no concept of a revision or a post-release in [Semver][semver].
54-
However, with `build=post`, for instance you could accomplish add the build identifiers *post* and *1* which would be similar to a PEP 440 post-release.
54+
However, with `build=post`, for instance you could add the build identifiers *post* and *1* which would be similar to a PEP 440 post-release.
5555
Like in PEP 440, also in Semver build identifiers have the same precedence.
5656

57-
The abbreviations `a`, `b`, and `c` for `alpha`, `beta`, `rc`, and `preview` are also not supported and will result in [python-semver][python-semver] throwing a `ValueError` with *... is not a valid SemVer string*. Hatch-semver actually uses `pre` as an alias for [prerelease][prerelease].
57+
The abbreviations `a`, `b`, and `c` for `alpha`, `beta`, `rc`, and `preview`,respectively, are also not supported and will result in [python-semver][python-semver] throwing a `ValueError` with *... is not a valid SemVer string*. Hatch-semver actually uses `pre` as an alias for [pre-release][prerelease].
5858

5959
Semver allows custom identifiers in prereleases, so if you really wanted an `a0` pre-release, you could achieve it by bumping to a specific version, i.e. `hatch version 1.2.3-a0` although such alphanumeric identifiers [cannot be bumped][unbumpable] by [python-semver].
6060
Better go with `1.2.3-a.1` which could be bumped to `1.2.3-a.2`, `1.2.3-a.3` etc.

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ dynamic = [
4949
]
5050

5151
[project.urls]
52-
Homepage = "https://github.com/Nagidal/hatch-semver"
52+
Homepage = "https://nagidal.github.io/hatch-semver/"
53+
Repository = "https://github.com/Nagidal/hatch-semver"
5354
Issues = "https://github.com/Nagidal/hatch-semver/issues"
55+
PyPI = "https://pypi.org/project/hatch-semver/"
5456

5557
[project.entry-points.hatch]
5658
semver = "hatch_semver.plugin.hooks"

src/hatch_semver/__about__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
__author_email__ = "[email protected]"
88
__maintainer__ = __author__
99
__maintainer_email__ = __author_email__
10-
__release_date__ = date(year=2022, month=11, day=13)
11-
__version__ = "1.0.0"
10+
__release_date__ = date(year=2022, month=11, day=17)
11+
__version__ = "1.0.1"

tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
from hatch.utils.fs import Path, temp_directory
99

1010
collect_ignore = [
11-
# "test_semver_scheme.py",
11+
# "test_about.py",
1212
# "test_bump_instruction.py",
13+
# "test_changelog.py",
14+
# "test_hooks.py",
15+
# "test_semver_scheme.py",
1316
]
1417

1518

tests/test_about.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
3+
import datetime
4+
5+
import hatch_semver.__about__ as about
6+
7+
8+
def test_date():
9+
release_date = about.__release_date__
10+
assert isinstance(
11+
release_date, datetime.date
12+
), "__release_date__ must be instance of datetime.date"
13+
today = datetime.datetime.today()
14+
assert release_date.year == today.year, "date.year in `__about__.py` is not current"
15+
assert release_date.month == today.month, "date.month in `__about__.py` is not current"
16+
assert release_date.day == today.day, "date.day in `__about__.py` is not current"
17+
18+
19+
def test_strings():
20+
for text in (
21+
about.__author__,
22+
about.__author_email__,
23+
about.__maintainer__,
24+
about.__maintainer_email__,
25+
):
26+
assert text
27+
assert isinstance(text, str)
28+
29+
30+
def test_emails():
31+
for mail in (
32+
about.__author_email__,
33+
about.__maintainer_email__,
34+
):
35+
assert "@" in mail

tests/test_changelog.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
3+
4+
import re
5+
from pathlib import Path
6+
7+
import pytest
8+
9+
import hatch_semver.__about__ as about
10+
11+
12+
@pytest.fixture
13+
def changelog_files():
14+
with open(
15+
Path(__file__).parent.parent.absolute() / "CHANGELOG.md", encoding="utf-8"
16+
) as root_changelog, open(
17+
Path(__file__).parent.parent.absolute() / "docs" / "CHANGELOG.md", encoding="utf-8"
18+
) as docs_changelog:
19+
yield root_changelog, docs_changelog
20+
21+
22+
semver_re = re.compile(
23+
r"(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?"
24+
)
25+
""" regex adapted from https://semver.org/ (just ditched the start and end of the string)"""
26+
27+
28+
def test_current_version_in_changelog(changelog_files):
29+
"""
30+
Reads lines from the changelog until it encounters one which starts with
31+
a heading level 2 (`## `) what should follow is a link to the current version in
32+
Markdown syntax, e.g. `[1.0.0](https://...)`.
33+
then it tries to get a match for the semver regex and compares it to the version
34+
set in __about__.py
35+
"""
36+
for file in changelog_files:
37+
found_at_least_one_heading_line = False
38+
while not (line := file.readline()).startswith("## "):
39+
continue
40+
else:
41+
found_at_least_one_heading_line = True
42+
match = semver_re.search(line)
43+
assert match, "Did not find any Semver version in the first level 2 heading"
44+
version_in_changelog = match.group(0)
45+
assert (
46+
version_in_changelog == about.__version__
47+
), f"Current version is not at the top of the changelog {file.name}"
48+
assert found_at_least_one_heading_line, f"Did not find any level 2 heading in {file.name}"

0 commit comments

Comments
 (0)