2007-04-19 20:47:59 +00:00
|
|
|
"""
|
2007-04-30 20:06:09 +00:00
|
|
|
Decentralized storage grid.
|
2007-04-19 20:47:59 +00:00
|
|
|
|
2010-06-03 06:35:30 +00:00
|
|
|
community web site: U{http://tahoe-lafs.org/}
|
2007-04-19 20:47:59 +00:00
|
|
|
"""
|
|
|
|
|
2011-01-21 05:36:10 +00:00
|
|
|
class PackagingError(EnvironmentError):
|
|
|
|
"""
|
|
|
|
Raised when there is an error in packaging of Tahoe-LAFS or its
|
|
|
|
dependencies which makes it impossible to proceed safely.
|
|
|
|
"""
|
|
|
|
pass
|
2010-05-23 22:11:57 +00:00
|
|
|
|
2007-05-04 03:14:07 +00:00
|
|
|
__version__ = "unknown"
|
|
|
|
try:
|
2010-02-26 08:14:33 +00:00
|
|
|
from allmydata._version import __version__
|
2007-05-04 03:14:07 +00:00
|
|
|
except ImportError:
|
2008-01-22 17:22:51 +00:00
|
|
|
# We're running in a tree that hasn't run "./setup.py darcsver", and didn't
|
|
|
|
# come with a _version.py, so we don't know what our version is. This should
|
|
|
|
# not happen very often.
|
2007-05-04 03:14:07 +00:00
|
|
|
pass
|
2007-04-19 20:47:59 +00:00
|
|
|
|
versioning: include an "appname" in the application version string in the versioning protocol, and make that appname be controlled by setup.py
It is currently hardcoded in setup.py to be 'allmydata-tahoe'. Ticket #556 is to make it configurable by a runtime command-line argument to setup.py: "--appname=foo", but I suddenly wondered if we really wanted that and at the same time realized that we don't need that for tahoe-1.3.0 release, so this patch just hardcodes it in setup.py.
setup.py inspects a file named 'src/allmydata/_appname.py' and assert that it contains the string "__appname__ = 'allmydata-tahoe'", and creates it if it isn't already present. src/allmydata/__init__.py import _appname and reads __appname__ from it. The rest of the Python code imports allmydata and inspects "allmydata.__appname__", although actually every use it uses "allmydata.__full_version__" instead, where "allmydata.__full_version__" is created in src/allmydata/__init__.py to be:
__full_version__ = __appname + '-' + str(__version__).
All the code that emits an "application version string" when describing what version of a protocol it supports (introducer server, storage server, upload helper), or when describing itself in general (introducer client), usese allmydata.__full_version__.
This fixes ticket #556 at least well enough for tahoe-1.3.0 release.
2009-02-12 00:18:16 +00:00
|
|
|
__appname__ = "unknown"
|
|
|
|
try:
|
2010-02-26 08:14:33 +00:00
|
|
|
from allmydata._appname import __appname__
|
versioning: include an "appname" in the application version string in the versioning protocol, and make that appname be controlled by setup.py
It is currently hardcoded in setup.py to be 'allmydata-tahoe'. Ticket #556 is to make it configurable by a runtime command-line argument to setup.py: "--appname=foo", but I suddenly wondered if we really wanted that and at the same time realized that we don't need that for tahoe-1.3.0 release, so this patch just hardcodes it in setup.py.
setup.py inspects a file named 'src/allmydata/_appname.py' and assert that it contains the string "__appname__ = 'allmydata-tahoe'", and creates it if it isn't already present. src/allmydata/__init__.py import _appname and reads __appname__ from it. The rest of the Python code imports allmydata and inspects "allmydata.__appname__", although actually every use it uses "allmydata.__full_version__" instead, where "allmydata.__full_version__" is created in src/allmydata/__init__.py to be:
__full_version__ = __appname + '-' + str(__version__).
All the code that emits an "application version string" when describing what version of a protocol it supports (introducer server, storage server, upload helper), or when describing itself in general (introducer client), usese allmydata.__full_version__.
This fixes ticket #556 at least well enough for tahoe-1.3.0 release.
2009-02-12 00:18:16 +00:00
|
|
|
except ImportError:
|
|
|
|
# We're running in a tree that hasn't run "./setup.py". This shouldn't happen.
|
|
|
|
pass
|
|
|
|
|
|
|
|
# __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/wiki/Versioning
|
2009-02-13 05:37:38 +00:00
|
|
|
__full_version__ = __appname__ + '/' + str(__version__)
|
versioning: include an "appname" in the application version string in the versioning protocol, and make that appname be controlled by setup.py
It is currently hardcoded in setup.py to be 'allmydata-tahoe'. Ticket #556 is to make it configurable by a runtime command-line argument to setup.py: "--appname=foo", but I suddenly wondered if we really wanted that and at the same time realized that we don't need that for tahoe-1.3.0 release, so this patch just hardcodes it in setup.py.
setup.py inspects a file named 'src/allmydata/_appname.py' and assert that it contains the string "__appname__ = 'allmydata-tahoe'", and creates it if it isn't already present. src/allmydata/__init__.py import _appname and reads __appname__ from it. The rest of the Python code imports allmydata and inspects "allmydata.__appname__", although actually every use it uses "allmydata.__full_version__" instead, where "allmydata.__full_version__" is created in src/allmydata/__init__.py to be:
__full_version__ = __appname + '-' + str(__version__).
All the code that emits an "application version string" when describing what version of a protocol it supports (introducer server, storage server, upload helper), or when describing itself in general (introducer client), usese allmydata.__full_version__.
This fixes ticket #556 at least well enough for tahoe-1.3.0 release.
2009-02-12 00:18:16 +00:00
|
|
|
|
2011-04-10 15:57:05 +00:00
|
|
|
import os, platform, re, subprocess, sys, traceback
|
2008-09-23 17:14:31 +00:00
|
|
|
_distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
|
|
|
|
_release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
|
2008-09-23 16:28:58 +00:00
|
|
|
|
2008-09-23 17:14:31 +00:00
|
|
|
_distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
|
|
|
|
_release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
|
2008-08-28 22:04:54 +00:00
|
|
|
|
2008-09-24 18:09:22 +00:00
|
|
|
global _distname,_version
|
|
|
|
_distname = None
|
|
|
|
_version = None
|
|
|
|
|
2008-09-22 23:53:54 +00:00
|
|
|
def get_linux_distro():
|
|
|
|
""" Tries to determine the name of the Linux OS distribution name.
|
|
|
|
|
2008-09-23 17:14:31 +00:00
|
|
|
First, try to parse a file named "/etc/lsb-release". If it exists, and
|
|
|
|
contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
|
2008-09-24 18:09:22 +00:00
|
|
|
the strings parsed from that file.
|
|
|
|
|
|
|
|
If that doesn't work, then invoke platform.dist().
|
2008-09-23 17:14:31 +00:00
|
|
|
|
2008-09-24 18:09:22 +00:00
|
|
|
If that doesn't work, then try to execute "lsb_release", as standardized in
|
|
|
|
2001:
|
2008-09-22 23:53:54 +00:00
|
|
|
|
|
|
|
http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html
|
|
|
|
|
|
|
|
The current version of the standard is here:
|
|
|
|
|
|
|
|
http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html
|
|
|
|
|
2008-09-23 17:14:31 +00:00
|
|
|
that lsb_release emitted, as strings.
|
2008-09-23 16:28:58 +00:00
|
|
|
|
2008-09-22 23:53:54 +00:00
|
|
|
Returns a tuple (distname,version). Distname is what LSB calls a
|
|
|
|
"distributor id", e.g. "Ubuntu". Version is what LSB calls a "release",
|
|
|
|
e.g. "8.04".
|
|
|
|
|
|
|
|
A version of this has been submitted to python as a patch for the standard
|
|
|
|
library module "platform":
|
|
|
|
|
|
|
|
http://bugs.python.org/issue3937
|
|
|
|
"""
|
2008-09-24 18:09:22 +00:00
|
|
|
global _distname,_version
|
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
2008-09-23 16:28:58 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
etclsbrel = open("/etc/lsb-release", "rU")
|
2008-09-23 16:55:51 +00:00
|
|
|
for line in etclsbrel:
|
|
|
|
m = _distributor_id_file_re.search(line)
|
2008-09-23 16:28:58 +00:00
|
|
|
if m:
|
|
|
|
_distname = m.group(1).strip()
|
2008-09-23 17:14:31 +00:00
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
2008-09-23 16:55:51 +00:00
|
|
|
m = _release_file_re.search(line)
|
2008-09-23 16:28:58 +00:00
|
|
|
if m:
|
|
|
|
_version = m.group(1).strip()
|
2008-09-23 17:14:31 +00:00
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
2008-09-23 16:28:58 +00:00
|
|
|
except EnvironmentError:
|
2010-02-26 06:21:51 +00:00
|
|
|
pass
|
2008-09-23 16:28:58 +00:00
|
|
|
|
2008-09-24 18:09:22 +00:00
|
|
|
(_distname, _version) = platform.dist()[:2]
|
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
|
|
|
|
2008-09-23 17:14:31 +00:00
|
|
|
try:
|
|
|
|
p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
rc = p.wait()
|
|
|
|
if rc == 0:
|
|
|
|
for line in p.stdout.readlines():
|
|
|
|
m = _distributor_id_cmdline_re.search(line)
|
|
|
|
if m:
|
|
|
|
_distname = m.group(1).strip()
|
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
|
|
|
|
|
|
|
m = _release_cmdline_re.search(p.stdout.read())
|
|
|
|
if m:
|
|
|
|
_version = m.group(1).strip()
|
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
|
|
|
except EnvironmentError:
|
|
|
|
pass
|
2008-09-23 16:28:58 +00:00
|
|
|
|
2008-11-25 16:51:18 +00:00
|
|
|
if os.path.exists("/etc/arch-release"):
|
|
|
|
return ("Arch_Linux", "")
|
|
|
|
|
2008-09-24 18:09:22 +00:00
|
|
|
return (_distname,_version)
|
2008-09-22 23:53:54 +00:00
|
|
|
|
|
|
|
def get_platform():
|
|
|
|
# Our version of platform.platform(), telling us both less and more than the
|
|
|
|
# Python Standard Library's version does.
|
|
|
|
# We omit details such as the Linux kernel version number, but we add a
|
|
|
|
# more detailed and correct rendition of the Linux distribution and
|
|
|
|
# distribution-version.
|
|
|
|
if "linux" in platform.system().lower():
|
|
|
|
return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
|
|
|
|
else:
|
|
|
|
return platform.platform()
|
|
|
|
|
2010-08-01 16:05:17 +00:00
|
|
|
|
2011-01-21 05:36:10 +00:00
|
|
|
from allmydata.util import verlib
|
2011-04-01 20:27:50 +00:00
|
|
|
def normalized_version(verstr, what=None):
|
|
|
|
try:
|
|
|
|
return verlib.NormalizedVersion(verlib.suggest_normalized_version(verstr))
|
2011-04-07 17:22:31 +00:00
|
|
|
except (StandardError, verlib.IrrationalVersionError):
|
2011-04-10 15:57:05 +00:00
|
|
|
cls, value, trace = sys.exc_info()
|
2011-04-01 20:27:50 +00:00
|
|
|
raise PackagingError, ("could not parse %s due to %s: %s"
|
2011-04-10 15:57:05 +00:00
|
|
|
% (what or repr(verstr), cls.__name__, value)), trace
|
2011-01-21 05:36:10 +00:00
|
|
|
|
2010-08-08 17:12:35 +00:00
|
|
|
|
2009-01-19 22:04:35 +00:00
|
|
|
def get_package_versions_and_locations():
|
2011-01-21 05:36:10 +00:00
|
|
|
import warnings
|
2011-08-17 20:31:34 +00:00
|
|
|
from _auto_deps import package_imports, deprecation_messages, \
|
|
|
|
deprecation_imports, user_warning_messages
|
2011-01-21 05:36:10 +00:00
|
|
|
|
|
|
|
def package_dir(srcfile):
|
|
|
|
return os.path.dirname(os.path.dirname(os.path.normcase(os.path.realpath(srcfile))))
|
|
|
|
|
|
|
|
# pkg_resources.require returns the distribution that pkg_resources attempted to put
|
|
|
|
# on sys.path, which can differ from the one that we actually import due to #1258,
|
|
|
|
# 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)
|
|
|
|
|
2011-08-17 20:31:34 +00:00
|
|
|
# This is to suppress various DeprecationWarnings and UserWarnings that
|
|
|
|
# occur when modules are imported. See #859, #1435 and
|
|
|
|
# http://divmod.org/trac/ticket/2994 .
|
2011-01-21 05:36:10 +00:00
|
|
|
|
|
|
|
for msg in deprecation_messages:
|
|
|
|
warnings.filterwarnings("ignore", category=DeprecationWarning, message=msg, append=True)
|
2011-08-17 20:31:34 +00:00
|
|
|
for msg in user_warning_messages:
|
|
|
|
warnings.filterwarnings("ignore", category=UserWarning, message=msg, append=True)
|
2009-06-04 15:37:28 +00:00
|
|
|
try:
|
2011-01-21 05:36:10 +00:00
|
|
|
for modulename in deprecation_imports:
|
|
|
|
try:
|
|
|
|
__import__(modulename)
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
finally:
|
|
|
|
for ign in deprecation_messages:
|
|
|
|
warnings.filters.pop()
|
2011-08-17 20:31:34 +00:00
|
|
|
for ign in user_warning_messages:
|
|
|
|
warnings.filters.pop()
|
2011-01-21 05:36:10 +00:00
|
|
|
|
|
|
|
packages = []
|
|
|
|
|
|
|
|
def get_version(module, attr):
|
|
|
|
return str(getattr(module, attr, 'unknown'))
|
|
|
|
|
|
|
|
for pkgname, modulename in [(__appname__, 'allmydata')] + package_imports:
|
|
|
|
if modulename:
|
|
|
|
try:
|
|
|
|
__import__(modulename)
|
|
|
|
module = sys.modules[modulename]
|
|
|
|
except ImportError:
|
2011-04-10 15:57:05 +00:00
|
|
|
etype, emsg, etrace = sys.exc_info()
|
2011-04-11 19:07:38 +00:00
|
|
|
trace_info = (etype, str(emsg), ([None] + traceback.extract_tb(etrace))[-1])
|
2011-04-10 15:57:05 +00:00
|
|
|
packages.append( (pkgname, (None, None, trace_info)) )
|
2011-01-21 05:36:10 +00:00
|
|
|
else:
|
|
|
|
if 'sqlite' in pkgname:
|
2011-01-28 05:41:50 +00:00
|
|
|
packages.append( (pkgname, (get_version(module, 'version'), package_dir(module.__file__),
|
|
|
|
'sqlite %s' % (get_version(module, 'sqlite_version'),))) )
|
2011-01-21 05:36:10 +00:00
|
|
|
else:
|
2011-01-28 05:41:50 +00:00
|
|
|
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)) )
|
2011-01-21 05:36:10 +00:00
|
|
|
elif pkgname == 'python':
|
2011-01-28 05:41:50 +00:00
|
|
|
packages.append( (pkgname, (platform.python_version(), sys.executable, None)) )
|
2011-01-21 05:36:10 +00:00
|
|
|
elif pkgname == 'platform':
|
2011-01-28 05:41:50 +00:00
|
|
|
packages.append( (pkgname, (get_platform(), None, None)) )
|
2011-01-21 05:36:10 +00:00
|
|
|
|
|
|
|
return packages
|
|
|
|
|
|
|
|
|
|
|
|
def check_requirement(req, vers_and_locs):
|
|
|
|
# TODO: check [] options
|
2011-08-15 03:51:53 +00:00
|
|
|
# We support only disjunctions of <=, >=, and ==
|
2011-01-21 05:36:10 +00:00
|
|
|
|
|
|
|
reqlist = req.split(',')
|
2011-08-15 03:51:53 +00:00
|
|
|
name = reqlist[0].split('<=')[0].split('>=')[0].split('==')[0].strip(' ').split('[')[0]
|
2011-01-21 05:36:10 +00:00
|
|
|
if name not in vers_and_locs:
|
|
|
|
raise PackagingError("no version info for %s" % (name,))
|
|
|
|
if req.strip(' ') == name:
|
|
|
|
return
|
2011-01-28 05:41:50 +00:00
|
|
|
(actual, location, comment) = vers_and_locs[name]
|
2011-01-21 05:36:10 +00:00
|
|
|
if actual is None:
|
2011-04-11 19:07:38 +00:00
|
|
|
# comment is (type, message, (filename, line number, function name, text)) for the original ImportError
|
2011-04-10 15:57:05 +00:00
|
|
|
raise ImportError("for requirement %r: %s" % (req, comment))
|
2011-01-21 05:36:10 +00:00
|
|
|
if actual == 'unknown':
|
|
|
|
return
|
2011-04-01 20:27:50 +00:00
|
|
|
actualver = normalized_version(actual, what="actual version %r of %s from %r" % (actual, name, location))
|
2011-01-21 05:36:10 +00:00
|
|
|
|
|
|
|
for r in reqlist:
|
2011-08-15 03:51:53 +00:00
|
|
|
s = r.split('<=')
|
2011-01-21 05:36:10 +00:00
|
|
|
if len(s) == 2:
|
|
|
|
required = s[1].strip(' ')
|
2011-08-15 03:51:53 +00:00
|
|
|
if actualver <= normalized_version(required, what="required maximum version %r in %r" % (required, req)):
|
|
|
|
return # maximum requirement met
|
2009-06-04 15:37:28 +00:00
|
|
|
else:
|
2011-08-15 03:51:53 +00:00
|
|
|
s = r.split('>=')
|
2011-01-21 05:36:10 +00:00
|
|
|
if len(s) == 2:
|
|
|
|
required = s[1].strip(' ')
|
2011-08-15 03:51:53 +00:00
|
|
|
if actualver >= normalized_version(required, what="required minimum version %r in %r" % (required, req)):
|
|
|
|
return # minimum requirement met
|
2011-01-21 05:36:10 +00:00
|
|
|
else:
|
2011-08-15 03:51:53 +00:00
|
|
|
s = r.split('==')
|
|
|
|
if len(s) == 2:
|
|
|
|
required = s[1].strip(' ')
|
|
|
|
if actualver == normalized_version(required, what="required exact version %r in %r" % (required, req)):
|
|
|
|
return # exact requirement met
|
|
|
|
else:
|
|
|
|
raise PackagingError("no version info or could not understand requirement %r" % (req,))
|
2011-01-21 05:36:10 +00:00
|
|
|
|
|
|
|
msg = ("We require %s, but could only find version %s.\n" % (req, actual))
|
|
|
|
if location and location != 'unknown':
|
|
|
|
msg += "The version we found is from %r.\n" % (location,)
|
|
|
|
msg += ("To resolve this problem, uninstall that version, either using your\n"
|
|
|
|
"operating system's package manager or by moving aside the directory.")
|
|
|
|
raise PackagingError(msg)
|
|
|
|
|
|
|
|
|
|
|
|
_vers_and_locs_list = get_package_versions_and_locations()
|
|
|
|
|
|
|
|
|
|
|
|
def cross_check_pkg_resources_versus_import():
|
|
|
|
"""This function returns a list of errors due to any failed cross-checks."""
|
|
|
|
|
2009-01-19 22:04:35 +00:00
|
|
|
import pkg_resources
|
2011-01-21 05:36:10 +00:00
|
|
|
from _auto_deps import install_requires
|
|
|
|
|
2011-02-21 01:58:17 +00:00
|
|
|
pkg_resources_vers_and_locs = dict([(p.project_name.lower(), (str(p.version), p.location))
|
|
|
|
for p in pkg_resources.require(install_requires)])
|
|
|
|
|
|
|
|
return cross_check(pkg_resources_vers_and_locs, _vers_and_locs_list)
|
|
|
|
|
|
|
|
|
|
|
|
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."""
|
|
|
|
|
2011-01-21 05:36:10 +00:00
|
|
|
errors = []
|
2011-01-28 05:41:50 +00:00
|
|
|
not_pkg_resourceable = set(['sqlite3', 'python', 'platform', __appname__.lower()])
|
2011-01-21 05:36:10 +00:00
|
|
|
not_import_versionable = set(['zope.interface', 'mock', 'pyasn1'])
|
2011-08-01 00:52:09 +00:00
|
|
|
ignorable = set(['argparse', 'pyutil', 'zbase32', 'distribute', 'twisted-web', 'twisted-core'])
|
2011-01-21 05:36:10 +00:00
|
|
|
|
2011-02-21 01:58:17 +00:00
|
|
|
for name, (imp_ver, imp_loc, imp_comment) in imported_vers_and_locs_list:
|
2011-01-21 05:36:10 +00:00
|
|
|
name = name.lower()
|
|
|
|
if name not in not_pkg_resourceable:
|
|
|
|
if name not in pkg_resources_vers_and_locs:
|
2011-01-28 05:41:50 +00:00
|
|
|
if name == "setuptools" and "distribute" in pkg_resources_vers_and_locs:
|
|
|
|
pr_ver, pr_loc = pkg_resources_vers_and_locs["distribute"]
|
|
|
|
if not (os.path.normpath(os.path.realpath(pr_loc)) == os.path.normpath(os.path.realpath(imp_loc))
|
|
|
|
and imp_comment == "distribute"):
|
2011-02-21 02:01:25 +00:00
|
|
|
errors.append("Warning: dependency 'setuptools' found to be version %r of 'distribute' from %r "
|
|
|
|
"by pkg_resources, but 'import setuptools' gave version %r [%s] from %r. "
|
|
|
|
"A version mismatch is expected, but a location mismatch is not."
|
2011-01-28 05:41:50 +00:00
|
|
|
% (pr_ver, pr_loc, imp_ver, imp_comment or 'probably *not* distribute', imp_loc))
|
|
|
|
else:
|
2011-02-21 02:01:25 +00:00
|
|
|
errors.append("Warning: dependency %r (version %r imported from %r) was not found by pkg_resources."
|
2011-01-28 05:41:50 +00:00
|
|
|
% (name, imp_ver, imp_loc))
|
|
|
|
continue
|
2011-01-21 05:36:10 +00:00
|
|
|
|
|
|
|
pr_ver, pr_loc = pkg_resources_vers_and_locs[name]
|
|
|
|
try:
|
|
|
|
pr_normver = normalized_version(pr_ver)
|
|
|
|
except Exception, e:
|
2011-02-21 02:01:25 +00:00
|
|
|
errors.append("Warning: version number %r found for dependency %r by pkg_resources could not be parsed. "
|
|
|
|
"The version found by import was %r from %r. "
|
2011-01-21 05:36:10 +00:00
|
|
|
"pkg_resources thought it should be found at %r. "
|
|
|
|
"The exception was %s: %s"
|
2011-02-21 02:01:25 +00:00
|
|
|
% (pr_ver, name, imp_ver, imp_loc, pr_loc, e.__class__.__name__, e))
|
2011-01-21 05:36:10 +00:00
|
|
|
else:
|
|
|
|
if imp_ver == 'unknown':
|
|
|
|
if name not in not_import_versionable:
|
2011-02-21 02:01:25 +00:00
|
|
|
errors.append("Warning: unexpectedly could not find a version number for dependency %r imported from %r. "
|
|
|
|
"pkg_resources thought it should be version %r at %r."
|
2011-01-21 05:36:10 +00:00
|
|
|
% (name, imp_loc, pr_ver, pr_loc))
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
imp_normver = normalized_version(imp_ver)
|
|
|
|
except Exception, e:
|
2011-02-21 02:01:25 +00:00
|
|
|
errors.append("Warning: version number %r found for dependency %r (imported from %r) could not be parsed. "
|
|
|
|
"pkg_resources thought it should be version %r at %r. "
|
2011-01-21 05:36:10 +00:00
|
|
|
"The exception was %s: %s"
|
2011-02-21 02:01:25 +00:00
|
|
|
% (imp_ver, name, imp_loc, pr_ver, pr_loc, e.__class__.__name__, e))
|
2011-01-21 05:36:10 +00:00
|
|
|
else:
|
|
|
|
if pr_ver == 'unknown' or (pr_normver != imp_normver):
|
|
|
|
if not os.path.normpath(os.path.realpath(pr_loc)) == os.path.normpath(os.path.realpath(imp_loc)):
|
2011-02-21 02:01:25 +00:00
|
|
|
errors.append("Warning: dependency %r found to have version number %r (normalized to %r, from %r) "
|
|
|
|
"by pkg_resources, but version %r (normalized to %r, from %r) by import."
|
2011-01-21 05:36:10 +00:00
|
|
|
% (name, pr_ver, str(pr_normver), pr_loc, imp_ver, str(imp_normver), imp_loc))
|
|
|
|
|
2011-02-21 01:58:17 +00:00
|
|
|
imported_packages = set([p.lower() for (p, _) in imported_vers_and_locs_list])
|
2011-01-21 05:36:10 +00:00
|
|
|
for pr_name, (pr_ver, pr_loc) in pkg_resources_vers_and_locs.iteritems():
|
|
|
|
if pr_name not in imported_packages and pr_name not in ignorable:
|
2011-02-21 02:01:25 +00:00
|
|
|
errors.append("Warning: dependency %r (version %r) found by pkg_resources not found by import."
|
2011-01-21 05:36:10 +00:00
|
|
|
% (pr_name, pr_ver))
|
|
|
|
|
|
|
|
return errors
|
|
|
|
|
|
|
|
|
2011-01-22 04:02:20 +00:00
|
|
|
def get_error_string(errors, debug=False):
|
2011-01-21 05:36:10 +00:00
|
|
|
from allmydata._auto_deps import install_requires
|
|
|
|
|
2011-01-22 04:02:20 +00:00
|
|
|
msg = "\n%s\n" % ("\n".join(errors),)
|
|
|
|
if debug:
|
|
|
|
msg += ("\n"
|
|
|
|
"For debugging purposes, the PYTHONPATH was\n"
|
|
|
|
" %r\n"
|
|
|
|
"install_requires was\n"
|
|
|
|
" %r\n"
|
|
|
|
"sys.path after importing pkg_resources was\n"
|
|
|
|
" %s\n"
|
|
|
|
% (os.environ.get('PYTHONPATH'), install_requires, (os.pathsep+"\n ").join(sys.path)) )
|
|
|
|
return msg
|
2011-01-21 05:36:10 +00:00
|
|
|
|
|
|
|
def check_all_requirements():
|
|
|
|
"""This function returns a list of errors due to any failed checks."""
|
|
|
|
|
|
|
|
from allmydata._auto_deps import install_requires
|
|
|
|
|
|
|
|
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,))
|
2009-01-19 22:04:35 +00:00
|
|
|
else:
|
2011-01-21 05:36:10 +00:00
|
|
|
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,))
|
|
|
|
|
|
|
|
vers_and_locs = dict(_vers_and_locs_list)
|
|
|
|
for requirement in install_requires:
|
|
|
|
try:
|
|
|
|
check_requirement(requirement, vers_and_locs)
|
2011-01-28 15:20:06 +00:00
|
|
|
except (ImportError, PackagingError), e:
|
2011-01-21 05:36:10 +00:00
|
|
|
errors.append("%s: %s" % (e.__class__.__name__, e))
|
|
|
|
|
|
|
|
if errors:
|
2011-01-22 04:02:20 +00:00
|
|
|
raise PackagingError(get_error_string(errors, debug=True))
|
2011-01-21 05:36:10 +00:00
|
|
|
|
|
|
|
check_all_requirements()
|
2009-01-19 22:04:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_package_versions():
|
2011-01-28 05:41:50 +00:00
|
|
|
return dict([(k, v) for k, (v, l, c) in _vers_and_locs_list])
|
2009-01-19 22:04:35 +00:00
|
|
|
|
2009-01-16 19:47:51 +00:00
|
|
|
def get_package_locations():
|
2011-01-28 05:41:50 +00:00
|
|
|
return dict([(k, l) for k, (v, l, c) in _vers_and_locs_list])
|
2009-01-16 19:47:51 +00:00
|
|
|
|
2011-01-22 04:02:20 +00:00
|
|
|
def get_package_versions_string(show_paths=False, debug=False):
|
2007-12-13 02:37:37 +00:00
|
|
|
res = []
|
2011-01-28 05:41:50 +00:00
|
|
|
for p, (v, loc, comment) in _vers_and_locs_list:
|
2009-01-19 22:04:35 +00:00
|
|
|
info = str(p) + ": " + str(v)
|
2011-01-28 05:41:50 +00:00
|
|
|
if comment:
|
|
|
|
info = info + " [%s]" % str(comment)
|
2009-01-19 22:04:35 +00:00
|
|
|
if show_paths:
|
|
|
|
info = info + " (%s)" % str(loc)
|
|
|
|
res.append(info)
|
2011-01-21 05:36:10 +00:00
|
|
|
|
|
|
|
output = ",\n".join(res) + "\n"
|
|
|
|
|
|
|
|
if not hasattr(sys, 'frozen'):
|
|
|
|
errors = cross_check_pkg_resources_versus_import()
|
|
|
|
if errors:
|
2011-01-22 04:02:20 +00:00
|
|
|
output += get_error_string(errors, debug=debug)
|
2011-01-21 05:36:10 +00:00
|
|
|
|
|
|
|
return output
|