|
1 | | -# sphinx-autodoc2-fern |
| 1 | +# py2fern |
2 | 2 |
|
3 | | -Generate Fern-compatible API documentation from Python packages using static analysis. |
| 3 | +Generate [Fern](https://buildwithfern.com) API documentation from Python packages using static analysis. |
4 | 4 |
|
5 | | -Fork of [`sphinx-autodoc2`](https://github.com/sphinx-extensions2/sphinx-autodoc2) with [Fern](https://buildwithfern.com) output support. |
| 5 | +Simplified fork of [`sphinx-autodoc2`](https://github.com/sphinx-extensions2/sphinx-autodoc2) focused purely on **Python → Fern markdown** output. |
6 | 6 |
|
7 | 7 | ## Installation |
8 | 8 |
|
9 | 9 | ```bash |
10 | | -pip install sphinx-autodoc2-fern |
| 10 | +pipx install py2fern |
11 | 11 | ``` |
12 | 12 |
|
13 | 13 | ## Usage |
14 | 14 |
|
15 | | -Generate Fern-compatible markdown documentation: |
| 15 | +Generate Fern markdown documentation: |
16 | 16 |
|
17 | 17 | ```bash |
18 | | -autodoc2 --renderer fern /path/to/your/package |
| 18 | +py2fern write /path/to/your/package |
| 19 | +``` |
| 20 | + |
| 21 | +Specify output directory: |
| 22 | + |
| 23 | +```bash |
| 24 | +py2fern write /path/to/your/package --output ./docs/api |
19 | 25 | ``` |
20 | 26 |
|
21 | 27 | This creates: |
22 | | -- Markdown files with Fern-compatible frontmatter and slugs |
23 | | -- `navigation.yml` for Fern docs structure |
24 | | -- Tables with proper linking and descriptions |
| 28 | +- **MDX files** with Fern-compatible frontmatter and slugs |
| 29 | +- **`navigation.yml`** for Fern docs structure |
25 | 30 |
|
26 | 31 | ## Acknowledgments |
27 | 32 |
|
28 | 33 | This project is a fork of the excellent [`sphinx-autodoc2`](https://github.com/sphinx-extensions2/sphinx-autodoc2) by Chris Sewell. All credit for the core functionality goes to the original project. |
29 | 34 |
|
30 | | -## Design and comparison to sphinx-autoapi |
31 | | - |
32 | | -The original sphinx-autodoc2 was created with the following goals: |
33 | | - |
34 | | -- Static analysis of Python code, so things like `if TYPE_CHECKING` were handled correctly |
35 | | -- Support for MyST docstrings (see <https://github.com/executablebooks/MyST-Parser/issues/228>) |
36 | | - - Also support for transitioning from `rst` to `md`, i.e. mixing docstrings |
37 | | -- Make it simple and minimise the amount of configuration and rebuilds necessary |
38 | | -- Support for building public API via `__all__` variable |
39 | | - |
40 | | -I am not looking to support other languages tha Python (at least for now). |
41 | | - |
42 | | -[sphinx-autoapi](https://github.com/readthedocs/sphinx-autoapi) was a good candidate, but it had a few issues: |
43 | | - |
44 | | -- It does not support MyST docstrings: <https://github.com/readthedocs/sphinx-autoapi/issues/287> |
45 | | -- It does not support the `__all__` very well: <https://github.com/readthedocs/sphinx-autoapi/issues/358> |
46 | | -- The analysis and rendering are coupled, making it difficult to test, modify and use outside of Sphinx |
47 | | - |
48 | | -I've use a lot of their code, for the `astroid` static analysis, but I've made a number of "improvements": |
49 | | - |
50 | | -- separating concerns: analysis and template writing |
51 | | -- type annotations for code base |
52 | | -- fixed `a | b` annotations inference |
53 | | -- added analysis of `functools.singledispatch` and their registers |
54 | | -- handling of `__all__` |
55 | | -- docstrings (and summaries) are now parsed with the correct source/line, i.e. warnings point to the correct location in the source file |
56 | | -- added `:canonical:` to `py` directives |
57 | | -- Moved away from using jinja templates, to using python functions |
58 | | - - IMO the templates were too complex and hard to read, |
59 | | - plus they do not benefit from any form of type checking, linting, etc. |
60 | | - - uses `list-table`, instead of `auto-summary` directive |
61 | | - |
62 | 35 | ## Development |
63 | 36 |
|
64 | 37 | All configuration is mainly in `pyproject.toml`. |
|
0 commit comments