Skip to content

Commit 19ca2bf

Browse files
committed
Add test and documentation for running envkernel recursively
- This does not intrinsically add anything new to envkernel, this already worked. But see the commits right before this for some necessary fixes that had to be made in order to do this. - Add one basic test, which runs lmod and then conda and checks that the internal invocation has the same arguments as the first kernel. - Otherwise, this is still quite untested (I haven't even run it myself, beyond this one artifical test...)
1 parent ad1b888 commit 19ca2bf

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,28 @@ envkernel parses and manipulates these arguments however is needed.
336336

337337

338338

339+
## Running multiple modes
340+
341+
envkernel doesn't support running multiple modes - for example,
342+
`conda` and `lmod` at the same time. But, because of the general
343+
nature, you should be able to layer it yourself. The following
344+
example uses the `conda` mode to create an envkernel. Then, it uses
345+
`--kernel-template` to re-read that kernel and wrap it in `lmod`:
346+
347+
```
348+
envkernel conda --name=test1 conda_path
349+
envkernel lmod --name=test1 --kernel-template=test1 lmod_module
350+
```
351+
352+
There is nothing really special here, it is layering one envkernel
353+
execution on top of another. If you notice problems with this, please
354+
try to debug a bit and then send feedback/improvements, this is a
355+
relatively new feature.
356+
357+
358+
359+
360+
339361
## Use with nbgrader
340362

341363
envkernel was orginally inspired by the need for nbgrader to securely

test_envkernel.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,31 @@ def test_env(d, mode):
163163
assert kern['kernel']['env']['CCC'] == 'DDD'
164164

165165

166+
def test_recursive_run(d):
167+
"""Test envkernel being called on itself.
168+
169+
Roughly runs this, which :
170+
171+
envkernel lmod --name=test1 LMOD
172+
envkernel conda --kernel-template=test1 --name=test1 CPATH
173+
"""
174+
# Must set JUPYTER_PATH to be able to load the new kernel template
175+
os.environ['JUPYTER_PATH'] = pjoin(d, 'share/jupyter')
176+
kern1 = install(d, "lmod LMOD", name='test1')
177+
#print(kern1['kernel']['argv'])
178+
# Test the conda install
179+
CPATH = pjoin(d, 'test-conda')
180+
os.mkdir(CPATH)
181+
os.mkdir(pjoin(CPATH, 'bin'))
182+
kern2 = install(d, "conda --kernel-template=test1 %s"%CPATH, name='test1')
183+
#print(kern2['kernel']['argv'])
184+
def test_exec(_file, _args):
185+
#print(kern1['kernel']['argv'])
186+
# Exclude the last argument, which is the connection file
187+
assert _args[:-1] == kern1['kernel']['argv'][:-1]
188+
run(d, kern2, test_exec)
189+
190+
166191

167192
# Languages
168193
@all_modes()

0 commit comments

Comments
 (0)