I would like to pass the code from code block test_python
to script
. I do not want test_python
to be evaluated, but simply to have the source code inserted into script
when I evaluate script. The goal is to have a more generic extended version of script
that will do some useful stuff to setup the environment and run the contents of test_python
such that it can be run on different machines. I'd like to eventually hide the script
block in a #+INCLUDE
ed org mode file, then just be able to have the test_python
block and a #+CALL
to script
in the primary org mode.
A minimal example where I am trying to do this is:
#+NAME: test_python
#+BEGIN_SRC ipython :results none :exports none
import numpy as np
x0 = np.arange(-1, 1, 1/10.)
x1 = np.arange(-1, 1, 1/10.)
x0, x1 = np.meshgrid(x0, x1)
y_truth = x0**2 - x1**2 + x1 - 1
print('inside python')
#+END_SRC
#+NAME: script
#+HEADER: :var python_code=""
#+BEGIN_SRC bash :results output
#!/bin/bash
result=$(python <<EOF
$python_code
EOF
)
echo $python_code
echo $result
echo "done test"
#+END_SRC
#+NAME: script_generator
#+CALL: script[:var python_code=test_python]
Adding one more thing: I am actually tangling script
to write to file. I just removed that for the sake of the example.
--- Edit
I had left out some of this to try to get to a minimal example, but it seems that will make the question more clear. Ultimately I want this to look like the following.
any org file I'm currently working in:
* Some cool org stuff
:PROPERTIES:
:OUT_SCRIPT: /ssh:otherMachine:~/scripts/test_python.sh
:END:
#+INCLUDE: ~/org/script_utils.org
#+NAME: test_python
#+BEGIN_SRC ipython :results none :exports none
import numpy as np
x0 = np.arange(-1, 1, 1/10.)
x1 = np.arange(-1, 1, 1/10.)
x0, x1 = np.meshgrid(x0, x1)
y_truth = x0**2 - x1**2 + x1 - 1
print('inside python')
#+END_SRC
#+NAME: script_generator
#+CALL: script[:var python_code=test_python,script_path=OUT_SCRIPT]
and
script_utils.org:
#+NAME: script
#+HEADER: :var python_code="", script_path=""
#+BEGIN_SRC bash :results output :tangle script_path
#!/bin/bash
result=$(python <<EOF
$python_code
EOF
)
echo $python_code
echo $result
echo "done test"
#+END_SRC