Comments (5)
Agreed. I didn't know Sphinx had such a plugin 🙂
from markdown-exec.
WDYT about an expect
option that accepts an integer as value?
```bash exec="true" expect="1"
program-that-exits-with-1
```
Also, should we accept other values for Python code blocks? Something like expect="ValueError"
?
I don't see a use-case for expecting particular Python exceptions: one can always just use a regular python
/pycon
code block without executing it, showing what the exception looks like.
Or even execute a code block that catches the exception and simply prints the formatted traceback.
from markdown-exec.
For the sake of consistency with other tools, please use returncode
and not expect
as that can have lots of meanings, the library or the expected output?
returncode
is already used by https://docs.python.org/3/library/subprocess.html and by https://pythonhosted.org/sphinxcontrib-programoutput/#error-handling
I think that even an exception would translate to an exit code, so no need to extra complicate it.
$ python -c "import foo"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'foo'
FAIL: 1
Basically python will return exit code "1" when an exception is raised and I would recommend using the same approach for python blocks. Think about other code blocks, they should all run as subprocess for safety reasons anyway, so "returncode" is the portable solution.
I will also want to add an option to hide stderr like I had with sphinx, for now I had to add 2>/dev/null
to the commands to hide the noise from it. Making a PR for this would clearly be a good opportunity for me to learn some of the internals.
from markdown-exec.
Thanks for the feedback! I'll go with returncode
then.
About execution of Python code blocks: they're currently executed in the main process, with an isolated globals
dictionary each time. I didn't want to spawn a Python subprocess for each executed Python code block, the perf would be disastrous. But we can consider adding an option to let the user decide if they want to run a Python code block in the main process or in a subprocess.
from markdown-exec.
Implemented (see commit above) 🙂
from markdown-exec.
Related Issues (20)
- Unable to specify the pygments formatter to use on received output HOT 5
- code block exited with non-zero status does not provide enough information for addressing the issue HOT 8
- Setting source="console" is incompatible with result="ansi" HOT 1
- `source = "tabbed-right"` seems to conflict with annotations in Material HOT 7
- Support named blocks HOT 3
- Don't render anything if output is empty
- [Feature] Output logging in rendered output HOT 1
- [Feature] Option to globally disable execution HOT 1
- Add a cwd option to console
- stdout from "external" functions not shown HOT 8
- Compability with snippets HOT 3
- Feature Request: Support Other Languages? HOT 1
- Feature request: default behaviour for code blocs HOT 2
- No output without print and no line breaks HOT 4
- bug: source="tabbed-left" showing source vertically, rather than horizontally HOT 9
- bug: ANSI escape codes in `jax.ClosedJaxpr` are not being converted to HTML HOT 3
- Consideration for `mkdocs get-deps` regarding the `[ansi]` extra HOT 2
- bug: Don't always include ANSI CSS file
- Appearance of code block headings in the navigation sidebar HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markdown-exec.