3 # Allmydata Tahoe -- secure, distributed storage grid
5 # Copyright (C) 2008 Allmydata, Inc.
7 # This file is part of tahoe.
9 # See the docs/about.html file for licensing information.
11 import os, re, shutil, stat, subprocess, sys, zipfile
13 ##### sys.path management
15 def pylibdir(prefixdir):
16 pyver = "python%d.%d" % (sys.version_info[:2])
17 if sys.platform == "win32":
18 return os.path.join(prefixdir, "Lib", "site-packages")
20 return os.path.join(prefixdir, "lib", pyver, "site-packages")
22 basedir = os.path.dirname(os.path.abspath(__file__))
23 supportlib = pylibdir(os.path.join(basedir, "support"))
25 prefixdirs = [] # argh! horrible kludge to work-around setuptools #54
26 for i in range(len(sys.argv)):
28 if arg.startswith("--prefix="):
29 prefixdirs.append(arg[len("--prefix="):])
31 if len(sys.argv) > i+1:
32 prefixdirs.append(sys.argv[i+1])
34 if arg.startswith("develop") or arg.startswith("build") or arg.startswith("test"): # argh! horrible kludge to workaround setuptools #17
35 if sys.platform == "linux2":
36 # workaround for tahoe #229 / setuptools #17, on debian
37 sys.argv.extend(["--site-dirs", "/var/lib/python-support/python%d.%d" % (sys.version_info[:2])])
38 elif sys.platform == "darwin":
39 # this probably only applies to leopard 10.5, possibly only 10.5.5
40 sd = "/System/Library/Frameworks/Python.framework/Versions/%d.%d/Extras/lib/python" % (sys.version_info[:2])
41 sys.argv.extend(["--site-dirs", sd])
44 prefixdirs.append("support")
46 for prefixdir in prefixdirs:
47 libdir = pylibdir(prefixdir)
50 except EnvironmentError, le:
51 # Okay, maybe the dir was already there.
53 sys.path.append(libdir)
54 pp = os.environ.get('PYTHONPATH','').split(os.pathsep)
56 os.environ['PYTHONPATH'] = os.pathsep.join(pp)
59 from ez_setup import use_setuptools
63 # This invokes our own customized version of ez_setup.py to make sure that
64 # setuptools >= v0.6c8 (a.k.a. v0.6-final) is installed.
66 # setuptools < v0.6c8 doesn't handle eggs which get installed into the CWD
67 # as a result of being transitively depended on in a setup_requires, but
68 # then are needed for the installed code to run, i.e. in an
70 use_setuptools(download_delay=0, min_version="0.6c10dev")
72 from setuptools import find_packages, setup
73 from setuptools.command import sdist
74 from distutils.core import Command
75 from pkg_resources import require
77 # Make the dependency-version-requirement, which is used by the Makefile at
78 # build-time, also available to the app at runtime:
80 shutil.copyfile("_auto_deps.py", os.path.join("src", "allmydata", "_auto_deps.py"))
83 "Development Status :: 5 - Production/Stable",
84 "Environment :: Console",
85 "Environment :: Web Environment",
86 "License :: OSI Approved :: GNU General Public License (GPL)",
87 "License :: DFSG approved",
88 "License :: Other/Proprietary License",
89 "Intended Audience :: Developers",
90 "Intended Audience :: End Users/Desktop",
91 "Intended Audience :: System Administrators",
92 "Operating System :: Microsoft",
93 "Operating System :: Microsoft :: Windows",
94 "Operating System :: Microsoft :: Windows :: Windows NT/2000",
95 "Operating System :: Unix",
96 "Operating System :: POSIX :: Linux",
97 "Operating System :: POSIX",
98 "Operating System :: MacOS :: MacOS X",
99 "Operating System :: OS Independent",
100 "Natural Language :: English",
101 "Programming Language :: C",
102 "Programming Language :: Python",
103 "Programming Language :: Python :: 2",
104 "Programming Language :: Python :: 2.4",
105 "Programming Language :: Python :: 2.5",
106 "Programming Language :: Python :: 2.6",
107 "Topic :: Utilities",
108 "Topic :: System :: Systems Administration",
109 "Topic :: System :: Filesystems",
110 "Topic :: System :: Distributed Computing",
111 "Topic :: Software Development :: Libraries",
112 "Topic :: Communications :: Usenet News",
113 "Topic :: System :: Archiving :: Backup",
114 "Topic :: System :: Archiving :: Mirroring",
115 "Topic :: System :: Archiving",
119 VERSIONFILE = "src/allmydata/_version.py"
122 verstrline = open(VERSIONFILE, "rt").read()
123 except EnvironmentError:
124 pass # Okay, there is no version file.
126 VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
127 mo = re.search(VSRE, verstrline, re.M)
131 print "unable to find version in %s" % (VERSIONFILE,)
132 raise RuntimeError("if %s.py exists, it is required to be well-formed" % (VERSIONFILE,))
135 """Welcome to the Tahoe project, a secure, decentralized, fault-tolerant
136 filesystem. All of the source code is available under a Free Software, Open
139 This filesystem is encrypted and spread over multiple peers in such a way that
140 it remains available even when some of the peers are unavailable,
141 malfunctioning, or malicious."""
146 # Nevow requires Twisted to setup, but doesn't declare that requirement in a way that enables
147 # setuptools to satisfy that requirement before Nevow's setup.py tried to "import twisted".
148 # Fortunately we require setuptools_trial to setup and setuptools_trial requires Twisted to
149 # install, so hopefully everything will work out until the Nevow issue is fixed:
150 # http://divmod.org/trac/ticket/2629
151 # setuptools_trial is needed if you want "./setup.py trial" or "./setup.py test" to execute the
152 # tests (and in order to make sure Twisted is installed early enough -- see the paragraph
154 # http://pypi.python.org/pypi/setuptools_trial
155 setup_requires.extend(['setuptools_trial'])
157 # darcsver is needed if you want "./setup.py darcsver" to write a new version stamp in
158 # src/allmydata/_version.py, with a version number derived from darcs history.
159 # http://pypi.python.org/pypi/darcsver
160 setup_requires.append('darcsver >= 1.1.5')
162 if 'trial' in sys.argv[1:] or 'test' in sys.argv[1:]:
163 # Cygwin requires the poll reactor to work at all. Linux requires the poll reactor to avoid
164 # bug #402 (twisted bug #3218). In general, the poll reactor is better than the select
165 # reactor, but it is not available on all platforms. According to exarkun on IRC, it is
166 # available but buggy on some versions of Mac OS X, so just because you can install it
167 # doesn't mean we want to use it on every platform.
168 if sys.platform in ("linux2", "cygwin"):
169 if not [a for a in sys.argv if a.startswith("--reactor")]:
170 sys.argv.append("--reactor=poll")
172 # setuptools_darcs is required to produce complete distributions (such as with
173 # "sdist" or "bdist_egg"), unless there is a PKG-INFO file present which shows
174 # that this is itself a source distribution.
175 # http://pypi.python.org/pypi/setuptools_darcs
176 if not os.path.exists('PKG-INFO'):
177 setup_requires.append('setuptools_darcs >= 1.1.0')
179 class ShowSupportLib(Command):
181 def initialize_options(self):
183 def finalize_options(self):
186 # TODO: --quiet suppresses the 'running show_supportlib' message.
187 # Find a way to do this all the time.
188 print supportlib # TODO windowsy
190 class ShowPythonPath(Command):
192 def initialize_options(self):
194 def finalize_options(self):
197 # TODO: --quiet suppresses the 'running show_supportlib' message.
198 # Find a way to do this all the time.
199 print "PYTHONPATH=%s" % os.environ.get("PYTHONPATH", '')
201 class RunWithPythonPath(Command):
202 description = "Run a subcommand with PYTHONPATH set appropriately"
204 user_options = [ ("python", "p",
205 "Treat command string as arguments to a python executable"),
206 ("command=", "c", "Command to be run"),
207 ("directory=", "d", "Directory to run the command in"),
209 boolean_options = ["python"]
211 def initialize_options(self):
214 self.directory = None
215 def finalize_options(self):
218 oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
220 # grr silly split() behavior
222 os.environ['PYTHONPATH'] = os.pathsep.join(oldpp + [supportlib,])
224 # We must require the command to be safe to split on
225 # whitespace, and have --python and --directory to make it
226 # easier to achieve this.
230 command.append(sys.executable)
232 command.extend(self.command.split())
234 raise RuntimeError("The --command argument is mandatory")
236 os.chdir(self.directory)
238 print "command =", " ".join(command)
239 rc = subprocess.call(command)
242 class CheckAutoDeps(Command):
244 def initialize_options(self):
246 def finalize_options(self):
250 _auto_deps.require_auto_deps()
253 class MakeExecutable(Command):
255 def initialize_options(self):
257 def finalize_options(self):
260 bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
262 # Create the 'tahoe-script.py' file under the 'bin' directory. The 'tahoe-script.py'
263 # file is exactly the same as the 'tahoe-script.template' script except that the shebang
264 # line is rewritten to use our sys.executable for the interpreter. On Windows, create a
265 # tahoe.exe will execute it. On non-Windows, make a symlink to it from 'tahoe'. The
266 # tahoe.exe will be copied from the setuptools egg's cli.exe and this will work from a
267 # zip-safe and non-zip-safe setuptools egg.
268 f = open(bin_tahoe_template, "rU")
269 script_lines = f.readlines()
271 script_lines[0] = "#!%s\n" % sys.executable
272 tahoe_script = os.path.join("bin", "tahoe-script.py")
273 f = open(tahoe_script, "w")
274 for line in script_lines:
277 if sys.platform == "win32":
278 setuptools_egg = require("setuptools")[0].location
279 if os.path.isfile(setuptools_egg):
280 z = zipfile.ZipFile(setuptools_egg, 'r')
281 for filename in z.namelist():
282 if 'cli.exe' in filename:
283 cli_exe = z.read(filename)
285 cli_exe = os.path.join(setuptools_egg, 'setuptools', 'cli.exe')
286 tahoe_exe = os.path.join("bin", "tahoe.exe")
287 if os.path.isfile(setuptools_egg):
288 f = open(tahoe_exe, 'wb')
292 shutil.copy(cli_exe, tahoe_exe)
295 os.remove(os.path.join('bin', 'tahoe'))
297 # okay, probably it was already gone
299 os.symlink('tahoe-script.py', os.path.join('bin', 'tahoe'))
301 # chmod +x bin/tahoe-script.py
302 old_mode = stat.S_IMODE(os.stat(tahoe_script)[stat.ST_MODE])
303 new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
304 stat.S_IXGRP | stat.S_IRGRP |
305 stat.S_IXOTH | stat.S_IROTH )
306 os.chmod(tahoe_script, new_mode)
308 class MySdist(sdist.sdist):
309 """ A hook in the sdist command so that we can determine whether this the
310 tarball should be 'SUMO' or not, i.e. whether or not to include the
311 external dependency tarballs. Note that we always include
312 misc/dependencies/* in the tarball; --sumo controls whether tahoe-deps/*
316 user_options = sdist.sdist.user_options + \
318 "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
320 boolean_options = ['sumo']
322 def initialize_options(self):
323 sdist.sdist.initialize_options(self)
326 def make_distribution(self):
327 # add our extra files to the list just before building the
328 # tarball/zipfile. We override make_distribution() instead of run()
329 # because setuptools.command.sdist.run() does not lend itself to
330 # easy/robust subclassing (the code we need to add goes right smack
331 # in the middle of a 12-line method). If this were the distutils
332 # version, we'd override get_file_list().
335 # If '--sumo' was specified, include tahoe-deps/* in the sdist.
336 # We assume that the user has fetched the tahoe-deps.tar.gz
337 # tarball and unpacked it already.
338 self.filelist.extend([os.path.join("tahoe-deps", fn)
339 for fn in os.listdir("tahoe-deps")])
340 # In addition, we want the tarball/zipfile to have -SUMO in the
341 # name, and the unpacked directory to have -SUMO too. The easiest
342 # way to do this is to patch self.distribution and override the
343 # get_fullname() method. (an alternative is to modify
344 # self.distribution.metadata.version, but that also affects the
345 # contents of PKG-INFO).
346 fullname = self.distribution.get_fullname()
348 return fullname + "-SUMO"
349 self.distribution.get_fullname = get_fullname
351 return sdist.sdist.make_distribution(self)
353 # Tahoe's dependencies are managed by the find_links= entry in setup.cfg and
354 # the _auto_deps.install_requires list, which is used in the call to setup()
355 # at the end of this file
356 from _auto_deps import install_requires
358 setup(name='allmydata-tahoe',
360 description='secure, decentralized, fault-tolerant filesystem',
361 long_description=LONG_DESCRIPTION,
362 author='the allmydata.org Tahoe project',
363 author_email='tahoe-dev@allmydata.org',
364 url='http://allmydata.org/',
366 cmdclass={"show_supportlib": ShowSupportLib,
367 "show_pythonpath": ShowPythonPath,
368 "run_with_pythonpath": RunWithPythonPath,
369 "check_auto_deps": CheckAutoDeps,
370 "make_executable": MakeExecutable,
373 package_dir = {'':'src'},
374 packages=find_packages("src"),
375 classifiers=trove_classifiers,
376 test_suite="allmydata.test",
377 install_requires=install_requires,
378 include_package_data=True,
379 setup_requires=setup_requires,
380 entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
381 zip_safe=False, # We prefer unzipped for easier access.