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"))
26 for i in range(len(sys.argv)):
29 if arg.startswith("--prefix="):
30 prefixdir = arg[len("--prefix="):]
32 if len(sys.argv) > i+1:
33 prefixdir = sys.argv[i+1]
36 libdir = pylibdir(prefixdir)
39 except EnvironmentError, le:
40 # Okay, maybe the dir was already there.
42 sys.path.append(libdir)
43 pp = os.environ.get('PYTHONPATH','').split(os.pathsep)
45 os.environ['PYTHONPATH'] = os.pathsep.join(pp)
47 if arg.startswith("develop"):
48 if sys.platform == "linux2":
49 # workaround for tahoe #229 / setuptools #17, on debian
50 sys.argv.extend(["--site-dirs", "/var/lib/python-support/python%d.%d" % (sys.version_info[:2])])
51 elif sys.platform == "darwin":
52 # this probably only applies to leopard 10.5, possibly only 10.5.5
53 sd = "/System/Library/Frameworks/Python.framework/Versions/%d.%d/Extras/lib/python" % (sys.version_info[:2])
54 sys.argv.extend(["--site-dirs", sd])
57 from ez_setup import use_setuptools
61 # This invokes our own customized version of ez_setup.py to make sure that
62 # setuptools >= v0.6c8 (a.k.a. v0.6-final) is installed.
64 # setuptools < v0.6c8 doesn't handle eggs which get installed into the CWD
65 # as a result of being transitively depended on in a setup_requires, but
66 # then are needed for the installed code to run, i.e. in an
68 use_setuptools(download_delay=0, min_version="0.6c10dev")
70 from setuptools import find_packages, setup
71 from setuptools.command import sdist
72 from distutils.core import Command
73 from pkg_resources import require
75 # Make the dependency-version-requirement, which is used by the Makefile at
76 # build-time, also available to the app at runtime:
78 shutil.copyfile("_auto_deps.py", os.path.join("src", "allmydata", "_auto_deps.py"))
81 "Development Status :: 5 - Production/Stable",
82 "Environment :: Console",
83 "Environment :: Web Environment",
84 "License :: OSI Approved :: GNU General Public License (GPL)",
85 "License :: DFSG approved",
86 "License :: Other/Proprietary License",
87 "Intended Audience :: Developers",
88 "Intended Audience :: End Users/Desktop",
89 "Intended Audience :: System Administrators",
90 "Operating System :: Microsoft",
91 "Operating System :: Microsoft :: Windows",
92 "Operating System :: Microsoft :: Windows :: Windows NT/2000",
93 "Operating System :: Unix",
94 "Operating System :: POSIX :: Linux",
95 "Operating System :: POSIX",
96 "Operating System :: MacOS :: MacOS X",
97 "Operating System :: OS Independent",
98 "Natural Language :: English",
99 "Programming Language :: C",
100 "Programming Language :: Python",
101 "Programming Language :: Python :: 2",
102 "Programming Language :: Python :: 2.4",
103 "Programming Language :: Python :: 2.5",
104 "Topic :: Utilities",
105 "Topic :: System :: Systems Administration",
106 "Topic :: System :: Filesystems",
107 "Topic :: System :: Distributed Computing",
108 "Topic :: Software Development :: Libraries",
109 "Topic :: Communications :: Usenet News",
110 "Topic :: System :: Archiving :: Backup",
111 "Topic :: System :: Archiving :: Mirroring",
112 "Topic :: System :: Archiving",
116 VERSIONFILE = "src/allmydata/_version.py"
119 verstrline = open(VERSIONFILE, "rt").read()
120 except EnvironmentError:
121 pass # Okay, there is no version file.
123 VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
124 mo = re.search(VSRE, verstrline, re.M)
128 print "unable to find version in %s" % (VERSIONFILE,)
129 raise RuntimeError("if %s.py exists, it is required to be well-formed" % (VERSIONFILE,))
132 """Welcome to the Tahoe project, a secure, decentralized, fault-tolerant
133 filesystem. All of the source code is available under a Free Software, Open
136 This filesystem is encrypted and spread over multiple peers in such a way that
137 it remains available even when some of the peers are unavailable,
138 malfunctioning, or malicious."""
143 # Nevow requires Twisted to setup, but doesn't declare that requirement in a way that enables
144 # setuptools to satisfy that requirement before Nevow's setup.py tried to "import twisted".
145 setup_requires.extend(['Twisted >= 2.4.0', 'setuptools_trial'])
147 # darcsver is needed if you want "./setup.py darcsver" to write a new version stamp in
148 # src/allmydata/_version.py, with a version number derived from darcs history.
149 # http://pypi.python.org/pypi/darcsver
150 setup_requires.append('darcsver >= 1.1.5')
152 # setuptools_trial is needed only if you want "./setup.py trial" to execute the tests.
153 # http://pypi.python.org/pypi/setuptools_trial
154 if 'trial' in sys.argv[1:]:
155 # Cygwin requires the poll reactor to work at all. Linux requires the poll reactor to avoid
156 # bug #402 (twisted bug #3218). In general, the poll reactor is better than the select
157 # reactor, but it is not available on all platforms. According to exarkun on IRC, it is
158 # available but buggy on some versions of Mac OS X, so just because you can install it
159 # doesn't mean we want to use it on every platform.
160 if sys.platform in ("linux2", "cygwin"):
161 if not [a for a in sys.argv if a.startswith("--reactor")]:
162 sys.argv.append("--reactor=poll")
163 setup_requires.append('setuptools_trial >= 0.2')
165 # Whenever we run the 'trial' command, make sure that the build_tahoe step
167 trial_index = sys.argv.index('trial')
168 sys.argv.insert(trial_index, 'build_tahoe')
170 # setuptools_darcs is required to produce complete distributions (such as with
171 # "sdist" or "bdist_egg"), unless there is a PKG-INFO file present which shows
172 # that this is itself a source distribution.
173 # http://pypi.python.org/pypi/setuptools_darcs
174 if not os.path.exists('PKG-INFO'):
175 setup_requires.append('setuptools_darcs >= 1.1.0')
177 class ShowSupportLib(Command):
179 def initialize_options(self):
181 def finalize_options(self):
184 # TODO: --quiet suppresses the 'running show_supportlib' message.
185 # Find a way to do this all the time.
186 print supportlib # TODO windowsy
188 class ShowPythonPath(Command):
190 def initialize_options(self):
192 def finalize_options(self):
195 # TODO: --quiet suppresses the 'running show_supportlib' message.
196 # Find a way to do this all the time.
197 print "PYTHONPATH=%s" % os.environ.get("PYTHONPATH", '')
199 class RunWithPythonPath(Command):
200 description = "Run a subcommand with PYTHONPATH set appropriately"
202 user_options = [ ("python", "p",
203 "Treat command string as arguments to a python executable"),
204 ("command=", "c", "Command to be run"),
205 ("directory=", "d", "Directory to run the command in"),
207 boolean_options = ["python"]
209 def initialize_options(self):
212 self.directory = None
213 def finalize_options(self):
216 oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
218 # grr silly split() behavior
220 os.environ['PYTHONPATH'] = os.pathsep.join(oldpp + [supportlib,])
222 # We must require the command to be safe to split on
223 # whitespace, and have --python and --directory to make it
224 # easier to achieve this.
228 command.append(sys.executable)
230 command.extend(self.command.split())
232 raise RuntimeError("The --command argument is mandatory")
234 os.chdir(self.directory)
236 print "command =", " ".join(command)
237 rc = subprocess.call(command)
240 class CheckAutoDeps(Command):
242 def initialize_options(self):
244 def finalize_options(self):
248 _auto_deps.require_auto_deps()
251 class BuildTahoe(Command):
253 def initialize_options(self):
255 def finalize_options(self):
259 bin_tahoe = os.path.join("bin", "tahoe")
260 old_mode = stat.S_IMODE(os.stat(bin_tahoe)[stat.ST_MODE])
261 new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
262 stat.S_IXGRP | stat.S_IRGRP |
263 stat.S_IXOTH | stat.S_IROTH )
264 os.chmod(bin_tahoe, new_mode)
266 # On Windows, create the 'tahoe-script.py' file based on the 'tahoe'
267 # executable script under the 'bin' directory so that the tahoe.exe
268 # will work correctly. The 'tahoe-script.py' file is exactly the same
269 # as the 'tahoe' script except that we need to update the she-bang
270 # line. The tahoe.exe will be copied from the setuptools egg's cli.exe
271 # and this will work from a zip-safe and non-zip-safe setuptools egg.
272 if sys.platform == "win32":
273 setuptools_egg = require("setuptools")[0].location
274 if os.path.isfile(setuptools_egg):
275 z = zipfile.ZipFile(setuptools_egg, 'r')
276 for filename in z.namelist():
277 if 'cli.exe' in filename:
278 cli_exe = z.read(filename)
280 cli_exe = os.path.join(setuptools_egg, 'setuptools', 'cli.exe')
281 tahoe_exe = os.path.join("bin", "tahoe.exe")
282 if os.path.isfile(setuptools_egg):
283 f = open(tahoe_exe, 'wb')
287 shutil.copy(cli_exe, tahoe_exe)
288 f = open(bin_tahoe, "r")
289 script_lines = f.readlines()
291 script_lines[0] = "#!%s\n" % sys.executable
292 tahoe_script = os.path.join("bin", "tahoe-script.py")
293 f = open(tahoe_script, "w")
294 for line in script_lines:
298 command = [sys.executable, "setup.py", "develop",
300 print "Command:", " ".join(command)
301 rc = subprocess.call(command)
303 print >>sys.stderr, "'setup.py develop' terminated by signal", -rc
306 print >>sys.stderr, "'setup.py develop' exited with rc", rc
309 class MySdist(sdist.sdist):
310 """ A hook in the sdist command so that we can determine whether this the
311 tarball should be 'SUMO' or not, i.e. whether or not to include the
312 external dependency tarballs. Note that we always include
313 misc/dependencies/* in the tarball; --sumo controls whether tahoe-deps/*
317 user_options = sdist.sdist.user_options + \
319 "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
321 boolean_options = ['sumo']
323 def initialize_options(self):
324 sdist.sdist.initialize_options(self)
327 def make_distribution(self):
328 # add our extra files to the list just before building the
329 # tarball/zipfile. We override make_distribution() instead of run()
330 # because setuptools.command.sdist.run() does not lend itself to
331 # easy/robust subclassing (the code we need to add goes right smack
332 # in the middle of a 12-line method). If this were the distutils
333 # version, we'd override get_file_list().
336 # If '--sumo' was specified, include tahoe-deps/* in the sdist.
337 # We assume that the user has fetched the tahoe-deps.tar.gz
338 # tarball and unpacked it already.
339 self.filelist.extend([os.path.join("tahoe-deps", fn)
340 for fn in os.listdir("tahoe-deps")])
341 # In addition, we want the tarball/zipfile to have -SUMO in the
342 # name, and the unpacked directory to have -SUMO too. The easiest
343 # way to do this is to patch self.distribution and override the
344 # get_fullname() method. (an alternative is to modify
345 # self.distribution.metadata.version, but that also affects the
346 # contents of PKG-INFO).
347 fullname = self.distribution.get_fullname()
349 return fullname + "-SUMO"
350 self.distribution.get_fullname = get_fullname
352 return sdist.sdist.make_distribution(self)
354 # Tahoe's dependencies are managed by the find_links= entry in setup.cfg and
355 # the _auto_deps.install_requires list, which is used in the call to setup()
356 # at the end of this file
357 from _auto_deps import install_requires
359 setup(name='allmydata-tahoe',
361 description='secure, decentralized, fault-tolerant filesystem',
362 long_description=LONG_DESCRIPTION,
363 author='the allmydata.org Tahoe project',
364 author_email='tahoe-dev@allmydata.org',
365 url='http://allmydata.org/',
367 cmdclass={"show_supportlib": ShowSupportLib,
368 "show_pythonpath": ShowPythonPath,
369 "run_with_pythonpath": RunWithPythonPath,
370 "check_auto_deps": CheckAutoDeps,
371 "build_tahoe": BuildTahoe,
374 package_dir = {'':'src'},
375 packages=find_packages("src"),
376 classifiers=trove_classifiers,
377 test_suite="allmydata.test",
378 install_requires=install_requires,
379 include_package_data=True,
380 setup_requires=setup_requires,
381 entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
382 zip_safe=False, # We prefer unzipped for easier access.