Skip to content

Commit cc59640

Browse files
feat: better publishing workflow + tests (#8)
* tests * added yaml module for tests * fixed whitespace? * removed snapshot testing * need to fix precommit checks for code q --------- Co-authored-by: Ryan Amirthan Stephen <[email protected]>
1 parent ce45134 commit cc59640

File tree

13 files changed

+596
-413
lines changed

13 files changed

+596
-413
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,19 @@ jobs:
7676
steps:
7777
- name: Checkout source
7878
uses: actions/checkout@v4
79-
- name: Set up Python 3.8
79+
with:
80+
fetch-depth: 0
81+
- name: Set up Python 3.11
8082
uses: actions/setup-python@v5
8183
with:
82-
python-version: "3.8"
83-
- name: install flit
84+
python-version: "3.11"
85+
- name: Install flit
86+
run: pip install flit
87+
- name: Verify version
8488
run: |
85-
pip install flit~=3.4
89+
python -c "from src.autodoc2 import __version__; print(f'Publishing version: {__version__}')"
8690
- name: Build and publish
87-
run: |
88-
flit publish
91+
run: flit publish
8992
env:
9093
FLIT_USERNAME: __token__
91-
FLIT_PASSWORD: ${{ secrets.PYPI_TOKEN }}
94+
FLIT_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,5 @@ cython_debug/
153153
.vscode/
154154
docs/_build/
155155
_autodoc/
156+
157+
**/.DS_Store

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ py2fern write /path/to/your/package --output ./docs/api
2626

2727
This creates:
2828
- **MDX files** with Fern-compatible frontmatter and slugs
29-
- **`navigation.yml`** for Fern docs structure
29+
- **`navigation.yml`** for Fern docs structure
3030

3131
## Acknowledgments
3232

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ urls = {Home = "https://github.com/fern-api/py2fern"}
2020
requires-python = ">=3.8"
2121
dependencies = [
2222
"astroid>=2.7,<4",
23-
"tomli; python_version<'3.11'",
23+
"tomli; python_version<'3.11'",
2424
"typing-extensions",
2525
"typer[all]",
2626
"PyYAML"
@@ -31,6 +31,8 @@ testing = [
3131
"pytest",
3232
"pytest-regressions",
3333
"pytest-cov",
34+
"PyYAML", # Needed for navigation YAML tests
35+
"types-PyYAML", # Type stubs for mypy
3436
]
3537

3638
[project.scripts]

src/autodoc2/__init__.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,27 @@
33
A simplified fork of sphinx-autodoc2 focused purely on Python → Fern markdown output.
44
"""
55

6-
__version__ = "0.1.1"
6+
import subprocess
7+
from pathlib import Path
8+
9+
10+
def _get_version() -> str:
11+
"""Get version from git tag or fallback to default."""
12+
try:
13+
if Path(".git").exists():
14+
result = subprocess.run(
15+
["git", "describe", "--tags", "--exact-match", "HEAD"],
16+
capture_output=True,
17+
text=True,
18+
check=True,
19+
)
20+
version = result.stdout.strip()
21+
return version[1:] if version.startswith("v") else version
22+
except (subprocess.CalledProcessError, FileNotFoundError):
23+
pass
24+
25+
# Fallback version for development
26+
return "0.1.2-dev"
27+
28+
29+
__version__ = _get_version()

src/autodoc2/cli.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,20 @@ def _warn(msg: str, type_: WarningSubtypes) -> None:
255255
progress.console.print(f"[yellow]Warning[/yellow] {msg} [{type_.value}]")
256256

257257
config = Config()
258-
258+
259259
# Always use FernRenderer
260260
from autodoc2.render.fern_ import FernRenderer
261+
261262
render_class = FernRenderer
262-
263+
263264
for mod_name in to_write:
264265
progress.update(task, advance=1, description=mod_name)
265266
content = "\n".join(
266267
render_class(db, config, warn=_warn).render_item(mod_name)
267268
)
268-
269+
269270
# Use hyphens in filenames to match Fern slugs
270-
filename = mod_name.replace('.', '-').replace('_', '-')
271+
filename = mod_name.replace(".", "-").replace("_", "-")
271272
out_path = output / (filename + render_class.EXTENSION)
272273
paths.append(out_path)
273274
if out_path.exists() and out_path.read_text("utf8") == content:
@@ -283,6 +284,27 @@ def _warn(msg: str, type_: WarningSubtypes) -> None:
283284
nav_path.write_text(nav_content, "utf8")
284285
console.print(f"Navigation written to: {nav_path}")
285286

287+
# Validate all links
288+
console.print("[bold]Validating links...[/bold]")
289+
validation_results = renderer_instance.validate_all_links(str(output))
290+
291+
if validation_results["errors"]:
292+
console.print(
293+
f"[red]❌ {len(validation_results['errors'])} link errors found:[/red]"
294+
)
295+
for error in validation_results["errors"]:
296+
console.print(f" [red]• {error}[/red]")
297+
298+
if validation_results["warnings"]:
299+
console.print(
300+
f"[yellow]⚠️ {len(validation_results['warnings'])} link warnings:[/yellow]"
301+
)
302+
for warning in validation_results["warnings"]:
303+
console.print(f" [yellow]• {warning}[/yellow]")
304+
305+
if not validation_results["errors"] and not validation_results["warnings"]:
306+
console.print("[green]✅ All links validated successfully![/green]")
307+
286308
# remove any files that are no longer needed
287309
if clean:
288310
console.print("[bold]Cleaning old files[/bold]")

src/autodoc2/render/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Convert the database items into documentation."""
2+
23
from __future__ import annotations
34

45
import abc

0 commit comments

Comments
 (0)