File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,11 @@ These are envkernel-specific options:
95
95
used as a template for all kernel options (` --language ` ,
96
96
` --kernel-cmd ` , etc). Also, any other file in this directory (such
97
97
as logos) are copied to the new kernel (like kernel.js in irkernel).
98
+ * ` --kernel-make-path-relative ` removes an absolute path from the
99
+ kernel command (mainly useful with ` --kernel-template ` ). This would
100
+ be useful, for example, where you are setting up an lmod install and
101
+ the absolute path of the module might change, but you want it to
102
+ always run Python relative to that module anyway.
98
103
* ` --env=NAME=VALUE ` . Set these environment variables when running
99
104
the kernel. These are actually just saved in the ` kernel.json ` file
100
105
under the ` env ` key, which is used by Jupyter itself. So, this is
Original file line number Diff line number Diff line change @@ -119,6 +119,9 @@ def setup(self):
119
119
help = "Python command to run (default 'python')" )
120
120
parser .add_argument ('--kernel-cmd' ,
121
121
help = "Kernel command to run, separated by spaces. If this is given, --python is not used." )
122
+ parser .add_argument ('--kernel-make-path-relative' , action = 'store_true' ,
123
+ help = "Remove any leading absolute path from the kernel command. Mainly "
124
+ "useful with --kernel-template." )
122
125
parser .add_argument ('--language' ,
123
126
help = "Language to put into kernel file (default based on --kernel)" )
124
127
parser .add_argument ('--env' , action = 'append' , default = [],
@@ -172,6 +175,9 @@ def setup(self):
172
175
self .kernel ['argv' ][0 ] = args .python
173
176
if args .display_name :
174
177
self .kernel ['display_name' ] = args .display_name
178
+ # Make the kernel path relative
179
+ if args .kernel_make_path_relative :
180
+ self .kernel ['argv' ][0 ] = self .kernel ['argv' ][0 ].rsplit ('/' , 1 )[- 1 ]
175
181
# Copy logos from upstream packages, if exists
176
182
self .logos = None
177
183
if self .kernel ['language' ] == 'python' :
Original file line number Diff line number Diff line change @@ -121,6 +121,17 @@ def test_template_copyfiles(d, mode):
121
121
assert os .path .exists (pjoin (kern ['dir' ], 'A.txt' ))
122
122
assert open (pjoin (kern ['dir' ], 'A.txt' )).read () == 'LMNO'
123
123
124
+ @all_modes (['conda' ])
125
+ def test_template_make_path_relative (d , mode ):
126
+ os .environ ['JUPYTER_PATH' ] = pjoin (d , 'share/jupyter' )
127
+ subprocess .call ("python -m ipykernel install --name=aaa-ipy --display-name=BBB --prefix=%s" % d , shell = True )
128
+ # First test it without, ensure it has the full path
129
+ kern = install (d , "%s --kernel-template aaa-ipy MOD1" % mode )
130
+ assert kern ['k' ][0 ] != 'python' # This is an absolete path
131
+ # Now test it with --kernel-make-path-relative and ensure it's relative
132
+ kern = install (d , "%s --kernel-template aaa-ipy --kernel-make-path-relative MOD1" % mode )
133
+ assert kern ['k' ][0 ] == 'python' # This is an absolete path
134
+
124
135
def test_help ():
125
136
"""Test that the global -h option works and prints module names"""
126
137
p = subprocess .Popen ("python -m envkernel -h" , shell = True , stdout = subprocess .PIPE )
You can’t perform that action at this time.
0 commit comments