|
| 1 | +import shutil |
1 | 2 | import subprocess
|
2 | 3 | import sys
|
3 | 4 | from pathlib import Path
|
|
6 | 7 |
|
7 | 8 | PYTHON_ALL_VERSIONS = ["3.12", "3.11", "3.10", "3.9", "3.8"]
|
8 | 9 | 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"] |
10 | 11 | MAN_DEPENDENCIES = ["argparse-manpage[setuptools]"]
|
11 | 12 | TEST_DEPENDENCIES = ["pytest", "pypiserver[passlib]", 'setuptools; python_version>="3.12"', "pytest-cov"]
|
12 | 13 | # 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:
|
55 | 56 | session.notify("cover")
|
56 | 57 |
|
57 | 58 |
|
| 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 | + |
58 | 75 | @nox.session(python=PYTHON_ALL_VERSIONS)
|
59 | 76 | def tests(session: nox.Session) -> None:
|
60 | 77 | """Tests using local pypiserver only"""
|
@@ -112,13 +129,19 @@ def build_docs(session: nox.Session) -> None:
|
112 | 129 | site_dir = session.posargs or ["site/"]
|
113 | 130 | session.install(*DOC_DEPENDENCIES, ".")
|
114 | 131 | session.env["PIPX__DOC_DEFAULT_PYTHON"] = "typically the python used to execute pipx"
|
| 132 | + upcoming_changelog = create_upcoming_changelog(session) |
115 | 133 | 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")) |
116 | 137 |
|
117 | 138 |
|
118 | 139 | @nox.session(python=PYTHON_DEFAULT_VERSION)
|
119 | 140 | def watch_docs(session: nox.Session) -> None:
|
120 | 141 | session.install(*DOC_DEPENDENCIES, ".")
|
| 142 | + upcoming_changelog = create_upcoming_changelog(session) |
121 | 143 | session.run("mkdocs", "serve", "--strict")
|
| 144 | + upcoming_changelog.unlink(missing_ok=True) |
122 | 145 |
|
123 | 146 |
|
124 | 147 | @nox.session(python=PYTHON_DEFAULT_VERSION)
|
|
0 commit comments