cython-sphinx-plugin 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cython_sphinx_plugin-1.0.0/LICENSE +24 -0
- cython_sphinx_plugin-1.0.0/MANIFEST.in +4 -0
- cython_sphinx_plugin-1.0.0/PKG-INFO +24 -0
- cython_sphinx_plugin-1.0.0/README.md +53 -0
- cython_sphinx_plugin-1.0.0/docs/conf.py +23 -0
- cython_sphinx_plugin-1.0.0/docs/configuration.md +72 -0
- cython_sphinx_plugin-1.0.0/docs/diagnostics.md +42 -0
- cython_sphinx_plugin-1.0.0/docs/getting-started.md +73 -0
- cython_sphinx_plugin-1.0.0/docs/index.md +12 -0
- cython_sphinx_plugin-1.0.0/docs/testing.md +91 -0
- cython_sphinx_plugin-1.0.0/docs/using-autocython.md +91 -0
- cython_sphinx_plugin-1.0.0/pyproject.toml +47 -0
- cython_sphinx_plugin-1.0.0/setup.cfg +4 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin/__init__.py +6 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin/_metadata.py +27 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin/cython_core/__init__.py +19 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin/cython_core/model.py +62 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin/cython_core/parser.py +811 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin/services/cython_documentation_service.py +135 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin/services/source_resolver.py +220 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin/sphinx/config.py +91 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin/sphinx/directives.py +268 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin/sphinx/domains.py +411 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin/sphinx/setup.py +27 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin.egg-info/PKG-INFO +24 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin.egg-info/SOURCES.txt +37 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin.egg-info/dependency_links.txt +1 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin.egg-info/requires.txt +12 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin.egg-info/scm_file_list.json +41 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin.egg-info/scm_version.json +8 -0
- cython_sphinx_plugin-1.0.0/src/cython_sphinx_plugin.egg-info/top_level.txt +1 -0
- cython_sphinx_plugin-1.0.0/tests/conftest.py +114 -0
- cython_sphinx_plugin-1.0.0/tests/support.py +71 -0
- cython_sphinx_plugin-1.0.0/tests/test_metadata.py +55 -0
- cython_sphinx_plugin-1.0.0/tests/test_package_build.py +82 -0
- cython_sphinx_plugin-1.0.0/tests/test_parser.py +275 -0
- cython_sphinx_plugin-1.0.0/tests/test_publish_workflow.py +189 -0
- cython_sphinx_plugin-1.0.0/tests/test_source_resolver.py +77 -0
- cython_sphinx_plugin-1.0.0/tests/test_sphinx_integration.py +475 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Copyright (c) 2026, Mikhail Terekhov
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
15
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
16
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
17
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
18
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
19
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
20
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
21
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
22
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
23
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
24
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cython-sphinx-plugin
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Sphinx documentation support for Cython declarations
|
|
5
|
+
Author-email: Mikhail Terekhov <termim@gmail.com>
|
|
6
|
+
Maintainer-email: Mikhail Terekhov <termim@gmail.com>
|
|
7
|
+
License-Expression: BSD-2-Clause
|
|
8
|
+
Project-URL: homepage, https://github.com/termim/cython-sphinx
|
|
9
|
+
Project-URL: repository, https://github.com/termim/cython-sphinx
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/termim/cython-sphinx/issues
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: Cython>3.0
|
|
14
|
+
Requires-Dist: Sphinx>=9.0.4
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
17
|
+
Requires-Dist: myst-parser>=4; extra == "dev"
|
|
18
|
+
Requires-Dist: packaging>=24; extra == "dev"
|
|
19
|
+
Requires-Dist: pytest>=8.3; extra == "dev"
|
|
20
|
+
Requires-Dist: PyYAML>=6; extra == "dev"
|
|
21
|
+
Requires-Dist: setuptools>=77; extra == "dev"
|
|
22
|
+
Requires-Dist: setuptools-scm>=8; extra == "dev"
|
|
23
|
+
Requires-Dist: wheel; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Cython Sphinx Plugin
|
|
2
|
+
|
|
3
|
+
> Document Cython declarations in Sphinx without importing them for discovery.
|
|
4
|
+
|
|
5
|
+
The extension reads Cython source through Cython's compiler parser and exposes
|
|
6
|
+
declarations through an `autocython` directive and the `cython` cross-reference domain.
|
|
7
|
+
Keep Sphinx autodoc for importable Python APIs and use this extension for declarations
|
|
8
|
+
that runtime introspection cannot show.
|
|
9
|
+
|
|
10
|
+
## Quick Start
|
|
11
|
+
|
|
12
|
+
Requires Python 3.11 or later. From a project checkout, install the extension:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
python -m pip install .
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Enable the extension in `conf.py` and configure the directory containing your Cython
|
|
19
|
+
modules; see [Getting Started](docs/getting-started.md) for a complete configuration
|
|
20
|
+
example.
|
|
21
|
+
|
|
22
|
+
Then add a directive to an `.rst` page:
|
|
23
|
+
|
|
24
|
+
```rst
|
|
25
|
+
.. autocython:: demo
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
For example, `../src/demo.pxd` can declare `cpdef int add(int left, int right)`. The
|
|
29
|
+
extension documents that declaration without importing `demo`.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- Uses `.pxd` declarations as the API when matching `.pyx` implementations exist.
|
|
34
|
+
- Documents Cython functions, extension types, fields, and Python functions/classes
|
|
35
|
+
declared in `.pyx` sources with stable cross-references.
|
|
36
|
+
- Supports shortened declaration display names while retaining fully qualified
|
|
37
|
+
cross-reference targets.
|
|
38
|
+
- Filters underscore-prefixed and `extern` declarations by default; opt in per directive.
|
|
39
|
+
- Tracks parsed sources and cimported `.pxd` files for incremental Sphinx rebuilds.
|
|
40
|
+
|
|
41
|
+
## Documentation
|
|
42
|
+
|
|
43
|
+
| Guide | Description |
|
|
44
|
+
| -------------------------------------------- | ------------------------------------------------------- |
|
|
45
|
+
| [Getting Started](docs/getting-started.md) | Install and configure a first Sphinx project |
|
|
46
|
+
| [Configuration](docs/configuration.md) | Source paths and signature display |
|
|
47
|
+
| [Using autocython](docs/using-autocython.md) | Declarations, display, and autodoc |
|
|
48
|
+
| [Diagnostics](docs/diagnostics.md) | Parser messages, cross-references, and rebuilds |
|
|
49
|
+
| [Testing](docs/testing.md) | Run tests, build packages, CI, versioning, and releases |
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
This project is licensed under the BSD 2-Clause License. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
project_root = Path(__file__).resolve().parent.parent
|
|
6
|
+
sys.path.insert(0, str(project_root / "src"))
|
|
7
|
+
|
|
8
|
+
import cython_sphinx_plugin # noqa: E402 (needs src on sys.path)
|
|
9
|
+
|
|
10
|
+
release = cython_sphinx_plugin.__version__
|
|
11
|
+
version = ".".join(release.split(".")[:2])
|
|
12
|
+
|
|
13
|
+
project = "Cython Sphinx Plugin"
|
|
14
|
+
root_doc = "index"
|
|
15
|
+
extensions = ["myst_parser", "cython_sphinx_plugin"]
|
|
16
|
+
source_suffix = {
|
|
17
|
+
".rst": "restructuredtext",
|
|
18
|
+
".md": "markdown",
|
|
19
|
+
}
|
|
20
|
+
suppress_warnings = ["myst.xref_missing"]
|
|
21
|
+
cython_source_roots = [str(project_root / "src")]
|
|
22
|
+
cython_include_dirs = [str(project_root / "include")]
|
|
23
|
+
html_theme = "alabaster"
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
[← Previous Page](getting-started.md) · [Back to README](../README.md) · [Next Page →](using-autocython.md)
|
|
2
|
+
|
|
3
|
+
# Configuration
|
|
4
|
+
|
|
5
|
+
Configure these values in Sphinx's `conf.py`. Both settings accept a list or
|
|
6
|
+
tuple of existing directory paths; relative paths are resolved from the
|
|
7
|
+
configuration directory. The signature display setting accepts one of two
|
|
8
|
+
string values.
|
|
9
|
+
|
|
10
|
+
| Setting | Default | Purpose |
|
|
11
|
+
|---------|---------|---------|
|
|
12
|
+
| `cython_source_roots` | Sphinx source directory | Find modules named by `autocython` |
|
|
13
|
+
| `cython_include_dirs` | Empty | Resolve Cython `cimport` dependencies |
|
|
14
|
+
| `cython_signature_style` | `qualified` | Display qualified or shortened declaration names |
|
|
15
|
+
|
|
16
|
+
If `cython_source_roots` is omitted or empty, the Sphinx source directory is
|
|
17
|
+
searched. Invalid paths are reported as configuration errors rather than being
|
|
18
|
+
silently ignored.
|
|
19
|
+
|
|
20
|
+
## Module Lookup
|
|
21
|
+
|
|
22
|
+
For a qualified module name such as `package.geometry`, each source root is
|
|
23
|
+
searched for:
|
|
24
|
+
|
|
25
|
+
```text
|
|
26
|
+
package/geometry.pxd
|
|
27
|
+
package/geometry.pyx
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
If more than one configured root contains the module, resolution reports an
|
|
31
|
+
ambiguity instead of choosing one silently.
|
|
32
|
+
|
|
33
|
+
When both files exist, the `.pxd` defines the documented API. Matching
|
|
34
|
+
declarations in the `.pyx` provide implementation docstrings and source
|
|
35
|
+
locations. If only one file exists, that file is used. Imported modules are
|
|
36
|
+
dependencies, not additional modules to document.
|
|
37
|
+
|
|
38
|
+
## Cython Includes
|
|
39
|
+
|
|
40
|
+
Set `cython_include_dirs` to directories containing `.pxd` files imported by
|
|
41
|
+
your sources. The selected module's source root is also available to Cython's
|
|
42
|
+
parser. For example:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
cython_source_roots = ["../src"]
|
|
46
|
+
cython_include_dirs = ["../cython-include"]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
A missing cimport is reported with a source location. Declarations that remain
|
|
50
|
+
documentable are retained; imported declarations are not rendered recursively.
|
|
51
|
+
|
|
52
|
+
## Signature Display
|
|
53
|
+
|
|
54
|
+
Set `cython_signature_style` to `"short"` to omit the module path from displayed
|
|
55
|
+
declaration names. Module-level declarations show their own names; members show
|
|
56
|
+
their class and member names, such as `Connection.close`. The default,
|
|
57
|
+
`"qualified"`, displays the full name.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
cython_signature_style = "short"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The `:signature-style:` option on an `autocython` directive can override this
|
|
64
|
+
setting for one module. Both styles keep fully qualified names as the internal
|
|
65
|
+
targets, so cross-references continue to use names such as
|
|
66
|
+
`package.geometry.Point.distance`.
|
|
67
|
+
|
|
68
|
+
## See Also
|
|
69
|
+
|
|
70
|
+
- [Getting Started](getting-started.md) — installation and initial Sphinx setup
|
|
71
|
+
- [Using autocython](using-autocython.md) — declaration and display options
|
|
72
|
+
- [Diagnostics](diagnostics.md) — parser messages and dependency rebuilds
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[← Previous Page](using-autocython.md) · [Back to README](../README.md) ·
|
|
2
|
+
[Next Page →](testing.md)
|
|
3
|
+
|
|
4
|
+
# Diagnostics and Rebuilds
|
|
5
|
+
|
|
6
|
+
The extension reports parser and reference problems through Sphinx. Source diagnostics
|
|
7
|
+
include the relevant file and line when Cython provides them.
|
|
8
|
+
|
|
9
|
+
| Condition | Result |
|
|
10
|
+
| ----------------------------------------------------------- | -------------------------------------------------------- |
|
|
11
|
+
| Invalid `cython_source_roots` / `cython_include_dirs` entry | Error at `conf.py`; the entry is ignored |
|
|
12
|
+
| Invalid `cython_signature_style` value | Error at `conf.py`; the directive emits nothing |
|
|
13
|
+
| Invalid `:members:` or `:signature-style:` directive option | Directive error from Sphinx; the directive emits nothing |
|
|
14
|
+
| Invalid module name, or module not found in any source root | Error at the directive |
|
|
15
|
+
| Module found in more than one source root | Error at the directive (ambiguous module) |
|
|
16
|
+
| Missing cimported `.pxd` | Warning; unaffected declarations can still be documented |
|
|
17
|
+
| Source read or fatal parser failure | Error; the source and diagnostic are reported |
|
|
18
|
+
| Cython compiler note | Informational message with the source location |
|
|
19
|
+
| `:members:` name that matches no eligible declaration | Warning at the directive |
|
|
20
|
+
| No eligible declarations in the module | Warning at the directive |
|
|
21
|
+
| Malformed declaration signature | Warning; no target is registered for that declaration |
|
|
22
|
+
| Duplicate Cython target | Warning identifying the duplicate target |
|
|
23
|
+
| Unresolved or ambiguous Cython reference | Warning at the reference |
|
|
24
|
+
|
|
25
|
+
Warnings fail the build when Sphinx is run with `-W`; see
|
|
26
|
+
[Getting Started](getting-started.md) for the build command.
|
|
27
|
+
|
|
28
|
+
Use the warning text and its location to correct the source, directive, or
|
|
29
|
+
cross-reference. The parser and service retain Cython's raw diagnostic text for
|
|
30
|
+
troubleshooting; Sphinx reports normalized, source-located messages.
|
|
31
|
+
|
|
32
|
+
## Incremental Rebuilds
|
|
33
|
+
|
|
34
|
+
The directive registers the selected `.pxd` and `.pyx` files, along with resolved
|
|
35
|
+
cimported `.pxd` dependencies, with Sphinx. Editing one of these files marks the page for
|
|
36
|
+
a rebuild; no manual cache clearing is required for a normal incremental build.
|
|
37
|
+
|
|
38
|
+
## See Also
|
|
39
|
+
|
|
40
|
+
- [Configuration](configuration.md) — configure source and include paths
|
|
41
|
+
- [Using autocython](using-autocython.md) — declaration kinds and cross-references
|
|
42
|
+
- [Testing](testing.md) — build the integration fixtures and package
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
[Back to README](../README.md) · [Next Page →](configuration.md)
|
|
2
|
+
|
|
3
|
+
# Getting Started
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
The package declares these minimum runtime versions:
|
|
8
|
+
|
|
9
|
+
| Component | Minimum |
|
|
10
|
+
|-----------|---------|
|
|
11
|
+
| Python | 3.11 |
|
|
12
|
+
| Cython | >3.0 |
|
|
13
|
+
| Sphinx | 9.0.4 |
|
|
14
|
+
|
|
15
|
+
The implementation uses Cython compiler internals. It has been validated with
|
|
16
|
+
Cython 3.3.2 and Sphinx 9.0.4 on Python 3.11, and with Cython 3.3.2 and
|
|
17
|
+
Sphinx 9.1.1 on Python 3.12. Other versions are constrained by the declared
|
|
18
|
+
dependencies, not by a broader compatibility guarantee.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
Install from the repository root:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
python -m pip install .
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
For development, install the test and build tools as well:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
python -m pip install -e ".[dev]"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Enable the Extension
|
|
35
|
+
|
|
36
|
+
Add the extension and the source locations to your Sphinx `conf.py`:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
extensions = ["sphinx.ext.autodoc", "cython_sphinx_plugin"]
|
|
40
|
+
cython_source_roots = ["../src"]
|
|
41
|
+
cython_include_dirs = ["../include"]
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
These relative paths are resolved from the directory containing `conf.py`.
|
|
45
|
+
See [Configuration](configuration.md) for defaults and source-selection rules.
|
|
46
|
+
|
|
47
|
+
Add an `autocython` directive to an `.rst` page:
|
|
48
|
+
|
|
49
|
+
```rst
|
|
50
|
+
.. autocython:: demo
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The module name is qualified by its path under a configured source root. For
|
|
54
|
+
example, `src/demo.pxd` or `src/demo.pyx` is documented as `demo`; a file at
|
|
55
|
+
`src/package/demo.pxd` is documented as `package.demo`.
|
|
56
|
+
|
|
57
|
+
## Build the Documentation
|
|
58
|
+
|
|
59
|
+
From your Sphinx project root, with `conf.py` and source pages under `docs/`,
|
|
60
|
+
run Sphinx with warnings treated as errors:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
python -P -m sphinx -W -b html docs docs/_build/html
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`-P` keeps the current directory off the import path, which helps avoid a local
|
|
67
|
+
top-level Sphinx checkout shadowing the installed Sphinx package.
|
|
68
|
+
|
|
69
|
+
## See Also
|
|
70
|
+
|
|
71
|
+
- [Configuration](configuration.md) — source paths and `.pxd`/`.pyx` selection
|
|
72
|
+
- [Using autocython](using-autocython.md) — directives and declaration visibility
|
|
73
|
+
- [Testing](testing.md) — test and package-build commands
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
[← Previous Page](diagnostics.md) · [Back to README](../README.md)
|
|
2
|
+
|
|
3
|
+
# Testing
|
|
4
|
+
|
|
5
|
+
Install the development dependencies from the repository root:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
python -m pip install -e ".[dev]"
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Run the unit, Sphinx integration, serial/parallel, and incremental-rebuild tests:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
.venv/bin/python -P -m pytest
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Build both package formats; the command writes distributions under `dist/`:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
.venv/bin/python -P -m build --no-isolation --wheel --sdist
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The test suite builds temporary Sphinx projects with warnings treated as errors, except
|
|
24
|
+
for a test that explicitly asserts the expected missing-cimport warning. It also compares
|
|
25
|
+
serial and two-worker builds to verify equivalent targets and cross-references while
|
|
26
|
+
exercising the extension's parallel-read support.
|
|
27
|
+
|
|
28
|
+
To collect coverage the way CI does:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
python -m pip install pytest-cov
|
|
32
|
+
.venv/bin/python -P -m pytest --cov=cython_sphinx_plugin --cov-report=term-missing
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Make Shortcuts
|
|
36
|
+
|
|
37
|
+
The root `Makefile` wraps these commands. It uses `.venv/bin/python` when that interpreter
|
|
38
|
+
exists:
|
|
39
|
+
|
|
40
|
+
| Command | Runs |
|
|
41
|
+
| ------------------------------- | -------------------------------------------- |
|
|
42
|
+
| `make install` | Editable install with dev dependencies |
|
|
43
|
+
| `make version` | Git-derived and installed package versions |
|
|
44
|
+
| `make test` / `make test-cover` | Test suite / with coverage |
|
|
45
|
+
| `make docs` | Sphinx HTML build with `-W` |
|
|
46
|
+
| `make build` | Wheel and sdist into `dist/` |
|
|
47
|
+
| `make audit` | `pip-audit` and Bandit, as in `security.yml` |
|
|
48
|
+
| `make ci` | `test`, `build`, and `docs` |
|
|
49
|
+
|
|
50
|
+
Run `make help` to list every target.
|
|
51
|
+
|
|
52
|
+
## Continuous Integration
|
|
53
|
+
|
|
54
|
+
GitHub Actions workflows live in `.github/workflows/`:
|
|
55
|
+
|
|
56
|
+
| Workflow | Trigger | What it checks |
|
|
57
|
+
| -------------- | ------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
58
|
+
| `tests.yml` | Push to `main`, pull requests | `pytest` with coverage on Python 3.11 and 3.15 |
|
|
59
|
+
| `build.yml` | Push to `main`, pull requests | Wheel and sdist build, and documentation build with `-W` |
|
|
60
|
+
| `security.yml` | Push to `main`, pull requests, weekly | `pip-audit`, Bandit scan of `src/`, dependency review |
|
|
61
|
+
| `publish.yml` | Tag `v*` | Tests, build, a check that the built version matches the tag, publish to PyPI, then create a GitHub release |
|
|
62
|
+
|
|
63
|
+
## Versioning and Releases
|
|
64
|
+
|
|
65
|
+
The package version comes from git tags through `setuptools_scm`; `pyproject.toml` has no
|
|
66
|
+
static version. At runtime, `cython_sphinx_plugin.__version__`, the Sphinx extension
|
|
67
|
+
metadata, and the documentation `release` all read the installed distribution's version.
|
|
68
|
+
|
|
69
|
+
| Checkout state | Version |
|
|
70
|
+
| ----------------------- | --------------------------------- |
|
|
71
|
+
| On tag `v1.0.0`, clean | `1.0.0` |
|
|
72
|
+
| N commits after the tag | `1.0.0.postN+g<hash>` |
|
|
73
|
+
| Uncommitted changes | adds `.d<date>` to the local part |
|
|
74
|
+
| No tags yet | `0.0.postN+g<hash>` |
|
|
75
|
+
|
|
76
|
+
To release, push a tag such as `v1.0.0` from a clean checkout of the commit to publish.
|
|
77
|
+
The publish workflow fails if the built version differs from the tag.
|
|
78
|
+
|
|
79
|
+
After the PyPI upload succeeds, the workflow creates a GitHub release for the tag. It uses
|
|
80
|
+
GitHub's generated release notes and attaches the wheel and sdist. Tags with a pre-release
|
|
81
|
+
or dev part (`a`, `b`, `rc`, `.dev`, for example `v1.1.0rc1`) are marked as pre-releases.
|
|
82
|
+
Re-running the job for an existing release re-uploads the files instead of failing.
|
|
83
|
+
|
|
84
|
+
An editable install records the version when it is installed. Run `make install` again
|
|
85
|
+
after committing or tagging to refresh it; `make version` shows both values.
|
|
86
|
+
|
|
87
|
+
## See Also
|
|
88
|
+
|
|
89
|
+
- [Getting Started](getting-started.md) — install the runtime package
|
|
90
|
+
- [Diagnostics](diagnostics.md) — interpret parser and Sphinx messages
|
|
91
|
+
- [Configuration](configuration.md) — source roots and include directories
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
[← Previous Page](configuration.md) · [Back to README](../README.md) ·
|
|
2
|
+
[Next Page →](diagnostics.md)
|
|
3
|
+
|
|
4
|
+
# Using `autocython`
|
|
5
|
+
|
|
6
|
+
## Supported Declarations
|
|
7
|
+
|
|
8
|
+
The parser-backed directive documents Cython `cdef` and `cpdef` functions, extension
|
|
9
|
+
types, and fields. It also documents module-level Python `def` functions, Python classes
|
|
10
|
+
and their methods, and Python `def` methods declared inside `cdef` classes in `.pyx`
|
|
11
|
+
sources. It runs Cython's parser and analysis stages on the source files and stops before
|
|
12
|
+
C code generation. The module is never imported, and no `.c` files are written.
|
|
13
|
+
|
|
14
|
+
```rst
|
|
15
|
+
.. autocython:: package.geometry
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
This emits all eligible declarations from the resolved source. Use `:members:` to select
|
|
19
|
+
comma-separated names; a selected extension type or Python class includes its documentable
|
|
20
|
+
members. `*` selects all declarations:
|
|
21
|
+
|
|
22
|
+
```rst
|
|
23
|
+
.. autocython:: package.geometry
|
|
24
|
+
:members: distance, Point
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Visibility
|
|
28
|
+
|
|
29
|
+
By default, underscore-prefixed names and declarations marked `extern` are excluded. The
|
|
30
|
+
two options are independent:
|
|
31
|
+
|
|
32
|
+
```rst
|
|
33
|
+
.. autocython:: package.geometry
|
|
34
|
+
:private-members:
|
|
35
|
+
:extern-members:
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Use only the option needed for a page. Enabling one does not enable the other.
|
|
39
|
+
|
|
40
|
+
## Signature Display
|
|
41
|
+
|
|
42
|
+
By default, declaration signatures display fully qualified names. Set the global
|
|
43
|
+
`cython_signature_style` configuration value to `"short"` to omit the module path.
|
|
44
|
+
Module-level declarations show their own names, while members retain their class name (for
|
|
45
|
+
example, `Connection.close`).
|
|
46
|
+
|
|
47
|
+
Override the global style for an individual directive with `:signature-style:`:
|
|
48
|
+
|
|
49
|
+
```rst
|
|
50
|
+
.. autocython:: package.geometry
|
|
51
|
+
:signature-style: short
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Use `qualified` or `short` for the global setting or directive option. Short display
|
|
55
|
+
changes only the visible label: declarations keep fully qualified targets, and
|
|
56
|
+
cross-references should continue to use names such as `package.geometry.Point.distance`.
|
|
57
|
+
|
|
58
|
+
## Cross-References
|
|
59
|
+
|
|
60
|
+
The `cython` domain provides function, Python class, extension type, and field targets.
|
|
61
|
+
Link to fully qualified names with these roles:
|
|
62
|
+
|
|
63
|
+
```rst
|
|
64
|
+
See :cython:func:`package.geometry.distance`,
|
|
65
|
+
:cython:class:`package.geometry.Shape`,
|
|
66
|
+
:cython:type:`package.geometry.Point`, and
|
|
67
|
+
:cython:field:`package.geometry.Point.x`.
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Duplicate targets and unresolved or ambiguous references produce Sphinx warnings.
|
|
71
|
+
|
|
72
|
+
## Use with Sphinx autodoc
|
|
73
|
+
|
|
74
|
+
Keep autodoc for Python objects that can be imported. Add `autocython` for the Cython
|
|
75
|
+
declaration surface; the two directives may document the same module:
|
|
76
|
+
|
|
77
|
+
```rst
|
|
78
|
+
.. automodule:: package.geometry
|
|
79
|
+
:members:
|
|
80
|
+
|
|
81
|
+
.. autocython:: package.geometry
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`automodule` documents the runtime-visible Python API. `autocython` reads the configured
|
|
85
|
+
`.pxd`/`.pyx` sources and does not replace or customize autodoc.
|
|
86
|
+
|
|
87
|
+
## See Also
|
|
88
|
+
|
|
89
|
+
- [Getting Started](getting-started.md) — install and enable the extension
|
|
90
|
+
- [Configuration](configuration.md) — source paths and signature display
|
|
91
|
+
- [Diagnostics](diagnostics.md) — warnings, errors, and incremental rebuilds
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "setuptools-scm>=8", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "cython-sphinx-plugin"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Sphinx documentation support for Cython declarations"
|
|
9
|
+
authors = [{name = "Mikhail Terekhov", email = "termim@gmail.com"}]
|
|
10
|
+
maintainers = [{name = "Mikhail Terekhov", email = "termim@gmail.com"}]
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
license = "BSD-2-Clause"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"Cython>3.0",
|
|
16
|
+
"Sphinx>=9.0.4",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
homepage = "https://github.com/termim/cython-sphinx"
|
|
21
|
+
repository = "https://github.com/termim/cython-sphinx"
|
|
22
|
+
"Bug Tracker" = "https://github.com/termim/cython-sphinx/issues"
|
|
23
|
+
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
dev = [
|
|
26
|
+
"build>=1.2",
|
|
27
|
+
"myst-parser>=4",
|
|
28
|
+
"packaging>=24",
|
|
29
|
+
"pytest>=8.3",
|
|
30
|
+
"PyYAML>=6",
|
|
31
|
+
"setuptools>=77",
|
|
32
|
+
"setuptools-scm>=8",
|
|
33
|
+
"wheel",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.packages.find]
|
|
37
|
+
where = ["src"]
|
|
38
|
+
include = ["cython_sphinx_plugin*"]
|
|
39
|
+
namespaces = true
|
|
40
|
+
|
|
41
|
+
[tool.setuptools_scm]
|
|
42
|
+
version_scheme = "post-release"
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
testpaths = ["tests"]
|
|
46
|
+
pythonpath = ["src", "tests"]
|
|
47
|
+
addopts = "-ra --import-mode=importlib"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Package metadata: the installed distribution version."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
7
|
+
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
DISTRIBUTION = "cython-sphinx-plugin"
|
|
11
|
+
UNKNOWN_VERSION = "0+unknown"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def resolve_version(distribution: str = DISTRIBUTION) -> str:
|
|
15
|
+
"""Return the installed version of ``distribution``, or ``0+unknown``."""
|
|
16
|
+
try:
|
|
17
|
+
resolved = version(distribution)
|
|
18
|
+
except PackageNotFoundError:
|
|
19
|
+
logger.debug(
|
|
20
|
+
"%s is not installed; using version %s", distribution, UNKNOWN_VERSION
|
|
21
|
+
)
|
|
22
|
+
return UNKNOWN_VERSION
|
|
23
|
+
logger.debug("Resolved %s version %s", distribution, resolved)
|
|
24
|
+
return resolved
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
__version__ = resolve_version()
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Cython compiler adapter and normalized declaration models."""
|
|
2
|
+
|
|
3
|
+
from cython_sphinx_plugin.cython_core.model import (
|
|
4
|
+
Declaration,
|
|
5
|
+
DeclarationKind,
|
|
6
|
+
ModuleParseResult,
|
|
7
|
+
ParseDiagnostic,
|
|
8
|
+
ParseStageMetadata,
|
|
9
|
+
)
|
|
10
|
+
from cython_sphinx_plugin.cython_core.parser import parse_module_sources
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"Declaration",
|
|
14
|
+
"DeclarationKind",
|
|
15
|
+
"ModuleParseResult",
|
|
16
|
+
"ParseDiagnostic",
|
|
17
|
+
"ParseStageMetadata",
|
|
18
|
+
"parse_module_sources",
|
|
19
|
+
]
|