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 # The following horrible kludge to workaround setuptools #17 is commented-out, because I can't at this moment figure out how to make sure the horrible kludge gets executed only when it is needed (i.e., only when a "setup.py develop" step is about to happen), and the bad effect of setuptools #17 is "only" that setuptools re-installs extant packages.
35 # if arg.startswith("develop") or arg.startswith("build") or arg.startswith("test"): # argh! horrible kludge to workaround setuptools #17
36 # if sys.platform == "linux2":
37 # # workaround for tahoe #229 / setuptools #17, on debian
38 # sys.argv.extend(["--site-dirs", "/var/lib/python-support/python%d.%d" % (sys.version_info[:2])])
39 # elif sys.platform == "darwin":
40 # # this probably only applies to leopard 10.5, possibly only 10.5.5
41 # sd = "/System/Library/Frameworks/Python.framework/Versions/%d.%d/Extras/lib/python" % (sys.version_info[:2])
42 # sys.argv.extend(["--site-dirs", sd])
45 prefixdirs.append("support")
47 for prefixdir in prefixdirs:
48 libdir = pylibdir(prefixdir)
51 except EnvironmentError, le:
52 # Okay, maybe the dir was already there.
54 sys.path.append(libdir)
55 pp = os.environ.get('PYTHONPATH','').split(os.pathsep)
57 os.environ['PYTHONPATH'] = os.pathsep.join(pp)
60 from ez_setup import use_setuptools
64 # This invokes our own customized version of ez_setup.py to make sure that
65 # setuptools >= v0.6c8 (a.k.a. v0.6-final) is installed.
67 # setuptools < v0.6c8 doesn't handle eggs which get installed into the CWD
68 # as a result of being transitively depended on in a setup_requires, but
69 # then are needed for the installed code to run, i.e. in an
71 use_setuptools(download_delay=0, min_version="0.6c10dev")
73 from setuptools import find_packages, setup
74 from setuptools.command import sdist
75 from setuptools import Command
76 from pkg_resources import require
78 # Make the dependency-version-requirement, which is used by the Makefile at
79 # build-time, also available to the app at runtime:
81 shutil.copyfile("_auto_deps.py", os.path.join("src", "allmydata", "_auto_deps.py"))
84 "Development Status :: 5 - Production/Stable",
85 "Environment :: Console",
86 "Environment :: Web Environment",
87 "License :: OSI Approved :: GNU General Public License (GPL)",
88 "License :: DFSG approved",
89 "License :: Other/Proprietary License",
90 "Intended Audience :: Developers",
91 "Intended Audience :: End Users/Desktop",
92 "Intended Audience :: System Administrators",
93 "Operating System :: Microsoft",
94 "Operating System :: Microsoft :: Windows",
95 "Operating System :: Microsoft :: Windows :: Windows NT/2000",
96 "Operating System :: Unix",
97 "Operating System :: POSIX :: Linux",
98 "Operating System :: POSIX",
99 "Operating System :: MacOS :: MacOS X",
100 "Operating System :: OS Independent",
101 "Natural Language :: English",
102 "Programming Language :: C",
103 "Programming Language :: Python",
104 "Programming Language :: Python :: 2",
105 "Programming Language :: Python :: 2.4",
106 "Programming Language :: Python :: 2.5",
107 "Programming Language :: Python :: 2.6",
108 "Topic :: Utilities",
109 "Topic :: System :: Systems Administration",
110 "Topic :: System :: Filesystems",
111 "Topic :: System :: Distributed Computing",
112 "Topic :: Software Development :: Libraries",
113 "Topic :: Communications :: Usenet News",
114 "Topic :: System :: Archiving :: Backup",
115 "Topic :: System :: Archiving :: Mirroring",
116 "Topic :: System :: Archiving",
120 VERSIONFILE = "src/allmydata/_version.py"
123 verstrline = open(VERSIONFILE, "rt").read()
124 except EnvironmentError:
125 pass # Okay, there is no version file.
127 VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
128 mo = re.search(VSRE, verstrline, re.M)
132 print "unable to find version in %s" % (VERSIONFILE,)
133 raise RuntimeError("if %s.py exists, it is required to be well-formed" % (VERSIONFILE,))
136 """Welcome to the Tahoe project, a secure, decentralized, fault-tolerant
137 filesystem. All of the source code is available under a Free Software, Open
140 This filesystem is encrypted and spread over multiple peers in such a way that
141 it remains available even when some of the peers are unavailable,
142 malfunctioning, or malicious."""
147 # Nevow requires Twisted to setup, but doesn't declare that requirement in a way that enables
148 # setuptools to satisfy that requirement before Nevow's setup.py tried to "import twisted".
149 # Fortunately we require setuptools_trial to setup and setuptools_trial requires Twisted to
150 # install, so hopefully everything will work out until the Nevow issue is fixed:
151 # http://divmod.org/trac/ticket/2629
152 # setuptools_trial is needed if you want "./setup.py trial" or "./setup.py test" to execute the
153 # tests (and in order to make sure Twisted is installed early enough -- see the paragraph
155 # http://pypi.python.org/pypi/setuptools_trial
156 setup_requires.extend(['setuptools_trial'])
158 # darcsver is needed if you want "./setup.py darcsver" to write a new version stamp in
159 # src/allmydata/_version.py, with a version number derived from darcs history.
160 # http://pypi.python.org/pypi/darcsver
161 setup_requires.append('darcsver >= 1.1.5')
163 if 'trial' in sys.argv[1:] or 'test' in sys.argv[1:]:
164 # Cygwin requires the poll reactor to work at all. Linux requires the poll reactor to avoid
165 # bug #402 (twisted bug #3218). In general, the poll reactor is better than the select
166 # reactor, but it is not available on all platforms. According to exarkun on IRC, it is
167 # available but buggy on some versions of Mac OS X, so just because you can install it
168 # doesn't mean we want to use it on every platform.
169 if sys.platform in ("linux2", "cygwin"):
170 if not [a for a in sys.argv if a.startswith("--reactor")]:
171 sys.argv.append("--reactor=poll")
173 # setuptools_darcs is required to produce complete distributions (such as with
174 # "sdist" or "bdist_egg"), unless there is a PKG-INFO file present which shows
175 # that this is itself a source distribution.
176 # http://pypi.python.org/pypi/setuptools_darcs
177 if not os.path.exists('PKG-INFO'):
178 setup_requires.append('setuptools_darcs >= 1.1.0')
180 class ShowSupportLib(Command):
182 def initialize_options(self):
184 def finalize_options(self):
187 # TODO: --quiet suppresses the 'running show_supportlib' message.
188 # Find a way to do this all the time.
189 print supportlib # TODO windowsy
191 class ShowPythonPath(Command):
193 def initialize_options(self):
195 def finalize_options(self):
198 # TODO: --quiet suppresses the 'running show_supportlib' message.
199 # Find a way to do this all the time.
200 print "PYTHONPATH=%s" % os.environ.get("PYTHONPATH", '')
202 class RunWithPythonPath(Command):
203 description = "Run a subcommand with PYTHONPATH set appropriately"
205 user_options = [ ("python", "p",
206 "Treat command string as arguments to a python executable"),
207 ("command=", "c", "Command to be run"),
208 ("directory=", "d", "Directory to run the command in"),
210 boolean_options = ["python"]
212 def initialize_options(self):
215 self.directory = None
216 def finalize_options(self):
219 oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
221 # grr silly split() behavior
223 os.environ['PYTHONPATH'] = os.pathsep.join(oldpp + [supportlib,])
225 # We must require the command to be safe to split on
226 # whitespace, and have --python and --directory to make it
227 # easier to achieve this.
231 command.append(sys.executable)
233 command.extend(self.command.split())
235 raise RuntimeError("The --command argument is mandatory")
237 os.chdir(self.directory)
239 print "command =", " ".join(command)
240 rc = subprocess.call(command)
243 class CheckAutoDeps(Command):
245 def initialize_options(self):
247 def finalize_options(self):
251 _auto_deps.require_auto_deps()
254 class MakeExecutable(Command):
256 def initialize_options(self):
258 def finalize_options(self):
261 bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
263 # Create the 'tahoe-script.py' file under the 'bin' directory. The 'tahoe-script.py'
264 # file is exactly the same as the 'tahoe-script.template' script except that the shebang
265 # line is rewritten to use our sys.executable for the interpreter. On Windows, create a
266 # tahoe.exe will execute it. On non-Windows, make a symlink to it from 'tahoe'. The
267 # tahoe.exe will be copied from the setuptools egg's cli.exe and this will work from a
268 # zip-safe and non-zip-safe setuptools egg.
269 f = open(bin_tahoe_template, "rU")
270 script_lines = f.readlines()
272 script_lines[0] = "#!%s\n" % sys.executable
273 tahoe_script = os.path.join("bin", "tahoe-script.py")
274 f = open(tahoe_script, "w")
275 for line in script_lines:
278 if sys.platform == "win32":
279 setuptools_egg = require("setuptools")[0].location
280 if os.path.isfile(setuptools_egg):
281 z = zipfile.ZipFile(setuptools_egg, 'r')
282 for filename in z.namelist():
283 if 'cli.exe' in filename:
284 cli_exe = z.read(filename)
286 cli_exe = os.path.join(setuptools_egg, 'setuptools', 'cli.exe')
287 tahoe_exe = os.path.join("bin", "tahoe.exe")
288 if os.path.isfile(setuptools_egg):
289 f = open(tahoe_exe, 'wb')
293 shutil.copy(cli_exe, tahoe_exe)
296 os.remove(os.path.join('bin', 'tahoe'))
298 # okay, probably it was already gone
300 os.symlink('tahoe-script.py', os.path.join('bin', 'tahoe'))
302 # chmod +x bin/tahoe-script.py
303 old_mode = stat.S_IMODE(os.stat(tahoe_script)[stat.ST_MODE])
304 new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
305 stat.S_IXGRP | stat.S_IRGRP |
306 stat.S_IXOTH | stat.S_IROTH )
307 os.chmod(tahoe_script, new_mode)
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 "make_executable": MakeExecutable,
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.