Skip to content

Commit 499c8f7

Browse files
authored
use incremental to canonicalize versions for release (#329)
1 parent dfaa241 commit 499c8f7

3 files changed

Lines changed: 27 additions & 9 deletions

File tree

CONTRIBUTING.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ Step-by-step
3030
- Define the final release version you are preparing.
3131

3232
- towncrier uses `CalVer <https://calver.org/>`_ of the form ``YY.MM.micro`` with the micro version just incrementing.
33-
- Normalize the version according to `PEP 440 <https://www.python.org/dev/peps/pep-0440/#normalization>`_.
33+
- Normalize the version according to `incremental <https://github.com/twisted/incremental/>`_.
3434

3535
- This requires that ``towncrier[dev]`` extra is installed.
3636
- ``venv/bin/python admin/canonicalize_version.py 19.09.00-rc1``
37-
- Outputs ``19.9rc1`` which is the form to be used.
37+
- Outputs ``19.9.0.rc1`` which is the form to be used.
3838

39-
- Create a release branch with a name of the form ``release-19.9`` starting from the ``master`` branch.
39+
- Create a release branch with a name of the form ``release-19.9.0`` starting from the ``master`` branch.
4040

4141
- On the new release branch you will commit all tagged release candidate commits as well as the final tagged release commit.
4242

4343
- Update the version to the release candidate with the first being ``rc1`` (as opposed to 0).
4444

45-
- In ``src/towncrier/_version.py`` the version is set using ``incremental`` such as ``__version__ = Version('towncrier', 19, 9, release_candidate=1)``
45+
- In ``src/towncrier/_version.py`` the version is set using ``incremental`` such as ``__version__ = Version('towncrier', 19, 9, 0, release_candidate=1)``
4646

4747
- Run ``venv/bin/towncrier build --yes`` to build the the newsfragments into the release notes document and to automatically remove the newsfragment files.
4848

@@ -54,7 +54,7 @@ Step-by-step
5454

5555
- Request a review and address raised concerns until receiving an approval.
5656

57-
- Tag that commit such as ``19.9rc1`` and push the tag to the primary repository.
57+
- Tag that commit such as ``19.9.0.rc1`` and push the tag to the primary repository.
5858

5959
- This will result in another build which will publish to PyPI.
6060
- Confirm the presence of the release on PyPI.
@@ -73,7 +73,7 @@ Step-by-step
7373

7474
- If ready for a final release, remove the release candidate indicator from the version.
7575

76-
- Edit ``src/towncrier/_version.py`` such as ``__version__ = Version('towncrier', 19, 9)`` to remove the release candidate indication.
76+
- Edit ``src/towncrier/_version.py`` such as ``__version__ = Version('towncrier', 19, 9, 0)`` to remove the release candidate indication.
7777

7878
- Return to the towncrier build step and continue.
7979

admin/canonicalize_version.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
import click
2+
import incremental
23
import packaging.utils
34

45

56
@click.command()
67
@click.argument("version")
78
def cli(version):
8-
"""Canonicalizes the passed version according to PEP 517."""
9-
canonicalized_version = packaging.utils.canonicalize_version(version)
9+
"""Canonicalizes the passed version according to incremental."""
1010

11-
click.echo(canonicalized_version)
11+
parsed_version = packaging.utils.Version(version)
12+
13+
release_candidate = None
14+
if parsed_version.pre is not None:
15+
if parsed_version.pre[0] == 'rc':
16+
release_candidate = parsed_version.pre[1]
17+
18+
incremental_version = incremental.Version(
19+
package="",
20+
major=parsed_version.major,
21+
minor=parsed_version.minor,
22+
micro=parsed_version.micro,
23+
release_candidate=release_candidate,
24+
post=parsed_version.post,
25+
dev=parsed_version.dev,
26+
)
27+
28+
click.echo(incremental_version.public())
1229

1330

1431
if __name__ == "__main__":
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)