Evaluate shell command or python code in sphinx and myst
Project description
sphinxcontrib-eval
Evaluate shell command or python code in sphinx and myst.
Usage
Enable
docs/conf.py
extensions = [
"sphinxcontrib.eval",
]
Or
extensions = [
"myst_parser",
"sphinxcontrib.eval", # must be after myst_parser
]
Demonstration
For myst:
```{eval-sh}
echo My OS is $OSTYPE
```
For rst:
.. eval-sh::
echo My OS is $OSTYPE
Then build:
sphinx-build docs docs/_build/html
Result:
My OS is linux-gnu
Advanced Usages
All the following code is myst. The corresponding rst is similar. Click the hyperlink of title to see the actual example.
Generate API Document
Before:
# API of Translate Shell
```{eval-rst}
.. automodule:: translate_shell
:members:
.. automodule:: translate_shell.__main__
:members:
... (More)
```
Now
# API of Translate Shell
````{eval-rst}
```{eval-sh}
scripts/generate-api.md.sh '' -maxdepth 1
```
````
Where scripts/generate-api.md.sh
is a script which search all python file and
replace them from src/translate_shell/X/Y/Z.py
to
.. automodule:: translate_shell.X.Y.Z`
:members:
#!/usr/bin/env bash
# shellcheck disable=SC2086
find src/sphinxcontrib/eval/$1 $2 $3 -name '*.py' |
perl -pe's=src/=.. automodule:: =g;
s=\.py$=\n :members:=g;s=/__init__==g;s=/=.=g'
Generate TODO Document
Before:
# TODO
- <https://github.com/Freed-Wu/tranlate-shell/tree/main/src/translate_shell/translators/stardict/__init__.py#L4> more stardicts.
- <https://github.com/Freed-Wu/tranlate-shell/tree/main/src/translate_shell/translators/stardict/__init__.py#L5> Create different subclasses for different dict to get phonetic, explains
- <https://github.com/Freed-Wu/tranlate-shell/tree/main/src/translate_shell/ui/repl.py#L33> make the last line gray like ptpython
...
Now:
# TODO
```{eval-sh}
scripts/generate-todo.md.sh
```
Where the script searches all TODO
s in code then convert them to correct hyperlinks.
grep -RIn TODO: src | perl -pe's/:/#L/;s/:\s*#?\s*TODO:\s*/ /;
s=^=- https://github.com/Freed-Wu/tranlate-shell/tree/main/=g;
s=(https://\S+)=<\1>=g'
Generate Requirement Document
Before:
# Requirements
## completion
Generate shell completion scripts.
- [shtab](https://pypi.org/project/shtab)
...
Now
# Requirements
```{eval-sh}
scripts/generate-requirements.md.sh
```
Where
#!/usr/bin/env bash
for file in requirements.txt requirements/*.txt ; do
filename="${file##*/}"
perl -pe's=^([^#\n]\S*)=- [\1](https://pypi.org/project/\1)=g;
s/^#\s*//g;s/^!.*/## '"${filename%%.txt}"'/g' < "$file"
done
And requirements/completion.txt
:
#!/usr/bin/env -S pip install -r
# Generate shell completion scripts.
shtab
See document to know more.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sphinxcontrib-eval-0.0.1.tar.gz
(16.1 kB
view hashes)
Built Distribution
Close
Hashes for sphinxcontrib_eval-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a67d1c48984ecb7f405e3a970639fd3a22ce6215b70056e2499443dea5861487 |
|
MD5 | 0cad59078bcefe6b7c643c1c3507bb16 |
|
BLAKE2b-256 | cbbb2c3e6808339359bc1d0cdb6839f2d068ee4a2ca1f9f0207b7220d0f8645e |