From: david-sarah Date: Fri, 29 Oct 2010 22:28:25 +0000 (-0700) Subject: setup.py, misc/build_helpers/run_trial.py: use undocumented __requires__ variable... X-Git-Tag: trac-4800~23 X-Git-Url: https://git.rkrishnan.org/components/%22news.html/...?a=commitdiff_plain;h=fd02946074821be9852f58010a52958104f2fb83;p=tahoe-lafs%2Ftahoe-lafs.git setup.py, misc/build_helpers/run_trial.py: use undocumented __requires__ variable to cause setuptools/zetuptoolz to put the correct versions of dependencies on sys.path. Also ensure that run_trial adds the bundled zetuptoolz egg at the start of sys.path if present. Make the source directory comparison work correctly for the test-with-fake-pkg build step. refs #1190 --- diff --git a/misc/build_helpers/run_trial.py b/misc/build_helpers/run_trial.py index eb9c63a4..8ea44230 100644 --- a/misc/build_helpers/run_trial.py +++ b/misc/build_helpers/run_trial.py @@ -1,6 +1,44 @@ #!/usr/bin/env python -import os, sys, re +import os, sys, re, glob + +def read_version_py(infname): + try: + verstrline = open(infname, "rt").read() + except EnvironmentError: + return None + else: + VSRE = r"^verstr = ['\"]([^'\"]*)['\"]" + mo = re.search(VSRE, verstrline, re.M) + if mo: + return mo.group(1) + +version = read_version_py(os.path.join('..', 'src', 'allmydata', '_version.py')) + +if version is None: + raise AssertionError("We don't know which version we're supposed to be testing.") + +APPNAME='allmydata-tahoe' + +adglobals = {} +execfile(os.path.join('..', 'src', 'allmydata', '_auto_deps.py'), adglobals) +install_requires = adglobals['install_requires'] +test_requires = adglobals.get('test_requires', ['mock']) + +# setuptools/zetuptoolz looks in __main__.__requires__ for a list of +# requirements. + +__requires__ = [APPNAME + '==' + version] + install_requires + test_requires + +print "Requirements: %r" % (__requires__,) + +eggz = glob.glob('setuptools-*.egg') +if len(eggz) > 0: + egg = os.path.realpath(eggz[0]) + print "Inserting egg on sys.path: %r" % (egg,) + sys.path.insert(0, egg) + +import pkg_resources modulename = None for i in xrange(1, len(sys.argv)): @@ -29,6 +67,9 @@ elif os.path.normcase(os.path.basename(srcdir)) == 'site-packages': srcdir = os.path.normcase(os.path.normpath(srcdir)) cwd = os.path.normcase(os.path.normpath(os.getcwd())) +if os.path.normcase(os.path.basename(cwd)) == 'src': + cwd = os.path.dirname(cwd) + same = (srcdir == cwd) if not same: try: diff --git a/setup.py b/setup.py index 3959531b..4b1ef205 100644 --- a/setup.py +++ b/setup.py @@ -38,6 +38,34 @@ def read_version_py(infname): version = read_version_py("src/allmydata/_version.py") +APPNAME='allmydata-tahoe' +APPNAMEFILE = os.path.join('src', 'allmydata', '_appname.py') +APPNAMEFILESTR = "__appname__ = '%s'" % (APPNAME,) +try: + curappnamefilestr = open(APPNAMEFILE, 'rU').read() +except EnvironmentError: + # No file, or unreadable or something, okay then let's try to write one. + open(APPNAMEFILE, "w").write(APPNAMEFILESTR) +else: + if curappnamefilestr.strip() != APPNAMEFILESTR: + print "Error -- this setup.py file is configured with the 'application name' to be '%s', but there is already a file in place in '%s' which contains the contents '%s'. If the file is wrong, please remove it and setup.py will regenerate it and write '%s' into it." % (APPNAME, APPNAMEFILE, curappnamefilestr, APPNAMEFILESTR) + sys.exit(-1) + +# setuptools/zetuptoolz looks in __main__.__requires__ for a list of +# requirements. When running "python setup.py test", __main__ is +# setup.py, so we put the list here so that the requirements will be +# available for tests: + +# Tahoe's dependencies are managed by the find_links= entry in setup.cfg and +# the _auto_deps.install_requires list, which is used in the call to setup() +# below. +adglobals = {} +execfile('src/allmydata/_auto_deps.py', adglobals) +install_requires = adglobals['install_requires'] + +if len(sys.argv) > 1 and sys.argv[1] in ['trial', 'test'] and version is not None: + __requires__ = [APPNAME + '==' + version] + install_requires + egg = os.path.realpath(glob.glob('setuptools-*.egg')[0]) sys.path.insert(0, egg) egg = os.path.realpath(glob.glob('darcsver-*.egg')[0]) @@ -319,26 +347,6 @@ class MySdist(sdist.sdist): return sdist.sdist.make_distribution(self) -# Tahoe's dependencies are managed by the find_links= entry in setup.cfg and -# the _auto_deps.install_requires list, which is used in the call to setup() -# below. -adglobals = {} -execfile('src/allmydata/_auto_deps.py', adglobals) -install_requires = adglobals['install_requires'] - -APPNAME='allmydata-tahoe' -APPNAMEFILE = os.path.join('src', 'allmydata', '_appname.py') -APPNAMEFILESTR = "__appname__ = '%s'" % (APPNAME,) -try: - curappnamefilestr = open(APPNAMEFILE, 'rU').read() -except EnvironmentError: - # No file, or unreadable or something, okay then let's try to write one. - open(APPNAMEFILE, "w").write(APPNAMEFILESTR) -else: - if curappnamefilestr.strip() != APPNAMEFILESTR: - print "Error -- this setup.py file is configured with the 'application name' to be '%s', but there is already a file in place in '%s' which contains the contents '%s'. If the file is wrong, please remove it and setup.py will regenerate it and write '%s' into it." % (APPNAME, APPNAMEFILE, curappnamefilestr, APPNAMEFILESTR) - sys.exit(-1) - setup_args = {} if version: setup_args["version"] = version