Skip to content

Commit 4305282

Browse files
authored
auto-generate history from the changelog of the main branch of the poetry repo (#221)
1 parent db08689 commit 4305282

5 files changed

Lines changed: 34 additions & 2772 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ node_modules
22
public
33
assets/assets
44
/content/docs
5+
/content/history.md
56
/resources
67
.python-version
78
.vscode

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ help: ## Show this help
99
.PHONY: clean
1010
clean: ## Clean generated files
1111
@unlink content/docs &>/dev/null || true
12-
@rm -rf assets/ content/docs/ public/ resources/
12+
@rm -rf assets/ content/docs/ content/history.md public/ resources/
1313

1414
.PHONY: site
15-
site: node_modules content/docs ## Build and serve site
15+
site: node_modules content/docs content/history.md ## Build and serve site
1616
@test -f assets/assets/app.js || npx rollup --config
1717
@npm run dev
1818

1919
node_modules: package.json package-lock.json
2020
npm install
2121
@touch node_modules
2222

23-
content/docs: pyproject.toml
23+
content/docs content/history.md &: pyproject.toml
2424
poetry install
2525
poetry run ./bin/website configure $(WEBSITE_ARGS)
2626
poetry run ./bin/website docs pull $(WEBSITE_ARGS)

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ It's built using the static site generator [Hugo](https://gohugo.io) and the Mar
1515

1616
## Local development
1717

18+
> [!NOTE]
19+
> The following commands require GNU Make 4.3 or newer (the `Makefile` uses
20+
> [grouped targets](https://www.gnu.org/software/make/manual/html_node/Multiple-Targets.html),
21+
> introduced in 4.3). If you are on macOS, which may still ship an older version;
22+
> install a newer version with `brew install make` and invoke it as `gmake`.
23+
1824
To work on this project locally, first fork and clone this repo. Then:
1925

2026
```sh

bin/website

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ class ConfigureCommand(Command):
9999

100100

101101
class DocsPullCommand(ConfigureCommand):
102-
DESTINATION: Path = Path(__file__).parent.parent.joinpath("content/docs")
102+
DESTINATION = Path(__file__).parent.parent / "content" / "docs"
103+
HISTORY_DESTINATION = Path(__file__).parent.parent / "content" / "history.md"
104+
HISTORY_FRONTMATTER = "---\ntype: page\nlayout: single\ntitle: History\n---\n\n"
103105
REPOSITORY = "https://github.com/python-poetry/poetry.git"
104106

105107
name = "docs pull"
@@ -120,12 +122,17 @@ class DocsPullCommand(ConfigureCommand):
120122

121123
self.DESTINATION.mkdir(parents=True)
122124

125+
if self.HISTORY_DESTINATION.exists():
126+
self.HISTORY_DESTINATION.unlink()
127+
123128
if self.option("local"):
129+
local_src = Path(self.option("local"))
124130
self._pull_local_version(
125-
src=Path(self.option("local")),
131+
src=local_src,
126132
dest=self.DESTINATION,
127133
editable=self.option("editable"),
128134
)
135+
self._write_history(local_src / "CHANGELOG.md")
129136
return 0
130137

131138
for name, version in versions.items():
@@ -210,9 +217,24 @@ class DocsPullCommand(ConfigureCommand):
210217

211218
with path.joinpath(filepath.name).open("w") as f:
212219
f.write(new_content)
220+
221+
if version == "main":
222+
self._write_history(tmp_dir / "CHANGELOG.md")
213223
finally:
214224
os.chdir(cwd.as_posix())
215225

226+
def _write_history(self, changelog: Path) -> None:
227+
if not changelog.exists():
228+
raise RuntimeError(f"Changelog file not found at {changelog}")
229+
self.line(f" Writing history from <b>{changelog.name}</b>")
230+
lines = changelog.read_text(encoding="utf-8").splitlines(keepends=True)
231+
# replace changelog heading with history page title
232+
if lines and lines[0].lstrip().startswith("# "):
233+
lines = lines[1:]
234+
while lines and lines[0].strip() == "":
235+
lines = lines[1:]
236+
self.HISTORY_DESTINATION.write_text(self.HISTORY_FRONTMATTER + "".join(lines))
237+
216238

217239
class BuildCommand(DocsPullCommand):
218240
name = "build"

0 commit comments

Comments
 (0)