]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/__init__.py
src/allmydata/__init__.py: ensure that if a dependency cannot be imported, we will...
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / __init__.py
index 45484b2ca31426fd7bfb8aaea38776951c41fc66..ff9a8fbfd371acfee90a24f13450264c1f060d2c 100644 (file)
@@ -1,7 +1,7 @@
 """
 Decentralized storage grid.
 
-community web site: U{http://tahoe-lafs.org/}
+community web site: U{https://tahoe-lafs.org/}
 """
 
 class PackagingError(EnvironmentError):
@@ -29,7 +29,7 @@ except ImportError:
 
 # __full_version__ is the one that you ought to use when identifying yourself in the
 # "application" part of the Tahoe versioning scheme:
-# http://allmydata.org/trac/tahoe-lafs/wiki/Versioning
+# https://tahoe-lafs.org/trac/tahoe-lafs/wiki/Versioning
 __full_version__ = __appname__ + '/' + str(__version__)
 
 import os, platform, re, subprocess, sys, traceback
@@ -144,8 +144,8 @@ def normalized_version(verstr, what=None):
 
 def get_package_versions_and_locations():
     import warnings
-    from _auto_deps import package_imports, deprecation_messages, \
-        user_warning_messages, warning_imports
+    from _auto_deps import package_imports, global_deprecation_messages, deprecation_messages, \
+        user_warning_messages, runtime_warning_messages, warning_imports
 
     def package_dir(srcfile):
         return os.path.dirname(os.path.dirname(os.path.normcase(os.path.realpath(srcfile))))
@@ -155,21 +155,15 @@ def get_package_versions_and_locations():
     # or any other bug that causes sys.path to be set up incorrectly. Therefore we
     # must import the packages in order to check their versions and paths.
 
-    # This warning is generated by twisted, PyRex, and possibly other packages,
-    # but can happen at any time, not only when they are imported. See
-    # http://tahoe-lafs.org/trac/tahoe-lafs/ticket/1129 .
-    warnings.filterwarnings("ignore", category=DeprecationWarning,
-        message="BaseException.message has been deprecated as of Python 2.6",
-        append=True)
+    # This is to suppress various DeprecationWarnings, UserWarnings, and RuntimeWarnings
+    # (listed in _auto_deps.py).
 
-    # This is to suppress various DeprecationWarnings and UserWarnings that
-    # occur when modules are imported.  See #859, #1435 and
-    # http://divmod.org/trac/ticket/2994 .
-
-    for msg in deprecation_messages:
+    for msg in global_deprecation_messages + deprecation_messages:
         warnings.filterwarnings("ignore", category=DeprecationWarning, message=msg, append=True)
     for msg in user_warning_messages:
         warnings.filterwarnings("ignore", category=UserWarning, message=msg, append=True)
+    for msg in runtime_warning_messages:
+        warnings.filterwarnings("ignore", category=RuntimeWarning, message=msg, append=True)
     try:
         for modulename in warning_imports:
             try:
@@ -177,9 +171,8 @@ def get_package_versions_and_locations():
             except ImportError:
                 pass
     finally:
-        for ign in user_warning_messages:
-            warnings.filters.pop()
-        for ign in deprecation_messages:
+        # Leave suppressions for global_deprecation_messages active.
+        for ign in runtime_warning_messages + user_warning_messages + deprecation_messages:
             warnings.filters.pop()
 
     packages = []
@@ -197,15 +190,11 @@ def get_package_versions_and_locations():
                 trace_info = (etype, str(emsg), ([None] + traceback.extract_tb(etrace))[-1])
                 packages.append( (pkgname, (None, None, trace_info)) )
             else:
-                if 'sqlite' in pkgname:
-                    packages.append( (pkgname, (get_version(module, 'version'), package_dir(module.__file__),
-                                               'sqlite %s' % (get_version(module, 'sqlite_version'),))) )
-                else:
-                    comment = None
-                    if pkgname == 'setuptools' and hasattr(module, '_distribute'):
-                        # distribute does not report its version in any module variables
-                        comment = 'distribute'
-                    packages.append( (pkgname, (get_version(module, '__version__'), package_dir(module.__file__), comment)) )
+                comment = None
+                if pkgname == 'setuptools' and hasattr(module, '_distribute'):
+                    # distribute does not report its version in any module variables
+                    comment = 'distribute'
+                packages.append( (pkgname, (get_version(module, '__version__'), package_dir(module.__file__), comment)) )
         elif pkgname == 'python':
             packages.append( (pkgname, (platform.python_version(), sys.executable, None)) )
         elif pkgname == 'platform':
@@ -280,9 +269,9 @@ def cross_check(pkg_resources_vers_and_locs, imported_vers_and_locs_list):
     """This function returns a list of errors due to any failed cross-checks."""
 
     errors = []
-    not_pkg_resourceable = set(['sqlite3', 'python', 'platform', __appname__.lower()])
+    not_pkg_resourceable = set(['python', 'platform', __appname__.lower()])
     not_import_versionable = set(['zope.interface', 'mock', 'pyasn1'])
-    ignorable = set(['argparse', 'pyutil', 'zbase32', 'distribute', 'twisted-web', 'twisted-core'])
+    ignorable = set(['argparse', 'pyutil', 'zbase32', 'distribute', 'twisted-web', 'twisted-core', 'twisted-conch'])
 
     for name, (imp_ver, imp_loc, imp_comment) in imported_vers_and_locs_list:
         name = name.lower()
@@ -302,6 +291,12 @@ def cross_check(pkg_resources_vers_and_locs, imported_vers_and_locs_list):
                 continue
 
             pr_ver, pr_loc = pkg_resources_vers_and_locs[name]
+            if imp_ver is None and imp_loc is None:
+                errors.append("Warning: dependency %r could not be imported. pkg_resources thought it should be possible "
+                              "to import version %r from %r.\nThe exception trace was %r."
+                              % (name, pr_ver, pr_loc, imp_comment))
+                continue
+
             try:
                 pr_normver = normalized_version(pr_ver)
             except Exception, e:
@@ -362,24 +357,15 @@ def check_all_requirements():
 
     errors = []
 
-    # we require 2.4.4 on non-UCS-2, non-Redhat builds to avoid <http://www.python.org/news/security/PSF-2006-001/>
-    # we require 2.4.3 on non-UCS-2 Redhat, because 2.4.3 is common on Redhat-based distros and will have patched the above bug
-    # we require at least 2.4.2 in any case to avoid a bug in the base64 module: <http://bugs.python.org/issue1171487>
-    if sys.maxunicode == 65535:
-        if sys.version_info < (2, 4, 2) or sys.version_info[0] > 2:
-            errors.append("Tahoe-LAFS current requires Python v2.4.2 or greater "
-                          "for a UCS-2 build (but less than v3), not %r" %
-                          (sys.version_info,))
-    elif platform.platform().lower().find('redhat') >= 0:
-        if sys.version_info < (2, 4, 3) or sys.version_info[0] > 2:
-            errors.append("Tahoe-LAFS current requires Python v2.4.3 or greater "
-                          "on Redhat-based distributions (but less than v3), not %r" %
-                          (sys.version_info,))
-    else:
-        if sys.version_info < (2, 4, 4) or sys.version_info[0] > 2:
-            errors.append("Tahoe-LAFS current requires Python v2.4.4 or greater "
-                          "for a non-UCS-2 build (but less than v3), not %r" %
-                          (sys.version_info,))
+    # We require at least 2.5 on all platforms.
+    # (On Python 3, we'll have failed long before this point.)
+    if sys.version_info < (2, 5):
+        try:
+            version_string = ".".join(map(str, sys.version_info))
+        except Exception:
+            version_string = repr(sys.version_info)
+        errors.append("Tahoe-LAFS current requires Python v2.5 or greater (but less than v3), not %s"
+                      % (version_string,))
 
     vers_and_locs = dict(_vers_and_locs_list)
     for requirement in install_requires:
@@ -410,7 +396,7 @@ def get_package_versions_string(show_paths=False, debug=False):
             info = info + " (%s)" % str(loc)
         res.append(info)
 
-    output = ",\n".join(res) + "\n"
+    output = "\n".join(res) + "\n"
 
     if not hasattr(sys, 'frozen'):
         errors = cross_check_pkg_resources_versus_import()