Make bb-freeze (and probably other static packaging tools) work. This updates various places where we assumed that the tahoe process was executed via the Python interpreter. It also allows tests to recursively invoke the same tahoe.exe, rather than bin/tahoe. refs #585

This commit is contained in:
david-sarah 2011-01-21 00:04:29 -08:00
parent 8b94125b00
commit 8587c63bdc
3 changed files with 51 additions and 11 deletions

View File

@ -31,13 +31,18 @@ def get_root_from_file(src):
srcfile = allmydata.__file__
rootdir = get_root_from_file(srcfile)
bintahoe = os.path.join(rootdir, 'bin', 'tahoe')
if sys.platform == "win32":
bintahoe += ".pyscript"
if not os.path.exists(bintahoe):
alt_bintahoe = os.path.join(rootdir, 'Scripts', 'tahoe.pyscript')
if os.path.exists(alt_bintahoe):
bintahoe = alt_bintahoe
if hasattr(sys, 'frozen'):
bintahoe = os.path.join(rootdir, 'tahoe')
if sys.platform == "win32" and os.path.exists(bintahoe + '.exe'):
bintahoe += '.exe'
else:
bintahoe = os.path.join(rootdir, 'bin', 'tahoe')
if sys.platform == "win32":
bintahoe += '.pyscript'
if not os.path.exists(bintahoe):
alt_bintahoe = os.path.join(rootdir, 'Scripts', 'tahoe.pyscript')
if os.path.exists(alt_bintahoe):
bintahoe = alt_bintahoe
class RunBinTahoeMixin:
@ -53,7 +58,14 @@ class RunBinTahoeMixin:
def run_bintahoe(self, args, stdin=None, python_options=[], env=None):
self.skip_if_cannot_run_bintahoe()
command = [sys.executable] + python_options + [bintahoe] + args
if hasattr(sys, 'frozen'):
if python_options:
raise unittest.SkipTest("This test doesn't apply to frozen builds.")
command = [bintahoe] + args
else:
command = [sys.executable] + python_options + [bintahoe] + args
if stdin is None:
stdin_stream = None
else:
@ -69,6 +81,9 @@ class RunBinTahoeMixin:
class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin):
def _check_right_code(self, file_to_check):
root_to_check = get_root_from_file(file_to_check)
if os.path.basename(root_to_check) == 'dist':
root_to_check = os.path.dirname(root_to_check)
cwd = os.path.normcase(os.path.realpath("."))
root_from_cwd = os.path.dirname(cwd)
if os.path.basename(root_from_cwd) == 'src':
@ -172,8 +187,6 @@ class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin):
return d
def test_run_with_python_options(self):
self.skip_if_cannot_run_bintahoe()
# -t is a harmless option that warns about tabs.
d = self.run_bintahoe(["--version"], python_options=["-t"])
def _cb(res):

View File

@ -30,7 +30,7 @@ from twisted.web.error import Error
from allmydata.test.common import SystemTestMixin
# TODO: move these to common or common_util
# TODO: move this to common or common_util
from allmydata.test.test_runner import RunBinTahoeMixin
LARGE_DATA = """

27
static/tahoe.py Normal file
View File

@ -0,0 +1,27 @@
# This checks that we can import the right versions of all dependencies.
# Import this first to suppress deprecation warnings.
import allmydata
# nevow requires all these for its voodoo module import time adaptor registrations
from nevow import accessors, appserver, static, rend, url, util, query, i18n, flat
from nevow import guard, stan, testutil, context
from nevow.flat import flatmdom, flatstan, twist
from formless import webform, processors, annotate, iformless
from decimal import Decimal
from xml.dom import minidom
import allmydata.web
import mock
# junk to appease pyflakes's outrage
[
accessors, appserver, static, rend, url, util, query, i18n, flat, guard, stan, testutil,
context, flatmdom, flatstan, twist, webform, processors, annotate, iformless, Decimal,
minidom, allmydata, mock,
]
from allmydata.scripts import runner
runner.run()