Skip to content

Commit

Permalink
Use towncrier to manage release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpre committed Dec 1, 2023
1 parent af59ab8 commit b44e5ef
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ A few sentences and/or a bulleted list to describe and motivate the change:
- [ ] docstring updated (if appropriate),
- [ ] update user guide (if appropriate),
- [ ] added tests,
- [ ] added line to CHANGES.rst,
- [ ] add a changelog entry in the `upcoming_changes` folder (see [`upcoming_changes/README.rst`](https://github.com/hyperspy/holospy/blob/main/upcoming_changes/README.rst)),
- [ ] Check formatting of the changelog entry (and eventual user guide changes) in the `docs/readthedocs.org:holospy` build of this PR (link in github checks)
- [ ] ready for review.

### Minimal example of the bug fix or the new feature
Expand Down
13 changes: 8 additions & 5 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ build:
os: ubuntu-22.04
tools:
python: "3.11"
jobs:
post_checkout:
- git fetch --unshallow || true

# Build documentation in the docs/ directory with Sphinx
sphinx:
Expand All @@ -20,8 +23,8 @@ formats:
- htmlzip

python:
install:
- method: pip
path: .
extra_requirements:
- doc
install:
- method: pip
path: .
extra_requirements:
- doc
7 changes: 4 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Release Notes
Changelog entries for the development version are available at
https://holospy.readthedocs.io/en/latest/changes.html

0.2 (UNRELEASED)
================
.. towncrier-draft-entries:: |release| [UNRELEASED]

.. towncrier release notes start
- Fix getting version from metadata `#16 <https://github.com/hyperspy/holospy/pull/16>`_)
.. _changes_0.1:

0.1 (2023-11-15)
================
Expand Down
9 changes: 9 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"sphinx.ext.githubpages",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinxcontrib.towncrier",
]

linkcheck_ignore = [
Expand Down Expand Up @@ -107,5 +108,13 @@
if Version(numpydoc.__version__) >= Version("1.6.0rc0"):
numpydoc_validation_checks = {"all", "ES01", "EX01", "GL02", "GL03", "SA01", "SS06"}

# -- Options for towncrier_draft extension -----------------------------------

# Options: draft/sphinx-version/sphinx-release
towncrier_draft_autoversion_mode = "draft"
towncrier_draft_include_empty = False
towncrier_draft_working_directory = ".."


# def setup(app):
# app.add_css_file("custom-styles.css")
49 changes: 49 additions & 0 deletions prepare_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3
import argparse
import re
import subprocess


def run_towncrier(tag):
cmd = ("towncrier", "build", "--version", tag.strip("v"))

return subprocess.call(cmd)


def update_fallback_version_in_pyproject(tag, fname="pyproject.toml"):
version = tag.strip("v").split(".")
# Default to +1 on minor version
major, minor = version[0], int(version[1]) + 1

with open(fname, "r") as file:
lines = file.readlines()

pattern = "fallback_version"
new_version = f"{major}.{minor}.dev0"
# Iterate through the lines and find the pattern
for i, line in enumerate(lines):
if re.search(pattern, line):
lines[i] = f'{pattern} = "{new_version}"\n'
break

# Write the updated content back to the file
with open(fname, "w") as file:
file.writelines(lines)

print(
f"\nNew (fallback) dev version ({new_version}) written to `pyproject.toml`.\n"
)


if __name__ == "__main__":
# Get tag argument
parser = argparse.ArgumentParser()
parser.add_argument("tag")
args = parser.parse_args()
tag = args.tag

# Update release notes
run_towncrier(tag)

# Update fallback version for setuptools_scm
update_fallback_version_in_pyproject(tag)
45 changes: 45 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ doc = [
"pydata-sphinx-theme>=0.13",
"sphinx",
"sphinx-favicon",
"sphinxcontrib-towncrier",
"towncrier",
]
dev = [
"black",
Expand All @@ -71,6 +73,7 @@ branch = true
source = ["holospy"]
omit = [
"holospy/tests/*",
"prepare_release.py",
]

[tool.coverage.report]
Expand All @@ -97,3 +100,45 @@ include = ["holospy*"]
# Presence enables setuptools_scm, the version will be determine at build time from git
# The version will be updated by the `prepare_release.py` script
fallback_version = "0.2.dev0"

[tool.towncrier]
package = "holospy"
filename = "CHANGES.rst"
directory = "upcoming_changes/"
title_format = "{version} ({project_date})"
issue_format = "`#{issue} <https://github.com/hyperspy/holospy/issues/{issue}>`_"

[[tool.towncrier.type]]
directory = "new"
name = "New features"
showcontent = true

[[tool.towncrier.type]]
directory = "bugfix"
name = "Bug Fixes"
showcontent = true

[[tool.towncrier.type]]
directory = "doc"
name = "Improved Documentation"
showcontent = true

[[tool.towncrier.type]]
directory = "deprecation"
name = "Deprecations"
showcontent = true

[[tool.towncrier.type]]
directory = "enhancements"
name = "Enhancements"
showcontent = true

[[tool.towncrier.type]]
directory = "api"
name = "API changes"
showcontent = true

[[tool.towncrier.type]]
directory = "maintenance"
name = "Maintenance"
showcontent = true
8 changes: 4 additions & 4 deletions releasing_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ To publish a new HoloSpy release do the following steps:

## Preparation

- Create a new PR to the 'main' branch for the release process, e.g. `release_v0.1.1` with
the following changes:
- Update and check release notes
- Update dev `fallback_version` in `pyproject.toml`
- In a pull request, prepare the release by running the `prepare_release.py` python script (e.g. `python prepare_release.py 0.2`), which will do the following:
- update the release notes in `CHANGES.rst` by running `towncrier`,
- update the `setuptools_scm` fallback version in `pyproject.toml` (for a patch release, this will stay the same).
- Check release notes
- Let that PR collect comments for a day to ensure that other maintainers are comfortable
with releasing
- Set correct date and version number in `CHANGELOG.rst`
Expand Down
1 change: 1 addition & 0 deletions upcoming_changes/16.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix getting version from metadata

0 comments on commit b44e5ef

Please sign in to comment.