Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion bin/docs_scripts/generate_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ def nest(markdown: str) -> str:
return "\n".join(out)


def getting_started(major: int) -> str:
"""docs/getting-started.md for one major. Its install line pins that major, so a
reader never installs a major the page doesn't describe."""
text = (ROOT / "docs/getting-started.md").read_text()
if "{major}" not in text:
raise SystemExit("docs/getting-started.md: the install line must pin {major}")
pinned = text.replace("{major}", str(major))
return nest(pinned.replace("{next_major}", str(major + 1)))


def write(name: str, sections: list[str]) -> None:
(ROOT / "references" / name).write_text("\n\n".join(sections) + "\n")
print(f"wrote references/{name}")
Expand All @@ -239,7 +249,7 @@ def main() -> None:
(ROOT / "posthog/version.py").read_text().split('"')[1].split(".")[0]
)
major = opts.major or declared
started = nest((ROOT / "docs/getting-started.md").read_text())
started = getting_started(major)
body = [
"## Getting started",
started,
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ To send your first event, install the package, create a client, capture an event
## Install

```bash
pip install posthog
pip install "posthog>={major},<{next_major}"
```

## Initialize
Expand Down
7 changes: 7 additions & 0 deletions posthog/test/test_reference_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,10 @@ def test_summaries_keep_the_whole_first_paragraph(pkg):
generator.clean(cls)
md = generator.entry(cls, "FeatureFlagEvaluations")
assert "on the first access per (distinct_id, flag, value) tuple" in md


@pytest.mark.parametrize("major, pin", [(7, '"posthog>=7,<8"'), (8, '"posthog>=8,<9"')])
def test_getting_started_pins_the_install_to_the_page_major(major, pin):
text = generator.getting_started(major)
assert f"pip install {pin}" in text
assert "{major}" not in text and "{next_major}" not in text
2 changes: 1 addition & 1 deletion references/posthog-python-7.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ To send your first event, install the package, create a client, capture an event
### Install

```bash
pip install posthog
pip install "posthog>=7,<8"
```

### Initialize
Expand Down
2 changes: 1 addition & 1 deletion references/posthog-python-8.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ To send your first event, install the package, create a client, capture an event
### Install

```bash
pip install posthog
pip install "posthog>=8,<9"
```

### Initialize
Expand Down
2 changes: 1 addition & 1 deletion references/posthog-python-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ To send your first event, install the package, create a client, capture an event
### Install

```bash
pip install posthog
pip install "posthog>=7,<8"
```

### Initialize
Expand Down
Loading