Skip to content

Commit 4ed2a8b

Browse files
author
Luke Stagner
committed
IDL branding; check for IDL before falling back on GDL
1 parent 89a8f31 commit 4ed2a8b

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

gdl_kernel.py renamed to idl_kernel.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
version_pat = re.compile(r'Version (\d+(\.\d+)+)')
1616

17-
class GDLKernel(Kernel):
18-
implementation = 'gdl_kernel'
17+
class IDLKernel(Kernel):
18+
implementation = 'IDL_kernel'
1919
implementation_version = __version__
20-
language = 'GDL'
20+
language = 'IDL'
2121
@property
2222
def language_version(self):
2323
m = version_pat.search(self.banner)
@@ -27,7 +27,10 @@ def language_version(self):
2727
@property
2828
def banner(self):
2929
if self._banner is None:
30-
self._banner = check_output(['gdl', '--version']).decode('utf-8')
30+
try:
31+
self._banner = check_output(['idl', '-e "" ']).decode('utf-8')
32+
except:
33+
self._banner = check_output(['gdl', '--version']).decode('utf-8')
3134
return self._banner
3235

3336
def __init__(self, **kwargs):
@@ -38,11 +41,14 @@ def __init__(self, **kwargs):
3841
# so that bash and its children are interruptible.
3942
sig = signal.signal(signal.SIGINT, signal.SIG_DFL)
4043
try:
41-
self.gdlwrapper = replwrap.REPLWrapper("gdl",u"GDL> ",None)
42-
self.gdlwrapper.run_command("!quiet=1 & defsysv,'!inline',0".rstrip(), timeout=None)
44+
self.idlwrapper = replwrap.REPLWrapper("idl",u"IDL> ",None)
45+
except:
46+
self.idlwrapper = replwrap.REPLWrapper("gdl",u"GDL> ",None)
4347
finally:
4448
signal.signal(signal.SIGINT, sig)
4549

50+
self.idlwrapper.run_command("!quiet=1 & defsysv,'!inline',0".rstrip(), timeout=None)
51+
4652
def do_execute(self, code, silent, store_history=True, user_expressions=None,
4753
allow_stdin=False):
4854
if not code.strip():
@@ -81,7 +87,7 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
8187
try:
8288
tfile.file.write(code.rstrip()+postcall.rstrip())
8389
tfile.file.close()
84-
output = self.gdlwrapper.run_command(".run "+tfile.name, timeout=None)
90+
output = self.idlwrapper.run_command(".run "+tfile.name, timeout=None)
8591

8692
# Publish images (only one for now)
8793
images = [open(imgfile, 'rb').read() for imgfile in glob("%s/__fig.png" % plot_dir)]
@@ -94,10 +100,10 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
94100
for data in display_data:
95101
self.send_response(self.iopub_socket, 'display_data',{'data':data,'metadata':{'image/png':{'width':683,'height':384}}})
96102
except KeyboardInterrupt:
97-
self.gdlwrapper.child.sendintr()
103+
self.idlwrapper.child.sendintr()
98104
interrupted = True
99-
self.gdlwrapper._expect_prompt()
100-
output = self.gdlwrapper.child.before
105+
self.idlwrapper._expect_prompt()
106+
output = self.idlwrapper.child.before
101107
finally:
102108
tfile.close()
103109
rmtree(plot_dir)
@@ -122,9 +128,9 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
122128
'payloads': [], 'user_expressions': {}}
123129

124130
def do_shutdown(self, restart):
125-
self.gdlwrapper.child.kill(signal.SIGKILL)
131+
self.idlwrapper.child.kill(signal.SIGKILL)
126132
return {'status':'ok', 'restart':restart}
127133

128134
if __name__ == '__main__':
129135
from IPython.kernel.zmq.kernelapp import IPKernelApp
130-
IPKernelApp.launch_instance(kernel_class=GDLKernel)
136+
IPKernelApp.launch_instance(kernel_class=IDLKernel)

kernelspec/kernel.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{"argv":["python","-m","gdl_kernel", "-f", "{connection_file}"],
2-
"display_name":"GDL",
3-
"language":"GDL",
4-
"codemirror_mode":"GDL"
1+
{"argv":["python","-m","idl_kernel", "-f", "{connection_file}"],
2+
"display_name":"IDL",
3+
"language":"IDL",
4+
"codemirror_mode":"IDL"
55
}

setup.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class install_with_kernelspec(install):
66
def run(self):
77
install.run(self)
88
from IPython.kernel.kernelspec import install_kernel_spec
9-
install_kernel_spec('kernelspec', 'GDL', replace=True)
9+
install_kernel_spec('kernelspec', 'IDL', replace=True)
1010

1111
with open('README.md') as f:
1212
readme = f.read()
@@ -15,12 +15,12 @@ def run(self):
1515
if svem_flag in sys.argv:
1616
sys.argv.remove(svem_flag)
1717

18-
setup(name='GDL_kernel',
18+
setup(name='IDL_kernel',
1919
version='0.1',
20-
description='A GDL kernel for IPython',
20+
description='A IDL kernel for IPython',
2121
long_description=readme,
2222
author='Luke Stagner',
23-
py_modules=['gdl_kernel'],
23+
py_modules=['idl_kernel'],
2424
cmdclass={'install': install_with_kernelspec},
2525
install_requires=['pexpect>=3.3'],
2626
classifiers = [

0 commit comments

Comments
 (0)