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.
This commit is contained in:
Zooko O'Whielacronx 2009-01-28 18:07:16 -07:00
parent 204629be43
commit 083795ddd6
3 changed files with 33 additions and 36 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/bin/false # You must specify a python interpreter.
import errno, sys, os, subprocess import errno, sys, os, subprocess

View File

@ -28,5 +28,5 @@ find_links=misc/dependencies tahoe-deps ../tahoe-deps
# http://pypi.python.org/pypi/pywin32 # http://pypi.python.org/pypi/pywin32
[aliases] [aliases]
build = darcsver --count-all-patches build_tahoe build = darcsver --count-all-patches develop --prefix=support make_executable build
test = build trial test = build trial

View File

@ -247,27 +247,30 @@ class CheckAutoDeps(Command):
_auto_deps.require_auto_deps() _auto_deps.require_auto_deps()
class BuildTahoe(Command): class MakeExecutable(Command):
user_options = [] user_options = []
def initialize_options(self): def initialize_options(self):
pass pass
def finalize_options(self): def finalize_options(self):
pass pass
def run(self): def run(self):
# chmod +x bin/tahoe bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
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' # Create the 'tahoe-script.py' file under the 'bin' directory. The 'tahoe-script.py'
# executable script under the 'bin' directory so that the tahoe.exe # file is exactly the same as the 'tahoe-script.template' script except that the shebang
# will work correctly. The 'tahoe-script.py' file is exactly the same # line is rewritten to use our sys.executable for the interpreter. On Windows, create a
# as the 'tahoe' script except that we need to update the she-bang # tahoe.exe will execute it. On non-Windows, make a symlink to it from 'tahoe'. The
# line. The tahoe.exe will be copied from the setuptools egg's cli.exe # tahoe.exe will be copied from the setuptools egg's cli.exe and this will work from a
# and this will work from a zip-safe and non-zip-safe setuptools egg. # 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": if sys.platform == "win32":
setuptools_egg = require("setuptools")[0].location setuptools_egg = require("setuptools")[0].location
if os.path.isfile(setuptools_egg): if os.path.isfile(setuptools_egg):
@ -284,26 +287,20 @@ class BuildTahoe(Command):
f.close() f.close()
else: else:
shutil.copy(cli_exe, tahoe_exe) shutil.copy(cli_exe, tahoe_exe)
f = open(bin_tahoe, "r") else:
script_lines = f.readlines() try:
f.close() os.remove(os.path.join('bin', 'tahoe'))
script_lines[0] = "#!%s\n" % sys.executable except:
tahoe_script = os.path.join("bin", "tahoe-script.py") # okay, probably it was already gone
f = open(tahoe_script, "w") pass
for line in script_lines: os.symlink('tahoe-script.py', os.path.join('bin', 'tahoe'))
f.write(line)
f.close()
command = [sys.executable, "setup.py", "develop", # chmod +x bin/tahoe-script.py
"--prefix=support"] old_mode = stat.S_IMODE(os.stat(tahoe_script)[stat.ST_MODE])
print "Command:", " ".join(command) new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
rc = subprocess.call(command) stat.S_IXGRP | stat.S_IRGRP |
if rc < 0: stat.S_IXOTH | stat.S_IROTH )
print >>sys.stderr, "'setup.py develop' terminated by signal", -rc os.chmod(tahoe_script, new_mode)
sys.exit(1)
elif rc > 0:
print >>sys.stderr, "'setup.py develop' exited with rc", rc
sys.exit(rc)
class MySdist(sdist.sdist): class MySdist(sdist.sdist):
""" A hook in the sdist command so that we can determine whether this the """ 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, "show_pythonpath": ShowPythonPath,
"run_with_pythonpath": RunWithPythonPath, "run_with_pythonpath": RunWithPythonPath,
"check_auto_deps": CheckAutoDeps, "check_auto_deps": CheckAutoDeps,
"build_tahoe": BuildTahoe, "make_executable": MakeExecutable,
"sdist": MySdist, "sdist": MySdist,
}, },
package_dir = {'':'src'}, package_dir = {'':'src'},