From: Zooko O'Whielacronx Date: Thu, 29 Jan 2009 01:07:16 +0000 (-0700) Subject: setup: a new improved way to create tahoe executables X-Git-Tag: allmydata-tahoe-1.3.0~130 X-Git-Url: https://git.rkrishnan.org/pf/content/en/footer/%3C?a=commitdiff_plain;h=083795ddd6b286d75e398e0bccf5a550f7a93b48;p=tahoe-lafs%2Ftahoe-lafs.git setup: a new improved way to create tahoe executables Create the 'tahoe-script.py' file under the 'bin' directory. The 'tahoe-script.py' file is exactly the same as the 'tahoe-script.template' script except that the shebang line is rewritten to use our sys.executable for the interpreter. On Windows, create a tahoe.exe will execute it. On non-Windows, make a symlink to it from 'tahoe'. The tahoe.exe will be copied from the setuptools egg's cli.exe and this will work from a zip-safe and non-zip-safe setuptools egg. --- diff --git a/bin/tahoe b/bin/tahoe deleted file mode 100644 index 71dbc809..00000000 --- a/bin/tahoe +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python - -import errno, sys, os, subprocess - -where = os.path.realpath(sys.argv[0]) -base = os.path.dirname(os.path.dirname(where)) - -whoami = '''\ -I am a "bin/tahoe" executable who is only for the convenience of running -Tahoe from its source distribution -- I work only when invoked as the "tahoe" -script that lives in the "bin/" subdirectory of a Tahoe source code -distribution, and only if you have already run "make". -''' - -# look for Tahoe.home . -homemarker = os.path.join(base, "Tahoe.home") -if not os.path.exists(homemarker): - print whoami - print '''\ -I just tried to run and found that I am not living in such a directory, so I -am stopping now. To run Tahoe after it has been is installed, please execute -my brother, also named "tahoe", who gets installed into the appropriate place -for executables when you run "make install" (perhaps as /usr/bin/tahoe). -''' - sys.exit(1) - -# we've found our home. Put the tahoe support/lib etc. in our PYTHONPATH. -if sys.platform == "win32": - supportdir = os.path.join(base, "support", "Lib", "site-packages") -else: - supportdir = os.path.join(base, "support", - "lib", - "python%d.%d" % sys.version_info[:2], - "site-packages") - -# update PYTHONPATH so that child processes (like twistd) will use this too -pp = os.environ.get("PYTHONPATH") -if pp: - pp = os.pathsep.join([supportdir] + pp.split(os.pathsep)) -else: - pp = supportdir -os.environ["PYTHONPATH"] = pp - -# find the location of the tahoe executable. -bin_dir = "bin" -if sys.platform == "win32": - bin_dir = "Scripts" -executable = os.path.join(base, "support", bin_dir, "tahoe") - -try: - res = subprocess.call([executable] + sys.argv[1:], env=os.environ) -except (OSError, IOError), le: - if le.args[0] == errno.ENOENT: - print whoami - print '''\ -I just tried to run and could not find my brother, named -"../support/bin/tahoe". To run Tahoe when it is installed, please execute my -brother, also named "tahoe", who gets installed into the appropriate place -for executables when you run "make install" (perhaps as /usr/bin/tahoe). -''' - raise -except Exception, le: - print whoami - print '''\ -I just tried to invoke my brother, named "../support/bin/tahoe" and got an -exception. -''' - raise -else: - sys.exit(res) diff --git a/bin/tahoe-script.template b/bin/tahoe-script.template new file mode 100644 index 00000000..674a27d9 --- /dev/null +++ b/bin/tahoe-script.template @@ -0,0 +1,70 @@ +#!/bin/false # You must specify a python interpreter. + +import errno, sys, os, subprocess + +where = os.path.realpath(sys.argv[0]) +base = os.path.dirname(os.path.dirname(where)) + +whoami = '''\ +I am a "bin/tahoe" executable who is only for the convenience of running +Tahoe from its source distribution -- I work only when invoked as the "tahoe" +script that lives in the "bin/" subdirectory of a Tahoe source code +distribution, and only if you have already run "make". +''' + +# look for Tahoe.home . +homemarker = os.path.join(base, "Tahoe.home") +if not os.path.exists(homemarker): + print whoami + print '''\ +I just tried to run and found that I am not living in such a directory, so I +am stopping now. To run Tahoe after it has been is installed, please execute +my brother, also named "tahoe", who gets installed into the appropriate place +for executables when you run "make install" (perhaps as /usr/bin/tahoe). +''' + sys.exit(1) + +# we've found our home. Put the tahoe support/lib etc. in our PYTHONPATH. +if sys.platform == "win32": + supportdir = os.path.join(base, "support", "Lib", "site-packages") +else: + supportdir = os.path.join(base, "support", + "lib", + "python%d.%d" % sys.version_info[:2], + "site-packages") + +# update PYTHONPATH so that child processes (like twistd) will use this too +pp = os.environ.get("PYTHONPATH") +if pp: + pp = os.pathsep.join([supportdir] + pp.split(os.pathsep)) +else: + pp = supportdir +os.environ["PYTHONPATH"] = pp + +# find the location of the tahoe executable. +bin_dir = "bin" +if sys.platform == "win32": + bin_dir = "Scripts" +executable = os.path.join(base, "support", bin_dir, "tahoe") + +try: + res = subprocess.call([executable] + sys.argv[1:], env=os.environ) +except (OSError, IOError), le: + if le.args[0] == errno.ENOENT: + print whoami + print '''\ +I just tried to run and could not find my brother, named +"../support/bin/tahoe". To run Tahoe when it is installed, please execute my +brother, also named "tahoe", who gets installed into the appropriate place +for executables when you run "make install" (perhaps as /usr/bin/tahoe). +''' + raise +except Exception, le: + print whoami + print '''\ +I just tried to invoke my brother, named "../support/bin/tahoe" and got an +exception. +''' + raise +else: + sys.exit(res) diff --git a/setup.cfg b/setup.cfg index 8acef3a5..42956914 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,5 +28,5 @@ find_links=misc/dependencies tahoe-deps ../tahoe-deps # http://pypi.python.org/pypi/pywin32 [aliases] -build = darcsver --count-all-patches build_tahoe +build = darcsver --count-all-patches develop --prefix=support make_executable build test = build trial diff --git a/setup.py b/setup.py index 8a2e53bf..af180724 100644 --- a/setup.py +++ b/setup.py @@ -247,27 +247,30 @@ class CheckAutoDeps(Command): _auto_deps.require_auto_deps() -class BuildTahoe(Command): +class MakeExecutable(Command): user_options = [] def initialize_options(self): pass def finalize_options(self): pass def run(self): - # chmod +x bin/tahoe - bin_tahoe = os.path.join("bin", "tahoe") - old_mode = stat.S_IMODE(os.stat(bin_tahoe)[stat.ST_MODE]) - new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR | - stat.S_IXGRP | stat.S_IRGRP | - stat.S_IXOTH | stat.S_IROTH ) - os.chmod(bin_tahoe, new_mode) - - # On Windows, create the 'tahoe-script.py' file based on the 'tahoe' - # executable script under the 'bin' directory so that the tahoe.exe - # will work correctly. The 'tahoe-script.py' file is exactly the same - # as the 'tahoe' script except that we need to update the she-bang - # line. The tahoe.exe will be copied from the setuptools egg's cli.exe - # and this will work from a zip-safe and non-zip-safe setuptools egg. + bin_tahoe_template = os.path.join("bin", "tahoe-script.template") + + # Create the 'tahoe-script.py' file under the 'bin' directory. The 'tahoe-script.py' + # file is exactly the same as the 'tahoe-script.template' script except that the shebang + # line is rewritten to use our sys.executable for the interpreter. On Windows, create a + # tahoe.exe will execute it. On non-Windows, make a symlink to it from 'tahoe'. The + # tahoe.exe will be copied from the setuptools egg's cli.exe and this will work from a + # zip-safe and non-zip-safe setuptools egg. + f = open(bin_tahoe_template, "rU") + script_lines = f.readlines() + f.close() + script_lines[0] = "#!%s\n" % sys.executable + tahoe_script = os.path.join("bin", "tahoe-script.py") + f = open(tahoe_script, "w") + for line in script_lines: + f.write(line) + f.close() if sys.platform == "win32": setuptools_egg = require("setuptools")[0].location if os.path.isfile(setuptools_egg): @@ -284,26 +287,20 @@ class BuildTahoe(Command): f.close() else: shutil.copy(cli_exe, tahoe_exe) - f = open(bin_tahoe, "r") - script_lines = f.readlines() - f.close() - script_lines[0] = "#!%s\n" % sys.executable - tahoe_script = os.path.join("bin", "tahoe-script.py") - f = open(tahoe_script, "w") - for line in script_lines: - f.write(line) - f.close() - - command = [sys.executable, "setup.py", "develop", - "--prefix=support"] - print "Command:", " ".join(command) - rc = subprocess.call(command) - if rc < 0: - print >>sys.stderr, "'setup.py develop' terminated by signal", -rc - sys.exit(1) - elif rc > 0: - print >>sys.stderr, "'setup.py develop' exited with rc", rc - sys.exit(rc) + else: + try: + os.remove(os.path.join('bin', 'tahoe')) + except: + # okay, probably it was already gone + pass + os.symlink('tahoe-script.py', os.path.join('bin', 'tahoe')) + + # chmod +x bin/tahoe-script.py + old_mode = stat.S_IMODE(os.stat(tahoe_script)[stat.ST_MODE]) + new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR | + stat.S_IXGRP | stat.S_IRGRP | + stat.S_IXOTH | stat.S_IROTH ) + os.chmod(tahoe_script, new_mode) class MySdist(sdist.sdist): """ A hook in the sdist command so that we can determine whether this the @@ -367,7 +364,7 @@ setup(name='allmydata-tahoe', "show_pythonpath": ShowPythonPath, "run_with_pythonpath": RunWithPythonPath, "check_auto_deps": CheckAutoDeps, - "build_tahoe": BuildTahoe, + "make_executable": MakeExecutable, "sdist": MySdist, }, package_dir = {'':'src'},