yongrenjie / sphinx-exec-directive

Sphinx extension to run Python code blocks and display the output.
https://yongrenjie.github.io/sphinx-exec-directive/
MIT License
3 stars 3 forks source link

Allow code to be executed by other sources #7

Open yongrenjie opened 3 years ago

yongrenjie commented 3 years ago

It seems easy enough to pass the code to stdin of a process.

Haskell would be a tougher one because ghc doesn't accept code passed via stdin. Probably the easiest way would be to make a tempfile, call ghc on that file and capture the stdout.

yongrenjie commented 3 years ago

Generally there are three methods which could conceivably be used to run code with an external process, illustrated here with a shell script:

In theory we should deal with all three, but the pipes are the easiest to implement (using subprocess.Popen.communicate()). 45fcf4a allows execution of Haskell code by piping it into runghc.

.. exec::
   :process: haskell

   main :: IO ()
   main = print $ take 20 fibs
     where
       fibs = 0 : scanl (+) 1 fibs
Screenshot 2021-05-21 at 9 13 36 PM

It would of course be nice to be able to completely customise this using the options, but I'm willing to settle for a bunch of predefined languages.

yongrenjie commented 3 years ago

34d6829 allows execution of Matlab code via a tempfile.

yongrenjie commented 3 years ago

7d67b77 allows shell scripts...