Skip to content

Commit 2221e03

Browse files
Gitznikgaborbernatchrysle
authored
Introduce towncrier (#1201)
* Introduce towncrier with basic configuration * Format changelog according to keep a changelog * Add pre-commit hook * Add changelog entry * Update PR template * Switch to default fragment types * Update .github/PULL_REQUEST_TEMPLATE.md Co-authored-by: chrysle <[email protected]> * Update news contribution docs * Update bump changelog workflow * Remove redundant news fragments * Add empty gitignore file to make sure changelog.d folder is tracked * Apply suggestions from code review Co-authored-by: chrysle <[email protected]> * Add changelog entry * Build changelog during `build_docs` nox command * Moved towncrier changelog entry to docs block * Stop adding version number to top of changelog via mkdocs script * Render current newsfragments cleanly during build docs * Remove extra stdout lines from towncrier build step * Add draft changelog file to gitignore * Add upcoming changes to prod changelog * Remove draft changelog in site after build * Create news fragment for current dev changelog --------- Co-authored-by: Bernát Gábor <[email protected]> Co-authored-by: chrysle <[email protected]>
1 parent 4dd1b6b commit 2221e03

12 files changed

+234
-101
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- add an 'x' in the brackets below -->
22

3-
- [ ] I have added an entry to `docs/changelog.md`
3+
- [ ] I have added a news fragment under `changelog.d/` (if the patch affects the end users)
44

55
## Summary of changes
66

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ jobs:
139139
- name: Create pull request branch
140140
run: git switch -c "bump-changelog-for-${RELEASE_VERSION}"
141141
- name: Update changelog
142-
run: echo -e "## dev\n\n## $RELEASE_VERSION\n$(tail -n +2 CHANGELOG.md)" > CHANGELOG.md
142+
run: pipx run towncrier build --yes --version $RELEASE_VERSION
143143
- name: Commit and push change
144144
run: |
145145
git config --global user.name 'github-actions[bot]'

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ __pycache__
1515
build
1616
*.whl
1717
/pipx.1
18+
/docs/_draft_changelog.md

CHANGELOG.md

+158-93
Large diffs are not rendered by default.

CONTRIBUTING.md

+36
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,42 @@ Thanks for your interest in contributing to pipx!
33
Everyone who interacts with the pipx project via codebase, issue tracker, chat rooms, or otherwise is expected to follow
44
the [PSF Code of Conduct](https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md).
55

6+
7+
## Submitting changes
8+
9+
1. Fork [the GitHub repository](https://github.com/pypa/pipx).
10+
2. Make a branch off of `main` and commit your changes to it.
11+
3. Add a changelog entry.
12+
4. Submit a pull request to the `main` branch on GitHub, referencing an
13+
open issue.
14+
15+
### Changelog entries
16+
17+
The `CHANGELOG.md` file is built by
18+
[towncrier](https://pypi.org/project/towncrier/) from news fragments in the
19+
`changelog.d/` directory. To add an entry, create a news fragment in that directory
20+
named `{number}.{type}.md`, where `{number}` is the issue number,
21+
and `{type}` is one of `feature`, `bugfix`, `doc`, `removal`, or `misc`.
22+
23+
For example, if your issue number is 1234 and it's fixing a bug, then you
24+
would create `changelog.d/1234.bugfix.md`. PRs can span multiple
25+
categories by creating multiple files: if you added a feature and
26+
deprecated/removed an old feature for issue #5678, you would create
27+
`changelog.d/5678.feature.md` and `changelog.d/5678.removal.md`.
28+
29+
A changelog entry is meant for end users and should only contain details
30+
relevant to them. In order to maintain a consistent style, please keep
31+
the entry to the point, in sentence case, shorter than 80 characters,
32+
and in an imperative tone. An entry should complete the sentence "This
33+
change will ...". If one line is not enough, use a summary line in an
34+
imperative tone, followed by a description of the change in one or more
35+
paragraphs, each wrapped at 80 characters and separated by blank lines.
36+
37+
You don't need to reference the pull request or issue number in a
38+
changelog entry, since towncrier will add a link using the number in the
39+
file name. Similarly, you don't need to add your name to the entry,
40+
since that will be associated with the pull request.
41+
642
## Running pipx For Development
743

844
To develop `pipx`, either create a [developer environment](#creating-a-developer-environment), or perform an editable

changelog.d/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.gitignore

changelog.d/1161.doc.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Introduce towncrier for managing the changelog

changelog.d/1198.doc.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add workaround for using pipx applications in shebang under macOS

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ plugins:
4747
- gen-files:
4848
scripts:
4949
- scripts/gen_doc_pages.py
50+
- macros

noxfile.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import shutil
12
import subprocess
23
import sys
34
from pathlib import Path
@@ -6,7 +7,7 @@
67

78
PYTHON_ALL_VERSIONS = ["3.12", "3.11", "3.10", "3.9", "3.8"]
89
PYTHON_DEFAULT_VERSION = "3.12"
9-
DOC_DEPENDENCIES = ["jinja2", "mkdocs", "mkdocs-material", "mkdocs-gen-files"]
10+
DOC_DEPENDENCIES = ["jinja2", "mkdocs", "mkdocs-material", "mkdocs-gen-files", "mkdocs-macros-plugin", "towncrier"]
1011
MAN_DEPENDENCIES = ["argparse-manpage[setuptools]"]
1112
TEST_DEPENDENCIES = ["pytest", "pypiserver[passlib]", 'setuptools; python_version>="3.12"', "pytest-cov"]
1213
# Packages whose dependencies need an intact system PATH to compile
@@ -55,6 +56,22 @@ def tests_with_options(session: nox.Session, *, net_pypiserver: bool) -> None:
5556
session.notify("cover")
5657

5758

59+
def create_upcoming_changelog(session: nox.Session) -> Path:
60+
draft_changelog_content = session.run("towncrier", "build", "--version", "Upcoming", "--draft", silent=True)
61+
draft_changelog = Path("docs", "_draft_changelog.md")
62+
if draft_changelog_content and "No significant changes" not in draft_changelog_content:
63+
lines_to_keep = draft_changelog_content.split("\n")
64+
changelog_start = 0
65+
for i, line in enumerate(lines_to_keep):
66+
if line.startswith("##"):
67+
changelog_start = i
68+
break
69+
lines_to_keep[changelog_start] = "## Planned for next release"
70+
clean_changelog_content = "\n".join(lines_to_keep[changelog_start:])
71+
draft_changelog.write_text(clean_changelog_content)
72+
return draft_changelog
73+
74+
5875
@nox.session(python=PYTHON_ALL_VERSIONS)
5976
def tests(session: nox.Session) -> None:
6077
"""Tests using local pypiserver only"""
@@ -112,13 +129,19 @@ def build_docs(session: nox.Session) -> None:
112129
site_dir = session.posargs or ["site/"]
113130
session.install(*DOC_DEPENDENCIES, ".")
114131
session.env["PIPX__DOC_DEFAULT_PYTHON"] = "typically the python used to execute pipx"
132+
upcoming_changelog = create_upcoming_changelog(session)
115133
session.run("mkdocs", "build", "--strict", "--site-dir", *site_dir)
134+
upcoming_changelog.unlink(missing_ok=True)
135+
for site in site_dir:
136+
shutil.rmtree(Path(site, "_draft_changelog"))
116137

117138

118139
@nox.session(python=PYTHON_DEFAULT_VERSION)
119140
def watch_docs(session: nox.Session) -> None:
120141
session.install(*DOC_DEPENDENCIES, ".")
142+
upcoming_changelog = create_upcoming_changelog(session)
121143
session.run("mkdocs", "serve", "--strict")
144+
upcoming_changelog.unlink(missing_ok=True)
122145

123146

124147
@nox.session(python=PYTHON_DEFAULT_VERSION)

pyproject.toml

+9
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ lint.mccabe.max-complexity = 15
7474
[tool.pytest.ini_options]
7575
markers = ["all_packages: test install with maximum number of packages"]
7676

77+
[tool.towncrier]
78+
directory = "changelog.d"
79+
filename = "CHANGELOG.md"
80+
start_string = "<!-- towncrier release notes start -->\n"
81+
underlines = ["", "", ""]
82+
title_format = "## [{version}](https://github.com/pypa/pipx/tree/{version}) - {project_date}"
83+
issue_format = "[#{issue}](https://github.com/pypa/pipx/issues/{issue})"
84+
package = "pipx"
85+
7786
[[tool.mypy.overrides]]
7887
module = ["pipx.version", "pycowsay.*"]
7988
ignore_missing_imports = true

scripts/gen_doc_pages.py

-5
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,3 @@ def get_help(cmd: Optional[str]) -> str:
4646
with mkdocs_gen_files.open("docs.md", "wt") as file_handler:
4747
file_handler.write(env.get_template("docs.md").render(**params))
4848
file_handler.write("\n")
49-
50-
with mkdocs_gen_files.open("changelog.md", "rt") as file_handler:
51-
text = file_handler.read()
52-
with mkdocs_gen_files.open("changelog.md", "wt") as file_handler:
53-
file_handler.write(f"## {__version__}" + text[len("## dev") :])

0 commit comments

Comments
 (0)