From bdc87b7fab1314b58190454fc104e78c40ca839c Mon Sep 17 00:00:00 2001 From: steffen Date: Fri, 17 Mar 2017 13:53:58 +0100 Subject: [PATCH 01/22] nest.helpdesk() opens now system default browser --- pynest/nest/lib/hl_api_helper.py | 60 ++++++++++++++++++++++++++++++-- pynest/nest/lib/hl_api_info.py | 58 ++++++++++++++++++++++++------ 2 files changed, 106 insertions(+), 12 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index f10f577ea9..61da757f04 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -28,6 +28,9 @@ import inspect import functools import textwrap +import subprocess +import os +import re # These variables MUST be set by __init__.py right after importing. # There is no safety net, whatsoever. @@ -111,7 +114,6 @@ def deprecated(alt_func_name, text=None): function: Decorator function """ - def deprecated_decorator(func): _deprecation_warning[func.__name__] = True @@ -172,6 +174,7 @@ def is_string(obj): """ return isinstance(obj, uni_str) + __debug = False @@ -389,7 +392,7 @@ def broadcast(item, length, allowed_types, name="item"): """ if isinstance(item, allowed_types): - return length * (item, ) + return length * (item,) elif len(item) == 1: return length * item elif len(item) != length: @@ -400,6 +403,58 @@ def broadcast(item, length, allowed_types, name="item"): return item + +def pdoc(obj, ppager): + """Output of doc in python with pager or print + + Parameters + ---------- + obj : object + Object to display + ppager: str, optional + pager to use, NO if you explicity do not want to use a pager + + @author graber + """ + # environment 'jupyter', 'ipython n' or plain python + jptk = re.findall(r'.*jupyter.*', os.environ['_']) + iptk = re.findall(r'.*ipython.*', os.environ['_']) + + # reading ~/.nestrc, try to find pager + if not ppager: + rc = open(os.environ['HOME'] + '/.nestrc', 'r') + for line in rc: + rctst = re.match(r'^\s?\%', line) + if rctst is None: + ppagers = re.findall( + r'\s?\/page\s?<<\s?\/command\s?\((.*)\).*', line) + if ppagers: + rcppager = ppagers[0] + break + rc.close() + if not rcppager: + rcppager = "less" + + helpdir = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/" + objname = obj + '.hlp' + ishelp = "" + for dirpath, dirnames, files in os.walk(helpdir): + for hlp in files: + if hlp == objname: + ishelp = True + objf = os.path.join(dirpath, objname) + fhlp = open(objf, 'r') + hlptxt = fhlp.read() + fhlp.close() + if jptk or iptk: + print(hlptxt) + else: + if not ppager or ppager == "NO": + print(hlptxt) + else: + subprocess.call([rcppager, objf]) + + @check_stack def get_verbosity(): """Return verbosity level of NEST's messages. @@ -432,6 +487,7 @@ def set_verbosity(level): sr("%s setverbosity" % level) + def model_deprecation_warning(model): """Checks whether the model is to be removed in a future verstion of NEST. If so, a deprecation warning is issued. diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index e78b43ce6f..5d2792f2a0 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -24,6 +24,10 @@ """ from .hl_api_helper import * +import os +import re +import subprocess +import webbrowser @check_stack @@ -55,19 +59,19 @@ def authors(): @check_stack -def helpdesk(browser="firefox"): +def helpdesk(): """Open the NEST helpdesk in the given browser. - The default browser is firefox. + The system default browser. - Parameters - ---------- - browser : str, optional - Name of the browser to use + @author graber """ - sr("/helpdesk << /command (%s) >> SetOptions" % browser) - sr("helpdesk") + # sr("/helpdesk << /command (%s) >> SetOptions" % browser) + # sr("helpdesk") + + url = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/helpindex.html" + webbrowser.open_new(url) @check_stack @@ -82,11 +86,45 @@ def help(obj=None, pager="less"): Object to display help for pager : str, optional Pager to use + + """ if obj is not None: - sr("/page << /command (%s) >> SetOptions" % pager) - sr("/%s help" % obj) + # sr("/page << /command (%s) >> SetOptions" % pager) + # sr("/%s help" % obj) + + # print('HALLO') + # @author graber + helpdir = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/" + objname = obj + '.hlp' + jptk = re.findall(r'.*jupyter.*', os.environ['_']) + iptk = re.findall(r'.*ipython.*', os.environ['_']) + + # reading ~/.nestrc + pypager = 'less' + rc = open(os.environ['HOME'] + '/.nestrc', 'r') + for line in rc: + rctst = re.match(r'^\s?\%', line) + if rctst is None: + pypagers = re.findall( + r'\s?\/page\s?<<\s?\/command\s?\((.*)\).*', line) + if pypagers: + pypager = pypagers[0] + break + rc.close() + + for dirpath, dirnames, files in os.walk(helpdir): + for hlp in files: + if hlp == objname: + objf = os.path.join(dirpath, objname) + fhlp = open(objf, 'r') + hlptxt = fhlp.read() + fhlp.close() + if jptk or iptk: + print(hlptxt) + else: + subprocess.call([pypager, objf]) else: print("Type 'nest.helpdesk()' to access the online documentation " "in a browser.") From 3e33deaa3e6db061b9d9f8939b6eac71325e6dea Mon Sep 17 00:00:00 2001 From: steffen Date: Fri, 17 Mar 2017 14:10:10 +0100 Subject: [PATCH 02/22] setting and using help pager/viewer --- pynest/nest/lib/hl_api_info.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index 5d2792f2a0..c370ce22f4 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -60,9 +60,10 @@ def authors(): @check_stack def helpdesk(): - """Open the NEST helpdesk in the given browser. + """Open the NEST helpdesk in browser. The system default browser. + /helpdesk << /command (firefox) >> SetOptions in ~/.nestrc is now obsolete @author graber """ @@ -87,7 +88,7 @@ def help(obj=None, pager="less"): pager : str, optional Pager to use - + @author graber """ if obj is not None: @@ -95,13 +96,13 @@ def help(obj=None, pager="less"): # sr("/%s help" % obj) # print('HALLO') - # @author graber + # helpdir = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/" objname = obj + '.hlp' jptk = re.findall(r'.*jupyter.*', os.environ['_']) iptk = re.findall(r'.*ipython.*', os.environ['_']) - # reading ~/.nestrc + # reading ~/.nestrc lookink for pager to use. pypager = 'less' rc = open(os.environ['HOME'] + '/.nestrc', 'r') for line in rc: @@ -121,10 +122,12 @@ def help(obj=None, pager="less"): fhlp = open(objf, 'r') hlptxt = fhlp.read() fhlp.close() - if jptk or iptk: - print(hlptxt) - else: - subprocess.call([pypager, objf]) + # @ graber + # @ todo try it + # if jptk or iptk: + # print(hlptxt) + # else: + subprocess.call([pypager, objf]) else: print("Type 'nest.helpdesk()' to access the online documentation " "in a browser.") From 83346c15000a294f35f17fc92f8eadb3d0323500 Mon Sep 17 00:00:00 2001 From: steffen Date: Mon, 20 Mar 2017 13:50:13 +0100 Subject: [PATCH 03/22] better use in notebook --- pynest/nest/lib/hl_api_info.py | 44 +++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index c370ce22f4..efd3689a3b 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -103,17 +103,20 @@ def help(obj=None, pager="less"): iptk = re.findall(r'.*ipython.*', os.environ['_']) # reading ~/.nestrc lookink for pager to use. - pypager = 'less' - rc = open(os.environ['HOME'] + '/.nestrc', 'r') - for line in rc: - rctst = re.match(r'^\s?\%', line) - if rctst is None: - pypagers = re.findall( - r'\s?\/page\s?<<\s?\/command\s?\((.*)\).*', line) - if pypagers: - pypager = pypagers[0] - break - rc.close() + + if pager is None: + + rc = open(os.environ['HOME'] + '/.nestrc', 'r') + for line in rc: + rctst = re.match(r'^\s?\%', line) + if rctst is None: + pypagers = re.findall( + r'\s?\/page\s?<<\s?\/command\s?\((.*)\).*', line) + if pypagers: + pager = pypagers[0] + break + else: pager = 'less' + rc.close() for dirpath, dirnames, files in os.walk(helpdir): for hlp in files: @@ -122,12 +125,19 @@ def help(obj=None, pager="less"): fhlp = open(objf, 'r') hlptxt = fhlp.read() fhlp.close() - # @ graber - # @ todo try it - # if jptk or iptk: - # print(hlptxt) - # else: - subprocess.call([pypager, objf]) + if jptk or iptk: + + consolepager = ['less', 'more', 'vi', 'vim', 'nano', + 'emacs -nw', 'ed', 'editor'] + if pager in consolepager: + print('---\n\n') + print('Use: help(obj=None, pager=YOURPAGER).\n') + print('For YOURPAGER do not use console editors!\n') + print('---\n\n') + print(hlptxt) + else: subprocess.call([pager, objf]) + else: + subprocess.call([pager, objf]) else: print("Type 'nest.helpdesk()' to access the online documentation " "in a browser.") From e7c9f9c42036e10378e3c5028fac7c18b772b1b0 Mon Sep 17 00:00:00 2001 From: steffen Date: Mon, 20 Mar 2017 14:24:52 +0100 Subject: [PATCH 04/22] some inline documentation --- pynest/nest/lib/hl_api_info.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index efd3689a3b..9a8ce773c4 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -101,11 +101,11 @@ def help(obj=None, pager="less"): objname = obj + '.hlp' jptk = re.findall(r'.*jupyter.*', os.environ['_']) iptk = re.findall(r'.*ipython.*', os.environ['_']) + # @todo is there a way to recognize 'ipython notebook'? Do it. # reading ~/.nestrc lookink for pager to use. - if pager is None: - + # open ~/.nestrc rc = open(os.environ['HOME'] + '/.nestrc', 'r') for line in rc: rctst = re.match(r'^\s?\%', line) @@ -125,11 +125,13 @@ def help(obj=None, pager="less"): fhlp = open(objf, 'r') hlptxt = fhlp.read() fhlp.close() - if jptk or iptk: - + # only for jupyter notebook + if jptk: + # @todo more pager consolepager = ['less', 'more', 'vi', 'vim', 'nano', 'emacs -nw', 'ed', 'editor'] if pager in consolepager: + # only in notebook print('---\n\n') print('Use: help(obj=None, pager=YOURPAGER).\n') print('For YOURPAGER do not use console editors!\n') From 8a2d69feb0dbb519cdb6b590c0765adef0cd56bd Mon Sep 17 00:00:00 2001 From: steffen Date: Tue, 21 Mar 2017 10:00:01 +0100 Subject: [PATCH 05/22] introducing check_nb() and moving to hl_api_helper.py --- pynest/nest/lib/hl_api_helper.py | 77 +++++++++++++++++++++++--------- pynest/nest/lib/hl_api_info.py | 61 ++++--------------------- 2 files changed, 65 insertions(+), 73 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index 61da757f04..dd42045809 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -403,8 +403,39 @@ def broadcast(item, length, allowed_types, name="item"): return item +def check_nb(): + """Check if is notebook or not -def pdoc(obj, ppager): + To know a little bit more about the environment use: + + jptk = re.findall(r'.*jupyter.*', os.environ['_']) + iptk = re.findall(r'.*ipython.*', os.environ['_']) + + """ + try: + cfg = get_ipython().config + if cfg['IPKernelApp']['connection_file']: + return True + else: + return False + except NameError: + return False + +@check_stack +def open_window(): + js = ''' + + ''' + print(js) + + +@check_stack +def pdoc(obj, pager): """Output of doc in python with pager or print Parameters @@ -416,43 +447,48 @@ def pdoc(obj, ppager): @author graber """ - # environment 'jupyter', 'ipython n' or plain python - jptk = re.findall(r'.*jupyter.*', os.environ['_']) - iptk = re.findall(r'.*ipython.*', os.environ['_']) + helpdir = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/" + objname = obj + '.hlp' - # reading ~/.nestrc, try to find pager - if not ppager: + # reading ~/.nestrc lookink for pager to use. + if pager is None: + # open ~/.nestrc rc = open(os.environ['HOME'] + '/.nestrc', 'r') for line in rc: rctst = re.match(r'^\s?\%', line) if rctst is None: - ppagers = re.findall( + pypagers = re.findall( r'\s?\/page\s?<<\s?\/command\s?\((.*)\).*', line) - if ppagers: - rcppager = ppagers[0] + if pypagers: + pager = pypagers[0] break + else: + pager = 'less' rc.close() - if not rcppager: - rcppager = "less" - helpdir = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/" - objname = obj + '.hlp' - ishelp = "" for dirpath, dirnames, files in os.walk(helpdir): for hlp in files: if hlp == objname: - ishelp = True objf = os.path.join(dirpath, objname) fhlp = open(objf, 'r') hlptxt = fhlp.read() fhlp.close() - if jptk or iptk: - print(hlptxt) - else: - if not ppager or ppager == "NO": + # only for notebook + if check_nb(): + # @todo more pager + consolepager = ['less', 'more', 'vi', 'vim', 'nano', + 'emacs -nw', 'ed', 'editor'] + if pager in consolepager: + # only in notebook + print('---\n') + print('Use: help(obj=None, pager=YOURPAGER).\n') + print('For YOURPAGER do not use console editors!\n') + print('---\n\n') print(hlptxt) else: - subprocess.call([rcppager, objf]) + subprocess.call([pager, objf]) + else: + subprocess.call([pager, objf]) @check_stack @@ -487,7 +523,6 @@ def set_verbosity(level): sr("%s setverbosity" % level) - def model_deprecation_warning(model): """Checks whether the model is to be removed in a future verstion of NEST. If so, a deprecation warning is issued. diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index 9a8ce773c4..b84ebae7f3 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -71,12 +71,12 @@ def helpdesk(): # sr("/helpdesk << /command (%s) >> SetOptions" % browser) # sr("helpdesk") - url = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/helpindex.html" + url = os.environ['NEST_DOC_DIR'] + "/help/helpindex.html" webbrowser.open_new(url) @check_stack -def help(obj=None, pager="less"): +def help(obj=None, pager=None): """Show the help page for the given object using the given pager. The default pager is less. @@ -90,67 +90,24 @@ def help(obj=None, pager="less"): @author graber """ - if obj is not None: # sr("/page << /command (%s) >> SetOptions" % pager) # sr("/%s help" % obj) - # print('HALLO') - # - helpdir = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/" - objname = obj + '.hlp' - jptk = re.findall(r'.*jupyter.*', os.environ['_']) - iptk = re.findall(r'.*ipython.*', os.environ['_']) - # @todo is there a way to recognize 'ipython notebook'? Do it. - - # reading ~/.nestrc lookink for pager to use. - if pager is None: - # open ~/.nestrc - rc = open(os.environ['HOME'] + '/.nestrc', 'r') - for line in rc: - rctst = re.match(r'^\s?\%', line) - if rctst is None: - pypagers = re.findall( - r'\s?\/page\s?<<\s?\/command\s?\((.*)\).*', line) - if pypagers: - pager = pypagers[0] - break - else: pager = 'less' - rc.close() - - for dirpath, dirnames, files in os.walk(helpdir): - for hlp in files: - if hlp == objname: - objf = os.path.join(dirpath, objname) - fhlp = open(objf, 'r') - hlptxt = fhlp.read() - fhlp.close() - # only for jupyter notebook - if jptk: - # @todo more pager - consolepager = ['less', 'more', 'vi', 'vim', 'nano', - 'emacs -nw', 'ed', 'editor'] - if pager in consolepager: - # only in notebook - print('---\n\n') - print('Use: help(obj=None, pager=YOURPAGER).\n') - print('For YOURPAGER do not use console editors!\n') - print('---\n\n') - print(hlptxt) - else: subprocess.call([pager, objf]) - else: - subprocess.call([pager, objf]) + pdoc(obj, pager) + + else: - print("Type 'nest.helpdesk()' to access the online documentation " - "in a browser.") + print("\nType 'nest.helpdesk()' to access the online documentation " + "in a browser.\n") print("Type 'nest.help(object)' to get help on a NEST object or " "command.\n") print("Type 'nest.Models()' to see a list of available models " "in NEST.\n") print("Type 'nest.authors()' for information about the makers " - "of NEST.") + "of NEST.\n") print("Type 'nest.sysinfo()' to see details on the system " - "configuration.") + "configuration.\n") print("Type 'nest.version()' for information about the NEST " "version.\n") print("For more information visit http://www.nest-simulator.org.") From 64f18a5de67a299f0589a154ffe40b8e01e82b97 Mon Sep 17 00:00:00 2001 From: steffen Date: Tue, 21 Mar 2017 15:49:31 +0100 Subject: [PATCH 06/22] introducing modal window in notebook --- pynest/nest/lib/hl_api_helper.py | 99 ++++++++++++++++++++++---------- pynest/nest/lib/hl_api_info.py | 9 ++- 2 files changed, 74 insertions(+), 34 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index dd42045809..e0e8ce53da 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -26,6 +26,7 @@ import warnings import inspect +import json import functools import textwrap import subprocess @@ -406,35 +407,67 @@ def broadcast(item, length, allowed_types, name="item"): def check_nb(): """Check if is notebook or not + Parameters + ---------- + + To know a little bit more about the environment use: jptk = re.findall(r'.*jupyter.*', os.environ['_']) iptk = re.findall(r'.*ipython.*', os.environ['_']) + @author graber """ + # test if notebook in ipython try: cfg = get_ipython().config - if cfg['IPKernelApp']['connection_file']: - return True - else: - return False + iptnk = cfg['IPKernelApp']['parent_appname'] except NameError: + iptnk = '' + # test if jupyther notebook + jpnk = re.findall(r'.*jupyter.*', os.environ['_']) + if iptnk == 'ipython-notebook': + return True + elif jpnk: + return True + else: return False -@check_stack -def open_window(): - js = ''' - - ''' - print(js) + +def open_window(objname, hlptxt): + """Open modal window with help text + + Parameters + ---------- + objname : str + filename + hlptxt : str + Full text + + @author graber + """ + hlptxt = json.dumps(hlptxt) + style = "" + + from IPython.display import HTML, Javascript, display + display(HTML(style)) + display(Javascript(""" + require( + ["base/js/dialog"], + function(dialog) { + dialog.modal({ + title: '%s', + body: %s, + buttons: { + 'close': {} + } + }); + } + ); + """ % (objname, hlptxt))) -@check_stack def pdoc(obj, pager): """Output of doc in python with pager or print @@ -449,16 +482,20 @@ def pdoc(obj, pager): """ helpdir = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/" objname = obj + '.hlp' + htmlname = obj + '.html' + # @todo more pager + consolepager = ['less', 'more', 'vi', 'vim', 'nano', 'emacs -nw', + 'ed', 'editor'] # reading ~/.nestrc lookink for pager to use. if pager is None: # open ~/.nestrc rc = open(os.environ['HOME'] + '/.nestrc', 'r') for line in rc: - rctst = re.match(r'^\s?\%', line) + rctst = re.match(r'^\s?%', line) if rctst is None: pypagers = re.findall( - r'\s?\/page\s?<<\s?\/command\s?\((.*)\).*', line) + r'\s?/page\s?<<\s?/command\s?\((.*)\).*', line) if pypagers: pager = pypagers[0] break @@ -475,20 +512,24 @@ def pdoc(obj, pager): fhlp.close() # only for notebook if check_nb(): - # @todo more pager - consolepager = ['less', 'more', 'vi', 'vim', 'nano', - 'emacs -nw', 'ed', 'editor'] if pager in consolepager: - # only in notebook - print('---\n') - print('Use: help(obj=None, pager=YOURPAGER).\n') - print('For YOURPAGER do not use console editors!\n') - print('---\n\n') - print(hlptxt) + htf = os.path.join(dirpath, htmlname) + fht = open(htf, 'r') + htmltxt = fht.read() + fht.close() + # only in notebook open modal window + open_window(objname, hlptxt) + break else: - subprocess.call([pager, objf]) + proc = subprocess.Popen([pager, objf]) + break else: - subprocess.call([pager, objf]) + if pager in consolepager: + subprocess.call([pager, objf]) + break + else: + proc = subprocess.Popen([pager, objf]) + break @check_stack diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index b84ebae7f3..21888f02f4 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -96,18 +96,17 @@ def help(obj=None, pager=None): pdoc(obj, pager) - else: - print("\nType 'nest.helpdesk()' to access the online documentation " - "in a browser.\n") + print("Type 'nest.helpdesk()' to access the online documentation " + "in a browser.") print("Type 'nest.help(object)' to get help on a NEST object or " "command.\n") print("Type 'nest.Models()' to see a list of available models " "in NEST.\n") print("Type 'nest.authors()' for information about the makers " - "of NEST.\n") + "of NEST.") print("Type 'nest.sysinfo()' to see details on the system " - "configuration.\n") + "configuration.") print("Type 'nest.version()' for information about the NEST " "version.\n") print("For more information visit http://www.nest-simulator.org.") From 7a3b8f8c06e0d46cb048157952c79df26eab3bbc Mon Sep 17 00:00:00 2001 From: steffen Date: Wed, 22 Mar 2017 07:55:55 +0100 Subject: [PATCH 07/22] better help on pure python level --- pynest/nest/lib/hl_api_helper.py | 9 ++++++--- pynest/nest/lib/hl_api_info.py | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index e0e8ce53da..bb3addf77a 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -426,10 +426,13 @@ def check_nb(): iptnk = '' # test if jupyther notebook jpnk = re.findall(r'.*jupyter.*', os.environ['_']) + ipjptk = re.findall(r'.*ipython.*', os.environ['_']) if iptnk == 'ipython-notebook': return True elif jpnk: return True + elif ipjptk: + return True else: return False @@ -468,7 +471,7 @@ def open_window(objname, hlptxt): """ % (objname, hlptxt))) -def pdoc(obj, pager): +def pdoc(hlpobj, pager): """Output of doc in python with pager or print Parameters @@ -481,8 +484,8 @@ def pdoc(obj, pager): @author graber """ helpdir = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/" - objname = obj + '.hlp' - htmlname = obj + '.html' + objname = hlpobj + '.hlp' + htmlname = hlpobj + '.html' # @todo more pager consolepager = ['less', 'more', 'vi', 'vim', 'nano', 'emacs -nw', 'ed', 'editor'] diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index 21888f02f4..72a5c16c4b 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -90,11 +90,12 @@ def help(obj=None, pager=None): @author graber """ - if obj is not None: + hlpobj = obj + if hlpobj is not None: # sr("/page << /command (%s) >> SetOptions" % pager) # sr("/%s help" % obj) - pdoc(obj, pager) + pdoc(hlpobj, pager) else: print("Type 'nest.helpdesk()' to access the online documentation " @@ -102,7 +103,7 @@ def help(obj=None, pager=None): print("Type 'nest.help(object)' to get help on a NEST object or " "command.\n") print("Type 'nest.Models()' to see a list of available models " - "in NEST.\n") + "in NEST.") print("Type 'nest.authors()' for information about the makers " "of NEST.") print("Type 'nest.sysinfo()' to see details on the system " From 3edd66e8ce70615f2257dec185c8486617a52395 Mon Sep 17 00:00:00 2001 From: steffen Date: Wed, 22 Mar 2017 08:07:11 +0100 Subject: [PATCH 08/22] minor helptext edits --- pynest/nest/lib/hl_api_helper.py | 23 +++++------------------ pynest/nest/lib/hl_api_info.py | 9 +-------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index bb3addf77a..bcd9e05c5b 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -406,19 +406,8 @@ def broadcast(item, length, allowed_types, name="item"): def check_nb(): """Check if is notebook or not - - Parameters - ---------- - - - To know a little bit more about the environment use: - - jptk = re.findall(r'.*jupyter.*', os.environ['_']) - iptk = re.findall(r'.*ipython.*', os.environ['_']) - - @author graber """ - # test if notebook in ipython + try: cfg = get_ipython().config iptnk = cfg['IPKernelApp']['parent_appname'] @@ -446,9 +435,8 @@ def open_window(objname, hlptxt): filename hlptxt : str Full text - - @author graber """ + hlptxt = json.dumps(hlptxt) style = "" @@ -476,13 +464,12 @@ def pdoc(hlpobj, pager): Parameters ---------- - obj : object + hlpobj : object Object to display - ppager: str, optional + pager: str, optional pager to use, NO if you explicity do not want to use a pager - - @author graber """ + helpdir = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/" objname = hlpobj + '.hlp' htmlname = hlpobj + '.html' diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index 72a5c16c4b..073964537a 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -68,9 +68,6 @@ def helpdesk(): @author graber """ - # sr("/helpdesk << /command (%s) >> SetOptions" % browser) - # sr("helpdesk") - url = os.environ['NEST_DOC_DIR'] + "/help/helpindex.html" webbrowser.open_new(url) @@ -87,14 +84,9 @@ def help(obj=None, pager=None): Object to display help for pager : str, optional Pager to use - - @author graber """ hlpobj = obj if hlpobj is not None: - # sr("/page << /command (%s) >> SetOptions" % pager) - # sr("/%s help" % obj) - pdoc(hlpobj, pager) else: @@ -125,6 +117,7 @@ def get_argv(): tuple: Argv, as seen by NEST. """ + sr('statusdict') statusdict = spp() return statusdict['argv'] From 6fe70e5a69d21309debcbd44a732aefe931dcffa Mon Sep 17 00:00:00 2001 From: steffen Date: Thu, 23 Mar 2017 11:19:38 +0100 Subject: [PATCH 09/22] Better check for notebooks --- pynest/nest/lib/hl_api_helper.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index bcd9e05c5b..60fa41541b 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -415,6 +415,8 @@ def check_nb(): iptnk = '' # test if jupyther notebook jpnk = re.findall(r'.*jupyter.*', os.environ['_']) + + # todo ipjptk = re.findall(r'.*ipython.*', os.environ['_']) if iptnk == 'ipython-notebook': return True @@ -426,6 +428,13 @@ def check_nb(): return False +def check_nb(): + try: + return get_ipython().__class__.__name__.startswith('ZMQ') + except NameError: + return False + + def open_window(objname, hlptxt): """Open modal window with help text From 3e710ae97d7bfe423a4844a8c6f0f6cc9a564b01 Mon Sep 17 00:00:00 2001 From: steffen Date: Thu, 23 Mar 2017 13:10:35 +0100 Subject: [PATCH 10/22] private functions --- pynest/nest/lib/hl_api_helper.py | 98 ++++++++++++-------------------- pynest/nest/lib/hl_api_info.py | 2 +- 2 files changed, 37 insertions(+), 63 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index 60fa41541b..4e02f5d920 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -33,6 +33,8 @@ import os import re +from string import Template + # These variables MUST be set by __init__.py right after importing. # There is no safety net, whatsoever. sps = spp = sr = pcd = kernel = None @@ -233,11 +235,11 @@ def stack_checker_func(*args, **kwargs): if not get_debug(): return f(*args, **kwargs) else: - sr('count') - stackload_before = spp() + sr + stackload_before = spp result = f(*args, **kwargs) - sr('count') - num_leftover_elements = spp() - stackload_before + sr + num_leftover_elements = spp - stackload_before if num_leftover_elements != 0: eargs = (f.__name__, num_leftover_elements) etext = "Function '%s' left %i elements on the stack." @@ -397,45 +399,21 @@ def broadcast(item, length, allowed_types, name="item"): elif len(item) == 1: return length * item elif len(item) != length: - raise TypeError("'%s' must be a single value, a list with " + - "one element or a list with %i elements." - % (name, length)) - + raise TypeError("'{0}' must be a single value, a list with " + + "one element or a list with {1} elements.".format( + name, length)) return item -def check_nb(): - """Check if is notebook or not - """ - - try: - cfg = get_ipython().config - iptnk = cfg['IPKernelApp']['parent_appname'] - except NameError: - iptnk = '' - # test if jupyther notebook - jpnk = re.findall(r'.*jupyter.*', os.environ['_']) - - # todo - ipjptk = re.findall(r'.*ipython.*', os.environ['_']) - if iptnk == 'ipython-notebook': - return True - elif jpnk: - return True - elif ipjptk: - return True - else: - return False - - -def check_nb(): +def __check_nb(): + """Return true if called from a Jupyter notebook.""" try: return get_ipython().__class__.__name__.startswith('ZMQ') except NameError: return False -def open_window(objname, hlptxt): +def __show_help_in_modal_window(objname, hlptxt): """Open modal window with help text Parameters @@ -449,26 +427,28 @@ def open_window(objname, hlptxt): hlptxt = json.dumps(hlptxt) style = "" + s = Template(""" + require( + ["base/js/dialog"], + function(dialog) { + dialog.modal({ + title: '$jstitle', + body: $jstext, + buttons: { + 'close': {} + } + }); + } + ); + """) from IPython.display import HTML, Javascript, display display(HTML(style)) - display(Javascript(""" - require( - ["base/js/dialog"], - function(dialog) { - dialog.modal({ - title: '%s', - body: %s, - buttons: { - 'close': {} - } - }); - } - ); - """ % (objname, hlptxt))) - - -def pdoc(hlpobj, pager): + + display(Javascript(s.substitute(jstitle=objname, jstext=hlptxt))) + + +def show_help_with_pager(hlpobj, pager): """Output of doc in python with pager or print Parameters @@ -481,7 +461,6 @@ def pdoc(hlpobj, pager): helpdir = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/" objname = hlpobj + '.hlp' - htmlname = hlpobj + '.html' # @todo more pager consolepager = ['less', 'more', 'vi', 'vim', 'nano', 'emacs -nw', 'ed', 'editor'] @@ -508,16 +487,11 @@ def pdoc(hlpobj, pager): objf = os.path.join(dirpath, objname) fhlp = open(objf, 'r') hlptxt = fhlp.read() - fhlp.close() # only for notebook - if check_nb(): + if __check_nb(): if pager in consolepager: - htf = os.path.join(dirpath, htmlname) - fht = open(htf, 'r') - htmltxt = fht.read() - fht.close() # only in notebook open modal window - open_window(objname, hlptxt) + __show_help_in_modal_window(objname, hlptxt) break else: proc = subprocess.Popen([pager, objf]) @@ -543,8 +517,8 @@ def get_verbosity(): # Defined in hl_api_helper to avoid circular inclusion problem with # hl_api_info.py - sr('verbosity') - return spp() + sr + return spp @check_stack @@ -560,7 +534,7 @@ def set_verbosity(level): # Defined in hl_api_helper to avoid circular inclusion problem with # hl_api_info.py - sr("%s setverbosity" % level) + sr def model_deprecation_warning(model): diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index 073964537a..4426fd47e4 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -87,7 +87,7 @@ def help(obj=None, pager=None): """ hlpobj = obj if hlpobj is not None: - pdoc(hlpobj, pager) + show_help_with_pager(hlpobj, pager) else: print("Type 'nest.helpdesk()' to access the online documentation " From fc66fe263f49248a8a09df685e8235b4ff777e44 Mon Sep 17 00:00:00 2001 From: steffen Date: Mon, 3 Apr 2017 10:12:59 +0200 Subject: [PATCH 11/22] Secure environment setting --- pynest/nest/lib/hl_api_helper.py | 14 ++++++++++---- pynest/nest/lib/hl_api_info.py | 2 -- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index 4e02f5d920..9414fd271d 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -458,8 +458,14 @@ def show_help_with_pager(hlpobj, pager): pager: str, optional pager to use, NO if you explicity do not want to use a pager """ - - helpdir = os.environ['NEST_INSTALL_DIR'] + "/share/doc/nest/help/" + if 'NEST_INSTALL_DIR' not in os.environ: + print( + 'NEST help needs to know where NEST is installed.' + 'Please source nest_vars.sh or define NEST_INSTALL_DIR manually.') + return + + helpdir = os.path.join(os.environ['NEST_INSTALL_DIR'], + "/share/doc/nest/help/") objname = hlpobj + '.hlp' # @todo more pager consolepager = ['less', 'more', 'vi', 'vim', 'nano', 'emacs -nw', @@ -494,14 +500,14 @@ def show_help_with_pager(hlpobj, pager): __show_help_in_modal_window(objname, hlptxt) break else: - proc = subprocess.Popen([pager, objf]) + subprocess.Popen([pager, objf]) break else: if pager in consolepager: subprocess.call([pager, objf]) break else: - proc = subprocess.Popen([pager, objf]) + subprocess.Popen([pager, objf]) break diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index 4426fd47e4..16e5a13625 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -25,8 +25,6 @@ from .hl_api_helper import * import os -import re -import subprocess import webbrowser From 508c008993a5f2ee9c8768de90ec83b451a9d10c Mon Sep 17 00:00:00 2001 From: steffen Date: Fri, 21 Apr 2017 15:39:13 +0200 Subject: [PATCH 12/22] change from review --- pynest/nest/lib/hl_api_helper.py | 8 ++++---- pynest/nest/lib/hl_api_info.py | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index 9414fd271d..6b96617d55 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -464,8 +464,8 @@ def show_help_with_pager(hlpobj, pager): 'Please source nest_vars.sh or define NEST_INSTALL_DIR manually.') return - helpdir = os.path.join(os.environ['NEST_INSTALL_DIR'], - "/share/doc/nest/help/") + helpdir = os.path.join(os.environ['NEST_INSTALL_DIR'], "share", "doc", + "nest", "help") objname = hlpobj + '.hlp' # @todo more pager consolepager = ['less', 'more', 'vi', 'vim', 'nano', 'emacs -nw', @@ -500,14 +500,14 @@ def show_help_with_pager(hlpobj, pager): __show_help_in_modal_window(objname, hlptxt) break else: - subprocess.Popen([pager, objf]) + subprocess.call([pager, objf]) break else: if pager in consolepager: subprocess.call([pager, objf]) break else: - subprocess.Popen([pager, objf]) + subprocess.call([pager, objf]) break diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index 16e5a13625..ee61dacb55 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -24,6 +24,7 @@ """ from .hl_api_helper import * +import sys import os import webbrowser @@ -62,12 +63,14 @@ def helpdesk(): The system default browser. /helpdesk << /command (firefox) >> SetOptions in ~/.nestrc is now obsolete - - @author graber """ - - url = os.environ['NEST_DOC_DIR'] + "/help/helpindex.html" - webbrowser.open_new(url) + url = os.path.join(os.environ['NEST_DOC_DIR'] + "help", "helpindex.html") + if sys.platform[:3] == "win": + os.startfile(url) + if sys.platform[:3] == "dar": + webbrowser.get('safari').open_new(url) + else: + webbrowser.open_new(url) @check_stack From 5d47a8032aa0119b219b25f50eadc269a94d41a2 Mon Sep 17 00:00:00 2001 From: steffen Date: Thu, 4 May 2017 09:47:22 +0200 Subject: [PATCH 13/22] Right URL for nest.helpdesk() --- pynest/nest/lib/hl_api_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index ee61dacb55..7231a38b61 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -64,7 +64,7 @@ def helpdesk(): The system default browser. /helpdesk << /command (firefox) >> SetOptions in ~/.nestrc is now obsolete """ - url = os.path.join(os.environ['NEST_DOC_DIR'] + "help", "helpindex.html") + url = os.path.join(os.environ['NEST_DOC_DIR'] + "/help", "helpindex.html") if sys.platform[:3] == "win": os.startfile(url) if sys.platform[:3] == "dar": From 4e124a39dcb1cec87c86c1db5eaf9f3fbffb72d6 Mon Sep 17 00:00:00 2001 From: steffen Date: Wed, 31 May 2017 13:00:15 +0200 Subject: [PATCH 14/22] Drop todo pager list seems to be complete --- pynest/nest/lib/hl_api_helper.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index 6b96617d55..4e07d6369a 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -467,7 +467,6 @@ def show_help_with_pager(hlpobj, pager): helpdir = os.path.join(os.environ['NEST_INSTALL_DIR'], "share", "doc", "nest", "help") objname = hlpobj + '.hlp' - # @todo more pager consolepager = ['less', 'more', 'vi', 'vim', 'nano', 'emacs -nw', 'ed', 'editor'] From 13caa6487231fc0e64ab8158ef27f977cd3c5cf3 Mon Sep 17 00:00:00 2001 From: steffen Date: Wed, 31 May 2017 13:01:11 +0200 Subject: [PATCH 15/22] Insert inline documentation --- pynest/nest/lib/hl_api_info.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index 7231a38b61..2e99b8ed85 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -61,12 +61,25 @@ def authors(): def helpdesk(): """Open the NEST helpdesk in browser. - The system default browser. - /helpdesk << /command (firefox) >> SetOptions in ~/.nestrc is now obsolete + Use the system default browser. """ + if 'NEST_DOC_DIR' not in os.environ: + print( + 'NEST help needs to know where NEST is installed.' + 'Please source nest_vars.sh or define NEST_DOC_DIR manually.') + return + url = os.path.join(os.environ['NEST_DOC_DIR'] + "/help", "helpindex.html") + """ + Under Windows systems webbrowser.open is incomplete + + """ if sys.platform[:3] == "win": os.startfile(url) + """ + Under MacOs we need to ask for the browser explicitly. + See . + """ if sys.platform[:3] == "dar": webbrowser.get('safari').open_new(url) else: From 89a5abe7e6492f20e8464beccaded2dd29691cf2 Mon Sep 17 00:00:00 2001 From: steffen Date: Wed, 31 May 2017 13:11:59 +0200 Subject: [PATCH 16/22] Set default browser to 'more' --- pynest/nest/lib/hl_api_helper.py | 2 +- pynest/nest/lib/hl_api_info.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index 4e07d6369a..0e0f672685 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -483,7 +483,7 @@ def show_help_with_pager(hlpobj, pager): pager = pypagers[0] break else: - pager = 'less' + pager = 'more' rc.close() for dirpath, dirnames, files in os.walk(helpdir): diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index 2e99b8ed85..1dca2a7bbc 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -90,7 +90,7 @@ def helpdesk(): def help(obj=None, pager=None): """Show the help page for the given object using the given pager. - The default pager is less. + The default pager is more. Parameters ---------- From 148fdb585d9f26c642e2511bdf21c68066a7830f Mon Sep 17 00:00:00 2001 From: steffen Date: Wed, 31 May 2017 15:04:16 +0200 Subject: [PATCH 17/22] Better .nesrc handling --- pynest/nest/lib/hl_api_helper.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index 0e0f672685..66cefd2a92 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -472,19 +472,24 @@ def show_help_with_pager(hlpobj, pager): # reading ~/.nestrc lookink for pager to use. if pager is None: - # open ~/.nestrc - rc = open(os.environ['HOME'] + '/.nestrc', 'r') - for line in rc: - rctst = re.match(r'^\s?%', line) - if rctst is None: - pypagers = re.findall( - r'\s?/page\s?<<\s?/command\s?\((.*)\).*', line) - if pypagers: - pager = pypagers[0] - break - else: - pager = 'more' - rc.close() + # check if .netsrc exist + rc_file = Path(os.environ['HOME'] + '/.nestrc') + if os.path.isfile(rc_file): + # open ~/.nestrc + rc = open(os.environ['HOME'] + '/.nestrc', 'r') + for line in rc: + rctst = re.match(r'^\s?%', line) + if rctst is None: + pypagers = re.findall( + r'^\s?/page\s?<<\s?/command\s?\((\S*)', line) + if pypagers: + pager = pypagers[0] + break + else: + pager = 'more' + rc.close() + else: + pager = 'more' for dirpath, dirnames, files in os.walk(helpdir): for hlp in files: From 4642c8df860296eaa6613589b00ae0da666681d5 Mon Sep 17 00:00:00 2001 From: steffen Date: Thu, 1 Jun 2017 09:56:23 +0200 Subject: [PATCH 18/22] Better inline documentation --- pynest/nest/lib/hl_api_info.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index 1dca2a7bbc..448da950fc 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -70,16 +70,14 @@ def helpdesk(): return url = os.path.join(os.environ['NEST_DOC_DIR'] + "/help", "helpindex.html") - """ - Under Windows systems webbrowser.open is incomplete - - """ + + # Under Windows systems webbrowser.open is incomplete + # See if sys.platform[:3] == "win": os.startfile(url) - """ - Under MacOs we need to ask for the browser explicitly. - See . - """ + + # Under MacOs we need to ask for the browser explicitly. + # See . if sys.platform[:3] == "dar": webbrowser.get('safari').open_new(url) else: From ee5b97dd79a51dddc9ee901e996d733e02fed47a Mon Sep 17 00:00:00 2001 From: steffen Date: Thu, 1 Jun 2017 10:00:31 +0200 Subject: [PATCH 19/22] Improvement of calling the help --- pynest/nest/lib/hl_api_helper.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index 66cefd2a92..98b7e5603c 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -473,7 +473,7 @@ def show_help_with_pager(hlpobj, pager): # reading ~/.nestrc lookink for pager to use. if pager is None: # check if .netsrc exist - rc_file = Path(os.environ['HOME'] + '/.nestrc') + rc_file = os.environ['HOME'] + '/.nestrc' if os.path.isfile(rc_file): # open ~/.nestrc rc = open(os.environ['HOME'] + '/.nestrc', 'r') @@ -481,19 +481,24 @@ def show_help_with_pager(hlpobj, pager): rctst = re.match(r'^\s?%', line) if rctst is None: pypagers = re.findall( - r'^\s?/page\s?<<\s?/command\s?\((\S*)', line) + r'^\s?/page\s?<<\s?/command\s?\((\w*)', line) if pypagers: - pager = pypagers[0] + for pa in pypagers: + if pa: + pager = pa + else: + pager = 'more' break else: pager = 'more' rc.close() else: pager = 'more' - + hlperror = True for dirpath, dirnames, files in os.walk(helpdir): for hlp in files: if hlp == objname: + hlperror = False objf = os.path.join(dirpath, objname) fhlp = open(objf, 'r') hlptxt = fhlp.read() @@ -502,17 +507,23 @@ def show_help_with_pager(hlpobj, pager): if pager in consolepager: # only in notebook open modal window __show_help_in_modal_window(objname, hlptxt) + fhlp.close() break else: subprocess.call([pager, objf]) + fhlp.close() break else: if pager in consolepager: subprocess.call([pager, objf]) + fhlp.close() break else: subprocess.call([pager, objf]) + fhlp.close() break + if hlperror == True: + print("Sorry, there is no help for '" + hlpobj + "'!") @check_stack From 42da7c34b4fc6d0d5650ea58d3de9ba1cd162952 Mon Sep 17 00:00:00 2001 From: steffen Date: Thu, 1 Jun 2017 10:22:10 +0200 Subject: [PATCH 20/22] PEP 8 --- pynest/nest/lib/hl_api_helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index 98b7e5603c..29d5c77ef4 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -522,7 +522,7 @@ def show_help_with_pager(hlpobj, pager): subprocess.call([pager, objf]) fhlp.close() break - if hlperror == True: + if hlperror is True: print("Sorry, there is no help for '" + hlpobj + "'!") From b82fa50502457995f2dd118a2918c61993d4d57c Mon Sep 17 00:00:00 2001 From: steffen Date: Wed, 7 Jun 2017 15:19:47 +0200 Subject: [PATCH 21/22] Documentation --- pynest/nest/lib/hl_api_helper.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index 29d5c77ef4..198115616e 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -476,10 +476,17 @@ def show_help_with_pager(hlpobj, pager): rc_file = os.environ['HOME'] + '/.nestrc' if os.path.isfile(rc_file): # open ~/.nestrc - rc = open(os.environ['HOME'] + '/.nestrc', 'r') + rc = open(rc_file, 'r') + # The loop goes through the .nestrc line by line and checks + # it for the definition of a pager. Whether a pager is + # found or not, this pager is used or the standard pager 'more'. for line in rc: + # the re checks if there are lines beginning with '%' rctst = re.match(r'^\s?%', line) if rctst is None: + # the next re checks for a sth. like + # '/page << /command (more)' + # and returns the given pager. pypagers = re.findall( r'^\s?/page\s?<<\s?/command\s?\((\w*)', line) if pypagers: @@ -495,6 +502,8 @@ def show_help_with_pager(hlpobj, pager): else: pager = 'more' hlperror = True + # Searching the given object in all helpfiles, check the environment + # and display the helptext in the pager. for dirpath, dirnames, files in os.walk(helpdir): for hlp in files: if hlp == objname: @@ -522,7 +531,7 @@ def show_help_with_pager(hlpobj, pager): subprocess.call([pager, objf]) fhlp.close() break - if hlperror is True: + if hlperror: print("Sorry, there is no help for '" + hlpobj + "'!") From a86a32cf75c7fbc46f1d744782054a8a6b29f7cc Mon Sep 17 00:00:00 2001 From: steffen Date: Fri, 9 Jun 2017 10:54:05 +0200 Subject: [PATCH 22/22] Removed string concatenation Minor Fix. --- pynest/nest/lib/hl_api_helper.py | 2 +- pynest/nest/lib/hl_api_info.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pynest/nest/lib/hl_api_helper.py b/pynest/nest/lib/hl_api_helper.py index 198115616e..4ad8a798ba 100644 --- a/pynest/nest/lib/hl_api_helper.py +++ b/pynest/nest/lib/hl_api_helper.py @@ -473,7 +473,7 @@ def show_help_with_pager(hlpobj, pager): # reading ~/.nestrc lookink for pager to use. if pager is None: # check if .netsrc exist - rc_file = os.environ['HOME'] + '/.nestrc' + rc_file = os.path.join(os.environ['HOME'], '.nestrc') if os.path.isfile(rc_file): # open ~/.nestrc rc = open(rc_file, 'r') diff --git a/pynest/nest/lib/hl_api_info.py b/pynest/nest/lib/hl_api_info.py index 448da950fc..9d3da1db75 100644 --- a/pynest/nest/lib/hl_api_info.py +++ b/pynest/nest/lib/hl_api_info.py @@ -69,19 +69,20 @@ def helpdesk(): 'Please source nest_vars.sh or define NEST_DOC_DIR manually.') return - url = os.path.join(os.environ['NEST_DOC_DIR'] + "/help", "helpindex.html") + helpfile = os.path.join(os.environ['NEST_DOC_DIR'], 'help', + 'helpindex.html') # Under Windows systems webbrowser.open is incomplete # See if sys.platform[:3] == "win": - os.startfile(url) + os.startfile(helpfile) # Under MacOs we need to ask for the browser explicitly. # See . if sys.platform[:3] == "dar": - webbrowser.get('safari').open_new(url) + webbrowser.get('safari').open_new(helpfile) else: - webbrowser.open_new(url) + webbrowser.open_new(helpfile) @check_stack