OpenNTI / sphinxcontrib-programoutput

Sphinx extension for capturing program output
BSD 3-Clause "New" or "Revised" License
37 stars 17 forks source link

Using cwd option #60

Closed kiteloopdesign closed 1 year ago

kiteloopdesign commented 1 year ago

Hi, thanks for this extension it is super useful for auto documenting cli tools!

One thing I can't get to work though is to get the "cwd" option. I don't think the documentation tells how this option should be used?

Note that I am trying to get this work with Sphinx+MyST, so what I am trying is the following (note I am using 3x acute tilde so they are not incorrectly interpreted here)

´´´{command-output} pwd
---
cwd ..
---
´´´

This is, I am just trying to go up one folder before I can execute "pwd". However I get a big error when doing so:

File "*****/.venv/lib/python3.9/site-packages/myst_parser/parsers/directives.py", line 144, in parse_directive_options
    for name, value in list(options.items()):
AttributeError: 'str' object has no attribute 'items'
The full traceback has been saved in /tmp/sphinx-err-l59_ympn.log, if you want to report the issue to the developers.

Actually, what I would really like to get more info about is regarding on what environment are these commands really running on. This is, on what shell environment is this running? I guess on a one provided by python's subprocess? Is it possible to update $PATH document-wide via some python command on conf.py?

Thanks

jamadden commented 1 year ago

File "*****/.venv/lib/python3.9/site-packages/myst_parser/parsers/directives.py"

As you can see, your error is coming from your myst extension, not this package. So I can't help you with that.

Actually, what I would really like to get more info about is regarding on what environment are these commands really running on. This is, on what shell environment is this running? I guess on a one provided by python's subprocess? Is it possible to update $PATH document-wide via some python command on conf.py?

Yes, this package runs commands using the subprocess module. Whether or not is uses a shell depends on whether you turn on the shell option or not. The PATH and the rest of the environment variables are entirely up to you, set them however you want to. Relative paths are interpreted as Sphinx normally interprets them.

kiteloopdesign commented 1 year ago

I guess the question I was asking is, independently of that error which, you are right, comes from myst, is that syntax the expected one for "cwd" ? Or, in other words, doc doesn't give an example of how would one write it down in normal rst sphinx's markdown? would it be like so?

.. command-output:: echo "$USER"
   :cwd:

Thanks

jamadden commented 1 year ago

It's just a normal option like any other directive option. In other words, it works exactly the same as the examples for returncode and ellipsis.