sphinx-examples-as-code 0.1.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.
Files changed (24) hide show
  1. sphinx_examples_as_code-0.1.0/.github/dependabot.yml +16 -0
  2. sphinx_examples_as_code-0.1.0/.github/release.yml +9 -0
  3. sphinx_examples_as_code-0.1.0/.github/workflows/ci.yml +89 -0
  4. sphinx_examples_as_code-0.1.0/.gitignore +6 -0
  5. sphinx_examples_as_code-0.1.0/.pre-commit-config.yaml +38 -0
  6. sphinx_examples_as_code-0.1.0/PKG-INFO +106 -0
  7. sphinx_examples_as_code-0.1.0/README.md +81 -0
  8. sphinx_examples_as_code-0.1.0/pyproject.toml +107 -0
  9. sphinx_examples_as_code-0.1.0/setup.cfg +4 -0
  10. sphinx_examples_as_code-0.1.0/sphinx_examples_as_code/__init__.py +711 -0
  11. sphinx_examples_as_code-0.1.0/sphinx_examples_as_code/_version.py +24 -0
  12. sphinx_examples_as_code-0.1.0/sphinx_examples_as_code.egg-info/PKG-INFO +106 -0
  13. sphinx_examples_as_code-0.1.0/sphinx_examples_as_code.egg-info/SOURCES.txt +22 -0
  14. sphinx_examples_as_code-0.1.0/sphinx_examples_as_code.egg-info/dependency_links.txt +1 -0
  15. sphinx_examples_as_code-0.1.0/sphinx_examples_as_code.egg-info/requires.txt +1 -0
  16. sphinx_examples_as_code-0.1.0/sphinx_examples_as_code.egg-info/scm_file_list.json +18 -0
  17. sphinx_examples_as_code-0.1.0/sphinx_examples_as_code.egg-info/scm_version.json +8 -0
  18. sphinx_examples_as_code-0.1.0/sphinx_examples_as_code.egg-info/top_level.txt +1 -0
  19. sphinx_examples_as_code-0.1.0/tests/test_sphinx_examples_as_code.py +1058 -0
  20. sphinx_examples_as_code-0.1.0/tests/test_tinypages.py +559 -0
  21. sphinx_examples_as_code-0.1.0/tests/tinypages/conf.py +55 -0
  22. sphinx_examples_as_code-0.1.0/tests/tinypages/docstring_cases.py +405 -0
  23. sphinx_examples_as_code-0.1.0/tests/tinypages/docstring_cases.rst +65 -0
  24. sphinx_examples_as_code-0.1.0/tests/tinypages/index.rst +7 -0
@@ -0,0 +1,16 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: pip
4
+ directory: /
5
+ schedule:
6
+ interval: weekly
7
+ labels: [maintenance, dependencies]
8
+ open-pull-requests-limit: 20
9
+ - package-ecosystem: github-actions
10
+ directory: /.github/workflows
11
+ schedule:
12
+ interval: weekly
13
+ labels: [maintenance, dependencies]
14
+ groups:
15
+ artifacts:
16
+ patterns: [actions/upload-artifact, actions/download-artifact]
@@ -0,0 +1,9 @@
1
+ changelog:
2
+ exclude:
3
+ authors:
4
+ - dependabot
5
+ - dependabot[bot]
6
+ - pre-commit-ci
7
+ - pre-commit-ci[bot]
8
+ - github-actions
9
+ - github-actions[bot]
@@ -0,0 +1,89 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ tags: [v*]
7
+ pull_request:
8
+ branches: [main]
9
+
10
+ concurrency:
11
+ group: ${{ github.workflow }}-${{ github.ref }}
12
+ cancel-in-progress: true
13
+
14
+ permissions:
15
+ contents: read
16
+
17
+ jobs:
18
+ pre-commit:
19
+ runs-on: ubuntu-latest
20
+ steps:
21
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
22
+ with:
23
+ persist-credentials: false
24
+ fetch-depth: 0
25
+ - uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
26
+ with:
27
+ enable-cache: false
28
+ - run: uv sync --group dev
29
+ - run: uv run pre-commit run --all-files --show-diff-on-failure
30
+ env:
31
+ # This hook exists to stop *local* commits straight to main; it
32
+ # would always fail here since CI checks out that branch/tag directly.
33
+ SKIP: no-commit-to-branch
34
+
35
+ test:
36
+ runs-on: ubuntu-latest
37
+ strategy:
38
+ fail-fast: false
39
+ matrix:
40
+ python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
41
+ steps:
42
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
43
+ with:
44
+ persist-credentials: false
45
+ fetch-depth: 0
46
+ - uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
47
+ with:
48
+ enable-cache: false
49
+ - uses: pyvista/setup-headless-display-action@5bc8de3bc71fcda7a96439571287a554901541a0 # v4.3
50
+ with:
51
+ pyvista: true
52
+ - run: uv sync --group dev --python ${{ matrix.python-version }}
53
+ - run: uv run pytest tests/ --cov --cov-report=xml
54
+ - uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
55
+ with:
56
+ files: ./coverage.xml
57
+ env:
58
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
59
+
60
+ build:
61
+ needs: [pre-commit, test]
62
+ runs-on: ubuntu-latest
63
+ steps:
64
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
65
+ with:
66
+ persist-credentials: false
67
+ fetch-depth: 0
68
+ - uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
69
+ with:
70
+ enable-cache: false
71
+ - run: uv build
72
+ - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
73
+ with:
74
+ name: dist
75
+ path: dist/
76
+
77
+ publish:
78
+ needs: build
79
+ if: startsWith(github.ref, 'refs/tags/v')
80
+ runs-on: ubuntu-latest
81
+ environment: release
82
+ permissions:
83
+ id-token: write
84
+ steps:
85
+ - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
86
+ with:
87
+ name: dist
88
+ path: dist/
89
+ - uses: pypa/gh-action-pypi-publish@ba38be9e461d3875417946c167d0b5f3d385a247 # release/v1
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ .coverage
3
+ .idea/
4
+ *.egg-info/
5
+ __pycache__/
6
+ sphinx_examples_as_code/_version.py
@@ -0,0 +1,38 @@
1
+ ci:
2
+ autoupdate_commit_msg: 'chore: update pre-commit hooks'
3
+ autofix_prs: true
4
+ autoupdate_schedule: quarterly
5
+
6
+ repos:
7
+ - repo: https://github.com/pre-commit/pre-commit-hooks
8
+ rev: v5.0.0
9
+ hooks:
10
+ - id: check-merge-conflict
11
+ - id: debug-statements
12
+ - id: no-commit-to-branch
13
+ args: [--branch, main]
14
+
15
+ - repo: https://github.com/astral-sh/ruff-pre-commit
16
+ rev: v0.16.0
17
+ hooks:
18
+ - id: ruff-check
19
+ args: [--fix, --show-fixes]
20
+ - id: ruff-format
21
+
22
+ - repo: https://github.com/zizmorcore/zizmor-pre-commit
23
+ rev: v1.11.0
24
+ hooks:
25
+ - id: zizmor
26
+
27
+ - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
28
+ rev: v2.15.0
29
+ hooks:
30
+ - id: pretty-format-yaml
31
+ args: [--autofix, --indent, '2']
32
+
33
+ - repo: https://github.com/ComPWA/taplo-pre-commit
34
+ rev: v0.9.3
35
+ hooks:
36
+ - id: taplo-format
37
+ # See options: https://taplo.tamasfe.dev/configuration/formatter-options.html
38
+ args: [--option, reorder_arrays=true, --option, reorder_keys=true, --option, align_comments=false]
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.4
2
+ Name: sphinx-examples-as-code
3
+ Version: 0.1.0
4
+ Summary: Sphinx extension for converting docstring examples into downloadable code.
5
+ Author-email: The PyVista Developers <info@pyvista.org>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/pyvista/sphinx-examples-as-code
8
+ Keywords: download,examples,sphinx
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Framework :: Sphinx :: Extension
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Operating System :: MacOS
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Scientific/Engineering :: Visualization
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ Requires-Dist: pyvista>=0.48
25
+
26
+ # sphinx-examples-as-code
27
+
28
+ A Sphinx extension that turns docstring/page "Examples" sections into downloadable,
29
+ runnable `.py` and/or `.ipynb` files, with a download link inserted into the section.
30
+
31
+ Pages or docstrings without an Examples section are left completely untouched. Adding
32
+ `sphinx_examples_as_code` to `conf.py`'s `extensions` is the only on/off switch.
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ pip install sphinx-examples-as-code
38
+ ```
39
+
40
+ Add it to your Sphinx `conf.py`:
41
+
42
+ ```python
43
+ extensions = [
44
+ ...,
45
+ 'sphinx_examples_as_code',
46
+ ]
47
+ ```
48
+
49
+ ## Configuration
50
+
51
+ Set these in `conf.py`:
52
+
53
+ - `sphinx_examples_as_code_link_position`: where the download link(s) land within the
54
+ Examples section. `'top'` (default) or `'bottom'`.
55
+ - `sphinx_examples_as_code_formats`: which downloads to generate. A list containing
56
+ `'py'`, `'ipynb'`, or both (default). Always offered in that order regardless of how
57
+ the list is written.
58
+ - `sphinx_examples_as_code_base_url`: the site's published base URL (e.g.
59
+ `'https://docs.pyvista.org/'`), used to turn cross-references into absolute links a
60
+ downloaded, standalone file can actually use. `None` (default) means no links are
61
+ generated anywhere. A missing trailing slash is added automatically; a value with no
62
+ scheme or host raises a configuration error at build start.
63
+
64
+ ## Conversion rules
65
+
66
+ What happens to the content of an Examples section:
67
+
68
+ - Doctest blocks (`>>> ...` / `... ...`) keep their input lines, prompts stripped, as
69
+ real Python source. Doctest *output* lines are dropped — only the input code matters.
70
+ - `.. code-block:: python` (or `py`) blocks are kept as-is; other languages become
71
+ comments.
72
+ - Admonitions (`.. note::`, `.. warning::`, `.. seealso::`, ...) become a `# LABEL:`
73
+ comment followed by their content as comments. "See Also" is recognized in any of its
74
+ three forms (`.. seealso::`, a bare `.. rubric:: See Also`, or a hand-written `See
75
+ Also` heading) and always renders the same way.
76
+ - Cross-references and inline code (`:class:`, `:meth:`, `:func:`, `:attr:`,
77
+ double-backtick literals, ...) keep their display text, wrapped in backticks (e.g.
78
+ `:class:\`pyvista.Plotter\`` -> `` `pyvista.Plotter` ``). If `..._base_url` is set and
79
+ the reference resolves: `.ipynb` turns it into a clickable link everywhere; `.py` only
80
+ writes the link inside a "See Also" part (as `name url` on its own line) — everywhere
81
+ else in `.py` the link is simply omitted.
82
+ - Plain prose-style references (`:ref:`, `:doc:`) are treated the same way, minus the
83
+ backticks.
84
+ - Everything else text-bearing (prose, captions, other non-Python code) becomes a plain
85
+ `#` comment.
86
+ - Figures/images, raw HTML, and sphinx-design dropdowns/tab-sets are dropped entirely.
87
+
88
+ Generated `.py` files start with a `# Examples from <qualified name>` title header and
89
+ follow a few whitespace conventions so the result reads like normal Python: prose
90
+ directly above a code block stays attached to it, a code block is always followed by a
91
+ blank line, and a directive (header, `# NOTE:`-style block) gets blank lines on both
92
+ sides.
93
+
94
+ Generated `.ipynb` notebooks use the same content, split into alternating code/markdown
95
+ cells instead.
96
+
97
+ A download link is only added if the resulting code contains at least one real
98
+ executable statement.
99
+
100
+ ## Development
101
+
102
+ ```bash
103
+ uv sync --group dev
104
+ uv run pytest
105
+ uv run pre-commit run --all-files
106
+ ```
@@ -0,0 +1,81 @@
1
+ # sphinx-examples-as-code
2
+
3
+ A Sphinx extension that turns docstring/page "Examples" sections into downloadable,
4
+ runnable `.py` and/or `.ipynb` files, with a download link inserted into the section.
5
+
6
+ Pages or docstrings without an Examples section are left completely untouched. Adding
7
+ `sphinx_examples_as_code` to `conf.py`'s `extensions` is the only on/off switch.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pip install sphinx-examples-as-code
13
+ ```
14
+
15
+ Add it to your Sphinx `conf.py`:
16
+
17
+ ```python
18
+ extensions = [
19
+ ...,
20
+ 'sphinx_examples_as_code',
21
+ ]
22
+ ```
23
+
24
+ ## Configuration
25
+
26
+ Set these in `conf.py`:
27
+
28
+ - `sphinx_examples_as_code_link_position`: where the download link(s) land within the
29
+ Examples section. `'top'` (default) or `'bottom'`.
30
+ - `sphinx_examples_as_code_formats`: which downloads to generate. A list containing
31
+ `'py'`, `'ipynb'`, or both (default). Always offered in that order regardless of how
32
+ the list is written.
33
+ - `sphinx_examples_as_code_base_url`: the site's published base URL (e.g.
34
+ `'https://docs.pyvista.org/'`), used to turn cross-references into absolute links a
35
+ downloaded, standalone file can actually use. `None` (default) means no links are
36
+ generated anywhere. A missing trailing slash is added automatically; a value with no
37
+ scheme or host raises a configuration error at build start.
38
+
39
+ ## Conversion rules
40
+
41
+ What happens to the content of an Examples section:
42
+
43
+ - Doctest blocks (`>>> ...` / `... ...`) keep their input lines, prompts stripped, as
44
+ real Python source. Doctest *output* lines are dropped — only the input code matters.
45
+ - `.. code-block:: python` (or `py`) blocks are kept as-is; other languages become
46
+ comments.
47
+ - Admonitions (`.. note::`, `.. warning::`, `.. seealso::`, ...) become a `# LABEL:`
48
+ comment followed by their content as comments. "See Also" is recognized in any of its
49
+ three forms (`.. seealso::`, a bare `.. rubric:: See Also`, or a hand-written `See
50
+ Also` heading) and always renders the same way.
51
+ - Cross-references and inline code (`:class:`, `:meth:`, `:func:`, `:attr:`,
52
+ double-backtick literals, ...) keep their display text, wrapped in backticks (e.g.
53
+ `:class:\`pyvista.Plotter\`` -> `` `pyvista.Plotter` ``). If `..._base_url` is set and
54
+ the reference resolves: `.ipynb` turns it into a clickable link everywhere; `.py` only
55
+ writes the link inside a "See Also" part (as `name url` on its own line) — everywhere
56
+ else in `.py` the link is simply omitted.
57
+ - Plain prose-style references (`:ref:`, `:doc:`) are treated the same way, minus the
58
+ backticks.
59
+ - Everything else text-bearing (prose, captions, other non-Python code) becomes a plain
60
+ `#` comment.
61
+ - Figures/images, raw HTML, and sphinx-design dropdowns/tab-sets are dropped entirely.
62
+
63
+ Generated `.py` files start with a `# Examples from <qualified name>` title header and
64
+ follow a few whitespace conventions so the result reads like normal Python: prose
65
+ directly above a code block stays attached to it, a code block is always followed by a
66
+ blank line, and a directive (header, `# NOTE:`-style block) gets blank lines on both
67
+ sides.
68
+
69
+ Generated `.ipynb` notebooks use the same content, split into alternating code/markdown
70
+ cells instead.
71
+
72
+ A download link is only added if the resulting code contains at least one real
73
+ executable statement.
74
+
75
+ ## Development
76
+
77
+ ```bash
78
+ uv sync --group dev
79
+ uv run pytest
80
+ uv run pre-commit run --all-files
81
+ ```
@@ -0,0 +1,107 @@
1
+ [build-system]
2
+ build-backend = 'setuptools.build_meta'
3
+ requires = ['setuptools>=64', 'setuptools_scm>=8']
4
+
5
+ [dependency-groups]
6
+ dev = [
7
+ 'nbformat',
8
+ 'numpydoc',
9
+ 'pre-commit',
10
+ 'pytest',
11
+ 'pytest-cov',
12
+ 'sphinx',
13
+ 'sphinx-design',
14
+ 'trame-pyvista',
15
+ ]
16
+
17
+ [project]
18
+ authors = [{ name = 'The PyVista Developers', email = 'info@pyvista.org' }]
19
+ classifiers = [
20
+ 'Development Status :: 4 - Beta',
21
+ 'Framework :: Sphinx :: Extension',
22
+ 'Intended Audience :: Science/Research',
23
+ 'Operating System :: MacOS',
24
+ 'Operating System :: Microsoft :: Windows',
25
+ 'Operating System :: POSIX :: Linux',
26
+ 'Programming Language :: Python :: 3',
27
+ 'Programming Language :: Python :: 3.10',
28
+ 'Programming Language :: Python :: 3.11',
29
+ 'Programming Language :: Python :: 3.12',
30
+ 'Programming Language :: Python :: 3.13',
31
+ 'Programming Language :: Python :: 3.14',
32
+ 'Topic :: Scientific/Engineering :: Visualization',
33
+ ]
34
+ dependencies = ['pyvista>=0.48']
35
+ description = 'Sphinx extension for converting docstring examples into downloadable code.'
36
+ dynamic = ['version']
37
+ keywords = ['download', 'examples', 'sphinx']
38
+ license = 'MIT'
39
+ name = 'sphinx-examples-as-code'
40
+ readme = 'README.md'
41
+ requires-python = '>=3.10'
42
+
43
+ [project.urls]
44
+ Homepage = 'https://github.com/pyvista/sphinx-examples-as-code'
45
+
46
+ [tool.coverage.run]
47
+ branch = true
48
+ omit = ['*/_version.py']
49
+ parallel = true
50
+ source = ['sphinx_examples_as_code']
51
+
52
+ [tool.pytest.ini_options]
53
+ addopts = '--cov=sphinx_examples_as_code --cov-fail-under=95'
54
+ testpaths = 'tests'
55
+
56
+ [tool.ruff]
57
+ line-length = 100
58
+
59
+ [tool.ruff.format]
60
+ quote-style = 'single'
61
+
62
+ [tool.ruff.lint]
63
+ extend-select = [
64
+ 'A',
65
+ 'B',
66
+ 'C4',
67
+ 'D',
68
+ 'E',
69
+ 'EM',
70
+ 'F',
71
+ 'FA',
72
+ 'I',
73
+ 'ICN',
74
+ 'N',
75
+ 'PERF',
76
+ 'PGH',
77
+ 'PIE',
78
+ 'PT',
79
+ 'RET',
80
+ 'RSE',
81
+ 'RUF',
82
+ 'SIM',
83
+ 'T10',
84
+ 'T20',
85
+ 'TCH',
86
+ 'TID',
87
+ 'UP',
88
+ 'W',
89
+ 'YTT',
90
+ ]
91
+ ignore = ['D203', 'D211', 'D213']
92
+ [tool.ruff.lint.per-file-ignores]
93
+ '*/conf.py' = ['E402']
94
+ 'tests/*' = ['D103']
95
+
96
+ [tool.ruff.lint.isort]
97
+ combine-as-imports = true
98
+ force-single-line = true
99
+ force-sort-within-sections = true
100
+ required-imports = ['from __future__ import annotations']
101
+
102
+ [tool.setuptools]
103
+ packages = ['sphinx_examples_as_code']
104
+
105
+ [tool.setuptools_scm]
106
+ version_scheme = 'release-branch-semver'
107
+ write_to = 'sphinx_examples_as_code/_version.py'
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+