[pytango] 63/98: Add PyTango module for backward compatibility

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


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

sbodomerle-guest pushed a commit to tag v9.2.0
in repository pytango.

commit 60723bbdb7e9c481c1f44072fe1b43d1a95e031e
Author: Vincent Michel <vincent.michel at maxlab.lu.se>
Date:   Fri Jul 8 16:30:40 2016 +0200

    Add PyTango module for backward compatibility
---
 PyTango.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/PyTango.py b/PyTango.py
new file mode 100644
index 0000000..dfb51c5
--- /dev/null
+++ b/PyTango.py
@@ -0,0 +1,50 @@
+"""Provides PyTango as a module for backward compatibility."""
+
+# Imports
+import sys
+import tango
+import pkgutil
+import warnings
+
+
+def alias_package(package, alias, extra_modules={}):
+    """Alias a python package properly.
+
+    It ensures that modules are not duplicated by trying
+    to import and alias all the submodules recursively.
+    """
+    path = package.__path__
+    alias_prefix = alias + '.'
+    prefix = package.__name__ + '.'
+    # Alias all importable modules recursively
+    for _, name, _ in pkgutil.walk_packages(path, prefix):
+        try:
+            if name not in sys.modules:
+                __import__(name)
+        except ImportError:
+            continue
+        alias_name = name.replace(prefix, alias_prefix)
+        sys.modules[alias_name] = sys.modules[name]
+    # Alias extra modules
+    for key, value in extra_modules.items():
+        name = prefix + value
+        if name not in sys.modules:
+            __import__(name)
+        if not hasattr(package, key):
+            setattr(package, key, sys.modules[name])
+        sys.modules[alias_prefix + key] = sys.modules[name]
+    # Alias root module
+    sys.modules[alias] = sys.modules[package.__name__]
+
+
+# Do not flood pytango users console with warnings yet
+# warnings.warn('PyTango module is deprecated, import tango instead.')
+
+# Alias tango package
+alias_package(
+    package=tango,
+    alias=__name__,
+    extra_modules={
+        '_PyTango': '_tango',
+        'constants': 'constants'},
+)

-- 
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