[pytango] 50/483: prepare for ipython 0.11

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:14:23 UTC 2017


This is an automated email from the git hooks/post-receive script.

sbodomerle-guest pushed a commit to annotated tag bliss_8.10
in repository pytango.

commit 6213142f3c61fb9c4c7863f5792d17ead77dd998
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date:   Fri Nov 4 08:22:07 2011 +0000

    prepare for ipython 0.11
    
    git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@18287 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
 PyTango/ipython/__init__.py                        |  4 +-
 PyTango/ipython/ipython.py                         | 78 ++++++++++------------
 PyTango/ipython/{ => ipython_00_10}/__init__.py    |  3 +-
 PyTango/ipython/{ => ipython_00_10}/ipy_cli.py     |  0
 PyTango/ipython/{ => ipython_00_10}/ipy_install.py |  0
 PyTango/ipython/{ => ipython_00_10}/ipy_qt.py      |  0
 .../{__init__.py => ipython_00_10/ipy_utils.py}    | 20 +++++-
 .../ipython/{ => ipython_00_10}/ipython_00_10.py   |  1 -
 PyTango/ipython/{ => ipython_00_11}/__init__.py    |  3 +-
 PyTango/ipython/{ => ipython_00_11}/ipy_install.py | 26 ++++----
 .../ipython_00_11.py}                              | 59 ++++++++--------
 setup.py                                           |  1 +
 12 files changed, 98 insertions(+), 97 deletions(-)

diff --git a/PyTango/ipython/__init__.py b/PyTango/ipython/__init__.py
index 1e66fc4..8988752 100644
--- a/PyTango/ipython/__init__.py
+++ b/PyTango/ipython/__init__.py
@@ -21,6 +21,4 @@
 ##
 ################################################################################
 
-from ipython import *
-
-from ipy_install import install
\ No newline at end of file
+from ipython import init_ipython, install
diff --git a/PyTango/ipython/ipython.py b/PyTango/ipython/ipython.py
index f974030..2645251 100644
--- a/PyTango/ipython/ipython.py
+++ b/PyTango/ipython/ipython.py
@@ -21,6 +21,8 @@
 ##
 ################################################################################
 
+__all__ = ["init_ipython", "install"]
+
 import os
 
 try:
@@ -45,52 +47,44 @@ def get_ipython_version():
         pass
     return v
 
-def default_init_ipython(ip, store=True, pytango=True, colors=True, console=True, magic=True):
-    print "Unsupported IPython version (%s) for spock profile" % get_ipython_version()
-    print "Supported IPython versions are: 0.10"
-    print "Starting normal IPython console..."
-
-def __define_init():
-    _ipv_str = get_ipython_version()
+def get_ipython_version_list():
+    ipv_str = get_ipython_version()
 
-    if _ipv_str is None:
-        _ipv = 0,0
+    if ipv_str is None:
+        ipv = [0, 0]
     else:
-        _ipv = tuple(map(int,_ipv_str.split(".")[:3]))
+        ipv = []
+        for i in ipv_str.split(".")[:2]:
+            try:
+                i = int(i)
+            except:
+                i = 0
+            ipv.append(i)
+    return ipv
 
-    ret = default_init_ipython
-    if _ipv >= (0,10) and _ipv <= (0,11):
-        import ipython_00_10
-        ret = ipython_00_10.init_ipython
-    return ret
+def default_init_ipython(ip, store=True, pytango=True, colors=True,
+                         console=True, magic=True):
+    print "Unsupported IPython version (%s) for spock profile" \
+        % get_ipython_version()
+    print "Supported IPython versions are: 0.10"
+    print "Starting normal IPython console..."
 
-def get_ipython_dir():
-    """Find the ipython local directory. Usually is <home>/.ipython"""
-    if hasattr(ipython.iplib, 'get_ipython_dir'):
-        # Starting from ipython 0.9 they hadded this method
-        return ipython.iplib.get_ipython_dir()
-    
-    # Try to find the profile in the current directory and then in the 
-    # default IPython dir
-    home_dir = ipython.genutils.get_home_dir()
+def default_install(ipydir=None, verbose=True):
+    print "Unsupported IPython version (%s) for spock profile" \
+        % get_ipython_version()
+    print "Supported IPython versions are: 0.10"
+    print "Tango extension to IPyhon will NOT be installed."
     
-    if os.name == 'posix':
-        ipdir = '.ipython'
-    else:
-        ipdir = '_ipython'
-    ipdir = os.path.join(home_dir, ipdir)
-    ipythondir = os.path.abspath( os.environ.get('IPYTHONDIR', ipdir) )
-    return ipythondir
-
-def get_ipython_profiles():
-    """Helper functions to find ipython profiles"""
-    ret = []
-    ipydir = get_ipython_dir()
-    if os.path.isdir(ipydir):
-        for i in os.listdir(ipydir):
-            if i.startswith("ipy_profile_") and i.endswith(".py") and \
-                os.path.isfile(i):
-                ret.append(i[len("ipy_profile_"):i.rfind(".")])
+def __define():
+    ipv = get_ipython_version_list()
+    ret = default_init_ipython, default_install
+    if ipv >= [0, 10] and ipv < [0, 11]:
+        import ipython_00_10
+        ret = ipython_00_10.init_ipython, ipython_00_10.install
+    elif ipv >= [0, 11] and ipv <= [0, 12]:
+        import ipython_00_11
+        ret = ipython_00_11.init_ipython, ipython_00_11.install        
     return ret
+    
+init_ipython, install = __define()
 
-init_ipython = __define_init()
diff --git a/PyTango/ipython/__init__.py b/PyTango/ipython/ipython_00_10/__init__.py
similarity index 93%
copy from PyTango/ipython/__init__.py
copy to PyTango/ipython/ipython_00_10/__init__.py
index 1e66fc4..f3f1841 100644
--- a/PyTango/ipython/__init__.py
+++ b/PyTango/ipython/ipython_00_10/__init__.py
@@ -21,6 +21,5 @@
 ##
 ################################################################################
 
-from ipython import *
-
+from ipython_00_10 import init_ipython
 from ipy_install import install
\ No newline at end of file
diff --git a/PyTango/ipython/ipy_cli.py b/PyTango/ipython/ipython_00_10/ipy_cli.py
similarity index 100%
rename from PyTango/ipython/ipy_cli.py
rename to PyTango/ipython/ipython_00_10/ipy_cli.py
diff --git a/PyTango/ipython/ipy_install.py b/PyTango/ipython/ipython_00_10/ipy_install.py
similarity index 100%
copy from PyTango/ipython/ipy_install.py
copy to PyTango/ipython/ipython_00_10/ipy_install.py
diff --git a/PyTango/ipython/ipy_qt.py b/PyTango/ipython/ipython_00_10/ipy_qt.py
similarity index 100%
rename from PyTango/ipython/ipy_qt.py
rename to PyTango/ipython/ipython_00_10/ipy_qt.py
diff --git a/PyTango/ipython/__init__.py b/PyTango/ipython/ipython_00_10/ipy_utils.py
similarity index 64%
copy from PyTango/ipython/__init__.py
copy to PyTango/ipython/ipython_00_10/ipy_utils.py
index 1e66fc4..5e0649f 100644
--- a/PyTango/ipython/__init__.py
+++ b/PyTango/ipython/ipython_00_10/ipy_utils.py
@@ -21,6 +21,22 @@
 ##
 ################################################################################
 
-from ipython import *
+import os
 
-from ipy_install import install
\ No newline at end of file
+import IPython
+ipython = IPython
+
+def get_ipython_dir():
+    """Find the ipython local directory. Usually is <home>/.ipython"""
+    return ipython.iplib.get_ipython_dir()
+
+def get_ipython_profiles():
+    """Helper functions to find ipython profiles"""
+    ret = []
+    ipydir = get_ipython_dir()
+    if os.path.isdir(ipydir):
+        for i in os.listdir(ipydir):
+            if i.startswith("ipy_profile_") and i.endswith(".py") and \
+                os.path.isfile(i):
+                ret.append(i[len("ipy_profile_"):i.rfind(".")])
+    return ret
\ No newline at end of file
diff --git a/PyTango/ipython/ipython_00_10.py b/PyTango/ipython/ipython_00_10/ipython_00_10.py
similarity index 99%
copy from PyTango/ipython/ipython_00_10.py
copy to PyTango/ipython/ipython_00_10/ipython_00_10.py
index 157c3a6..bc17d92 100644
--- a/PyTango/ipython/ipython_00_10.py
+++ b/PyTango/ipython/ipython_00_10/ipython_00_10.py
@@ -762,7 +762,6 @@ def init_pytango(ip):
     ip.set_hook('complete_command', attr_completer, re_key = ".*AttributeProxy[^\w\.]+")
     ip.set_hook('complete_command', attr_completer, re_key = ".*Attribute[^\w\.]+")
     
-    ip
     ip.set_custom_exc((PyTango.DevFailed,), __tango_exc_handler)
 
 def init_db(ip, parameter_s=''):
diff --git a/PyTango/ipython/__init__.py b/PyTango/ipython/ipython_00_11/__init__.py
similarity index 93%
copy from PyTango/ipython/__init__.py
copy to PyTango/ipython/ipython_00_11/__init__.py
index 1e66fc4..2ad2bbe 100644
--- a/PyTango/ipython/__init__.py
+++ b/PyTango/ipython/ipython_00_11/__init__.py
@@ -21,6 +21,5 @@
 ##
 ################################################################################
 
-from ipython import *
-
+from ipython_00_11 import init_ipython
 from ipy_install import install
\ No newline at end of file
diff --git a/PyTango/ipython/ipy_install.py b/PyTango/ipython/ipython_00_11/ipy_install.py
similarity index 82%
rename from PyTango/ipython/ipy_install.py
rename to PyTango/ipython/ipython_00_11/ipy_install.py
index 8e4ae69..97630e4 100644
--- a/PyTango/ipython/ipy_install.py
+++ b/PyTango/ipython/ipython_00_11/ipy_install.py
@@ -27,7 +27,7 @@ import sys
 import os
 import StringIO
 
-import IPython.genutils
+import IPython
 import PyTango
 
 __PROFILE = """\
@@ -36,16 +36,11 @@ __PROFILE = """\
 friendly interface to Tango.
 Created with PyTango {pytangover} for IPython {ipyver}\"\"\"
 
-import IPython
-import PyTango.ipython
-
-ip = IPython.ipapi.get()
-PyTango.ipython.init_ipython(ip)
-
+PyTango.ipython.init_ipython()
 """
 
 def install(ipydir=None,verbose=True):
-    install_dir = ipydir or IPython.genutils.get_ipython_dir()
+    install_dir = ipydir or IPython.core.path.get_ipython_dir()
     f_name = os.path.join(install_dir, 'ipy_profile_spock.py')
     if verbose:
         out = sys.stdout
@@ -59,7 +54,8 @@ def install(ipydir=None,verbose=True):
             r = r or 'y'
         if r.lower() == 'n':
             return
-    profile = __PROFILE.format(pytangover=PyTango.Release.version, ipyver=IPython.Release.version)
+    profile = __PROFILE.format(pytangover=PyTango.Release.version,
+                               ipyver=IPython.release.version)
     
     out.write("Installing spock extension to ipython... ")
     out.flush()
@@ -72,7 +68,8 @@ def install(ipydir=None,verbose=True):
         out.write("[FAILED]\n\n")
         raise e
     
-    ipy_user_config = os.path.join(IPython.genutils.get_ipython_dir(), 'ipy_user_conf.py')
+    d = IPython.core.path.get_ipython_dir()
+    ipy_user_config = os.path.join(d, 'ipy_user_conf.py')
     out.write("""\
 To start spock simply type on the command line:
 %% ipython -p spock
@@ -84,11 +81,12 @@ import ipy_profile_spock
 Next time, just start ipython on the command line:
 %% ipython
 
-and your spock extension should be loaded automaticaly. Note that if you are also
-loading other extensions that, for example, overwrite the prompt, the prompt
-that will appear is the one from the last extension to be imported.
+and your spock extension should be loaded automaticaly. Note that if you are
+also loading other extensions that, for example, overwrite the prompt, the
+prompt that will appear is the one from the last extension to be imported.
 
-For more information goto: http://www.tango-controls.org/static/PyTango/latest/doc/html/index.html
+For more information goto:
+http://www.tango-controls.org/static/PyTango/latest/doc/html/
 
 Have fun with spock!
 The PyTango team
diff --git a/PyTango/ipython/ipython_00_10.py b/PyTango/ipython/ipython_00_11/ipython_00_11.py
similarity index 95%
rename from PyTango/ipython/ipython_00_10.py
rename to PyTango/ipython/ipython_00_11/ipython_00_11.py
index 157c3a6..f1fdc24 100644
--- a/PyTango/ipython/ipython_00_10.py
+++ b/PyTango/ipython/ipython_00_11/ipython_00_11.py
@@ -30,13 +30,16 @@ import os
 import re
 import StringIO
 import textwrap
-import IPython.ipapi
 import IPython.ColorANSI
 import IPython.Prompts
 import IPython.PyColorize
 import IPython.excolors
 import IPython.ipstruct
 import IPython.genutils
+
+from IPython.core import ipapi
+from IPython.core.error import UsageError
+
 import PyTango
 import PyTango.utils
 
@@ -79,7 +82,7 @@ class DeviceClassCompleter(object):
 def __DeviceProxy_completer(ip, evt):
     db = __get_db()
     if db is None: return
-    ret = db._db_cache.devices.keys()
+    ret = db._db_cache.deviIPyhces.keys()
     ret.extend(db._db_cache.aliases.keys())
     return ret
 
@@ -163,7 +166,7 @@ def __AttributeProxy_completer(ip, evt):
 def __get_device_proxy(dev_name):
     db = __get_db()
     if db is None: return
-    cache = db._db_cache
+    cache = db._db_cacheIPyh
     from_alias = cache.aliases.get(dev_name)
     
     if from_alias is not None:
@@ -202,7 +205,7 @@ __monitor_completer = __AttributeProxy_completer
 #-------------------------------------------------------------------------------
 
 def magic_refreshdb(self, parameter_s=''):
-    init_db(IPython.ipapi.get(), parameter_s)
+    init_db(ipapi.get(), parameter_s)
 
 def magic_switchdb(self, parameter_s=''):
     """Switches the active tango Database.
@@ -217,8 +220,9 @@ def magic_switchdb(self, parameter_s=''):
     In [3]: switchdb homer"""
     
     if parameter_s == '':
-        raise IPython.ipapi.UsageError("%switchdb: Must specify a tango database name. See '%switchdb?'")
-    return init_db(IPython.ipapi.get(), parameter_s)
+        raise UsageError("%switchdb: Must specify a tango database name. "\
+                         "See '%switchdb?'")
+    return init_db(ipapi.get(), parameter_s)
 
 def magic_lsdev(self, parameter_s=''):
     """Lists all known tango devices.
@@ -316,7 +320,7 @@ _EVT_LOG = None
 def __get_event_log():
     global _EVT_LOG
     if _EVT_LOG is None:
-        qthreads = IPython.ipapi.get().options.q4thread
+        qthreads = ipapi.get().options.q4thread
         if qthreads:
             import ipy_qt
             model = ipy_qt.EventLoggerTableModel(capacity=10000)
@@ -343,13 +347,12 @@ def magic_mon(self, parameter_s=''):
         return
     opts, args = self.parse_options(parameter_s,'adril', mode='list')
     if len(args) > 3:
-        raise IPython.ipapi.UsageError("%mon: too many arguments")
+        raise UsageError("%mon: too many arguments")
     if opts.has_key('d'):
         try:
             todel = args[0]
         except IndexError:
-            raise IPython.ipapi.UsageError(
-                "%mon -d: must provide an attribute to unmonitor")
+            raise UsageError("%mon -d: must provide an attribute to unmonitor")
         else:
             try:
                 dev, sep, attr = todel.rpartition("/")
@@ -360,21 +363,18 @@ def magic_mon(self, parameter_s=''):
                 d.unsubscribe_event(id)
                 print "Stopped monitoring '%s'" % todel
             except KeyError:
-                raise IPython.ipapi.UsageError(
-                    "%%mon -d: Not monitoring '%s'" % todel)
+                raise UsageError("%%mon -d: Not monitoring '%s'" % todel)
                     
     elif opts.has_key('a'):
         try:
             toadd = args[0]
         except IndexError:
-            raise IPython.ipapi.UsageError(
-                "%mon -a: must provide an attribute to monitor")
+            raise UsageError("%mon -a: must provide an attribute to monitor")
         dev, sep, attr = toadd.rpartition("/")
         subscriptions = __get_device_subscriptions(dev)
         id = subscriptions.get(attr.lower())
         if id is not None:
-            raise IPython.ipapi.UsageError(
-                "%%mon -a: Already monitoring '%s'" % toadd)
+            raise UsageError("%%mon -a: Already monitoring '%s'" % toadd)
         d = __get_device_proxy(dev)
         w = __get_event_log()
         model = w.model()
@@ -391,11 +391,9 @@ def magic_mon(self, parameter_s=''):
         try:
             evtid = int(args[0])
         except IndexError:
-            raise IPython.ipapi.UsageError(
-                "%mon -i: must provide an event ID")
+            raise UsageError("%mon -i: must provide an event ID")
         except ValueError:
-            raise IPython.ipapi.UsageError(
-                "%mon -i: must provide a valid event ID")
+            raise UsageError("%mon -i: must provide a valid event ID")
         try:
             w = __get_event_log()
             e = w.getEvents()[evtid]
@@ -404,15 +402,14 @@ def magic_mon(self, parameter_s=''):
             else:
                 print str(e)
         except IndexError:
-            raise IPython.ipapi.UsageError(
-                "%mon -i: must provide a valid event ID")
+            raise UsageError("%mon -i: must provide a valid event ID")
     elif opts.has_key('l'):
         try:
             dexpr = args[0]
             aexpr = args[1]
         except IndexError:
-            raise IPython.ipapi.UsageError(
-                "%mon -l: must provide valid device and attribute filters")
+            raise UsageError("%mon -l: must provide valid device and " \
+                             "attribute filters")
         w = __get_event_log()
         w.show(dexpr, aexpr)
     else:
@@ -531,7 +528,7 @@ def __get_db(host_port=None):
                           and return it
     """
     
-    ip = IPython.ipapi.get()
+    ip = ipapi.get()
     global _DB_SYMB
     db = ip.user_ns.get(_DB_SYMB)
     
@@ -593,7 +590,7 @@ def __completer_wrapper(f):
             print
             print "An unexpected exception ocorred during Spock command completer."
             print "Please send a bug report to the PyTango team with the following informantion:"
-            print IPython.ipapi.get().options.banner
+            print ipapi.get().options.banner
             print 80*"-"
             print "Completer:",__get_obj_name(f)
             print 80*"-"
@@ -625,7 +622,7 @@ def __get_pytango_version():
     return ".".join(map(str,vi[:3]))+vi[3]
 
 def __get_ipapi():
-    return IPython.ipapi.get()
+    return ipapi.get()
 
 def __expose_magic(ip, name, fn, completer_func=None):
     ip.expose_magic(name, fn)
@@ -762,7 +759,6 @@ def init_pytango(ip):
     ip.set_hook('complete_command', attr_completer, re_key = ".*AttributeProxy[^\w\.]+")
     ip.set_hook('complete_command', attr_completer, re_key = ".*Attribute[^\w\.]+")
     
-    ip
     ip.set_custom_exc((PyTango.DevFailed,), __tango_exc_handler)
 
 def init_db(ip, parameter_s=''):
@@ -946,7 +942,7 @@ def init_magic(ip):
 
 def complete(text):
     """a super complete!!!!"""
-    self = IPython.ipapi.get().IP
+    self = ipapi.get().IP
     complete = self.Completer.complete
     state = 0
     comps = set()
@@ -959,10 +955,11 @@ def complete(text):
     outcomps = sorted(comps)
     return outcomps
 
-def init_ipython(ip, store=True, pytango=True, colors=True, console=True, magic=True):
+def init_ipython(ip=None, store=True, pytango=True, colors=True, console=True,
+                 magic=True):
     
     if ip is None:
-        raise Exception("Spock's init_ipython must be called from inside IPython")
+        ip = ipapi.get()
     
     global _spock_init
     if _spock_init is True: return
diff --git a/setup.py b/setup.py
index 6ea4af0..dbee658 100644
--- a/setup.py
+++ b/setup.py
@@ -239,6 +239,7 @@ def main():
     packages = [
         'PyTango',
         'PyTango.ipython',
+        'PyTango.ipython.ipython_00_10',
     ]
 
     py_modules = []

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git



More information about the debian-science-commits mailing list