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, sys, stat, subprocess
13 ##### sys.path management
15 basedir = os.path.dirname(os.path.abspath(__file__))
16 pyver = "python%d.%d" % (sys.version_info[:2])
17 if sys.platform == "win32":
18 supportlib = os.path.join("support", "Lib", "site-packages")
20 supportlib = os.path.join("support", "lib", pyver, "site-packages")
21 supportlib = os.path.join(basedir, supportlib)
23 def add_tahoe_paths():
24 """Modify sys.path and PYTHONPATH to include Tahoe and supporting libraries
26 The first step towards building Tahoe is to run::
28 python setup.py build_tahoe
30 which is the equivalent of::
32 mkdir -p $(BASEDIR)/support/lib/python2.5/site-packages
33 (or cygpath equivalent)
34 setup.py develop --multi-version --prefix=$(BASEDIR)/support
36 This installs .eggs for any dependent libraries that aren't already
37 available on the system, into support/lib/pythonN.N/site-packages (or
38 support/Lib/site-packages on windows). It also adds an .egg-link for
39 Tahoe itself into the same directory.
41 We add this directory to os.environ['PYTHONPATH'], so that any child
42 processes we spawn will be able to use these packages.
44 When the setuptools site.py sees that supportlib in PYTHONPATH, it scans
45 through it for .egg and .egg-link entries, and adds them to sys.path .
46 Since python has already processed all the site.py files by the time we
47 get here, we perform this same sort of processing ourselves: this makes
48 tahoe (and dependency libraries) available to code within setup.py
49 itself. This is used by the 'setup.py trial' subcommand, which invokes
50 trial directly rather than spawning a subprocess (this is easier than
51 locating the 'trial' executable, especially when Twisted was installed as
54 We'll need to add these .eggs to sys.path before importing anything that
55 isn't a part of stdlib. All the directories that we add this way are put
56 at the start of sys.path, so they will override anything that was present
57 on the system (and perhaps found lacking by the setuptools requirements
58 expressed in _auto_deps.py).
61 extra_syspath_items = []
62 extra_pythonpath_items = []
64 extra_syspath_items.append(supportlib)
65 extra_pythonpath_items.append(supportlib)
67 # Since we use setuptools to populate that directory, there will be a
68 # number of .egg and .egg-link entries there. Add all of them to
69 # sys.path, since that what the setuptools site.py would do if it
70 # encountered them at process start time. Without this step, the rest of
71 # this process would be unable to use the packages installed there. We
72 # don't need to add them to PYTHONPATH, since the site.py present there
73 # will add them when the child process starts up.
75 if os.path.isdir(supportlib):
76 for fn in os.listdir(supportlib):
77 if fn.endswith(".egg"):
78 extra_syspath_items.append(os.path.join(supportlib, fn))
80 # We also add our src/ directory, since that's where all the Tahoe code
81 # lives. This matches what site.py does when it sees the .egg-link file
82 # that is written to the support dir by an invocation of our 'setup.py
84 extra_syspath_items.append(os.path.join(basedir, "src"))
86 # and we put an extra copy of everything from PYTHONPATH in front, so
87 # that it is possible to override the packages that setuptools downloads
88 # with alternate versions, by doing e.g. "PYTHONPATH=foo python setup.py
90 oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
92 # grr silly split() behavior
94 extra_syspath_items = oldpp + extra_syspath_items
96 sys.path = extra_syspath_items + sys.path
98 # We also provide it to any child processes we spawn, via
99 # os.environ["PYTHONPATH"]
100 os.environ["PYTHONPATH"] = os.pathsep.join(oldpp + extra_pythonpath_items)
102 # add_tahoe_paths() must be called before use_setuptools() is called. I don't
103 # know why. If it isn't, then a later pkg_resources.requires(pycryptopp) call
104 # fails because an old version (in /usr/lib) was already loaded.
108 from ez_setup import use_setuptools
112 # This invokes our own customized version of ez_setup.py to make sure that
113 # setuptools >= v0.6c8 (a.k.a. v0.6-final) is installed.
115 # setuptools < v0.6c8 doesn't handle eggs which get installed into the CWD
116 # as a result of being transitively depended on in a setup_requires, but
117 # then are needed for the installed code to run, i.e. in an
119 use_setuptools(download_delay=0, min_version="0.6c8")
121 from setuptools import find_packages, setup
122 from setuptools.command import sdist
123 from distutils.core import Command
124 from setuptools_trial.setuptools_trial import TrialTest
126 # Make the dependency-version-requirement, which is used by the Makefile at
127 # build-time, also available to the app at runtime:
129 shutil.copyfile("_auto_deps.py", os.path.join("src", "allmydata", "_auto_deps.py"))
132 "Development Status :: 5 - Production/Stable",
133 "Environment :: Console",
134 "Environment :: Web Environment",
135 "License :: OSI Approved :: GNU General Public License (GPL)",
136 "License :: DFSG approved",
137 "License :: Other/Proprietary License",
138 "Intended Audience :: Developers",
139 "Intended Audience :: End Users/Desktop",
140 "Intended Audience :: System Administrators",
141 "Operating System :: Microsoft",
142 "Operating System :: Microsoft :: Windows",
143 "Operating System :: Microsoft :: Windows :: Windows NT/2000",
144 "Operating System :: Unix",
145 "Operating System :: POSIX :: Linux",
146 "Operating System :: POSIX",
147 "Operating System :: MacOS :: MacOS X",
148 "Operating System :: OS Independent",
149 "Natural Language :: English",
150 "Programming Language :: C",
151 "Programming Language :: Python",
152 "Programming Language :: Python :: 2",
153 "Programming Language :: Python :: 2.4",
154 "Programming Language :: Python :: 2.5",
155 "Topic :: Utilities",
156 "Topic :: System :: Systems Administration",
157 "Topic :: System :: Filesystems",
158 "Topic :: System :: Distributed Computing",
159 "Topic :: Software Development :: Libraries",
160 "Topic :: Communications :: Usenet News",
161 "Topic :: System :: Archiving :: Backup",
162 "Topic :: System :: Archiving :: Mirroring",
163 "Topic :: System :: Archiving",
167 VERSIONFILE = "src/allmydata/_version.py"
170 verstrline = open(VERSIONFILE, "rt").read()
171 except EnvironmentError:
172 pass # Okay, there is no version file.
174 VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
175 mo = re.search(VSRE, verstrline, re.M)
179 print "unable to find version in %s" % (VERSIONFILE,)
180 raise RuntimeError("if %s.py exists, it is required to be well-formed" % (VERSIONFILE,))
183 """Welcome to the Tahoe project, a secure, decentralized, fault-tolerant
184 filesystem. All of the source code is available under a Free Software, Open
187 This filesystem is encrypted and spread over multiple peers in such a way that
188 it remains available even when some of the peers are unavailable,
189 malfunctioning, or malicious."""
194 # Nevow requires Twisted to setup, but doesn't declare that requirement in a way that enables
195 # setuptools to satisfy that requirement before Nevow's setup.py tried to "import twisted".
196 setup_requires.extend(['Twisted >= 2.4.0', 'setuptools_trial'])
198 # darcsver is needed only if you want "./setup.py darcsver" to write a new
199 # version stamp in src/allmydata/_version.py, with a version number derived from
201 # http://pypi.python.org/pypi/darcsver
202 if 'darcsver' in sys.argv[1:]:
203 setup_requires.append('darcsver >= 1.1.5')
205 # setuptools_darcs is required to produce complete distributions (such as with
206 # "sdist" or "bdist_egg"), unless there is a PKG-INFO file present which shows
207 # that this is itself a source distribution.
208 # http://pypi.python.org/pypi/setuptools_darcs
209 if not os.path.exists('PKG-INFO'):
210 setup_requires.append('setuptools_darcs >= 1.1.0')
212 class ShowSupportLib(Command):
214 def initialize_options(self):
216 def finalize_options(self):
219 # TODO: --quiet suppresses the 'running show_supportlib' message.
220 # Find a way to do this all the time.
221 print supportlib # TODO windowsy
223 class ShowPythonPath(Command):
225 def initialize_options(self):
227 def finalize_options(self):
230 # TODO: --quiet suppresses the 'running show_supportlib' message.
231 # Find a way to do this all the time.
232 print "PYTHONPATH=%s" % os.environ["PYTHONPATH"]
234 class RunWithPythonPath(Command):
235 description = "Run a subcommand with PYTHONPATH set appropriately"
237 user_options = [ ("python", "p",
238 "Treat command string as arguments to a python executable"),
239 ("command=", "c", "Command to be run"),
240 ("directory=", "d", "Directory to run the command in"),
242 boolean_options = ["python"]
244 def initialize_options(self):
247 self.directory = None
248 def finalize_options(self):
251 # os.environ['PYTHONPATH'] is already set by add_tahoe_paths, so we
252 # just need to exec() their command. We must require the command to
253 # be safe to split on whitespace, and have --python and --directory
254 # to make it easier to achieve this.
257 command.append(sys.executable)
259 command.extend(self.command.split())
261 raise RuntimeError("The --command argument is mandatory")
263 os.chdir(self.directory)
265 print "command =", " ".join(command)
266 rc = subprocess.call(command)
269 class CheckAutoDeps(Command):
271 def initialize_options(self):
273 def finalize_options(self):
277 _auto_deps.require_auto_deps()
280 class BuildTahoe(Command):
282 def initialize_options(self):
284 def finalize_options(self):
288 bin_tahoe = os.path.join("bin", "tahoe")
289 old_mode = stat.S_IMODE(os.stat(bin_tahoe)[stat.ST_MODE])
290 new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
291 stat.S_IXGRP | stat.S_IRGRP |
292 stat.S_IXOTH | stat.S_IROTH )
293 os.chmod(bin_tahoe, new_mode)
295 # 'setup.py develop --multi-version --prefix SUPPORT' will complain if SUPPORTLIB is
296 # not on PYTHONPATH, because it thinks you are installing to a place
297 # that will not be searched at runtime (which is true, except that we
298 # add SUPPORTLIB to PYTHONPATH to run tests, etc). So set up
299 # PYTHONPATH now, then spawn a 'setup.py develop' command. Also, we
300 # have to create the directory ourselves.
301 if not os.path.isdir(supportlib):
302 os.makedirs(supportlib)
304 # command = [sys.executable, "setup.py", "develop", "--multi-version", "--prefix", "support"]
305 command = [sys.executable, "setup.py", "develop", "--prefix", "support"]
306 if sys.platform == "linux2":
307 # workaround for tahoe #229 / setuptools #17, on debian
308 command.extend(["--site-dirs", "/var/lib/python-support/" + pyver])
309 elif sys.platform == "darwin":
310 # this probably only applies to leopard 10.5, possibly only 10.5.5
311 sd = "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python"
312 command.extend(["--site-dirs", sd])
313 print "Command:", " ".join(command)
314 rc = subprocess.call(command)
316 print >>sys.stderr, "'setup.py develop' terminated by signal", -rc
319 print >>sys.stderr, "'setup.py develop' exited with rc", rc
322 class Trial(TrialTest):
323 # Custom sub-class of the TrialTest class from the setuptools_trial
324 # plugin so that we can ensure certain options are set by default.
327 # setup.py trial # run all tests
328 # setup.py trial -a allmydata.test.test_util # run some tests
329 # setup.py trial -a '--reporter=text allmydata.test.test_util' #other args
332 def initialize_options(self):
333 TrialTest.initialize_options(self)
335 # We want to set the reactor to 'poll', because of bug #402
336 # (twisted bug #3218).
337 if sys.platform in ("linux2", "cygwin"):
338 # poll on linux2 to avoid #402 problems with select
339 # poll on cygwin since selectreactor runs out of fds
340 self.reactor = "poll"
343 class MySdist(sdist.sdist):
344 """ A hook in the sdist command so that we can determine whether this the
345 tarball should be 'SUMO' or not, i.e. whether or not to include the
346 external dependency tarballs. Note that we always include
347 misc/dependencies/* in the tarball; --sumo controls whether tahoe-deps/*
351 user_options = sdist.sdist.user_options + \
353 "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
355 boolean_options = ['sumo']
357 def initialize_options(self):
358 sdist.sdist.initialize_options(self)
361 def make_distribution(self):
362 # add our extra files to the list just before building the
363 # tarball/zipfile. We override make_distribution() instead of run()
364 # because setuptools.command.sdist.run() does not lend itself to
365 # easy/robust subclassing (the code we need to add goes right smack
366 # in the middle of a 12-line method). If this were the distutils
367 # version, we'd override get_file_list().
370 # If '--sumo' was specified, include tahoe-deps/* in the sdist.
371 # We assume that the user has fetched the tahoe-deps.tar.gz
372 # tarball and unpacked it already.
373 self.filelist.extend([os.path.join("tahoe-deps", fn)
374 for fn in os.listdir("tahoe-deps")])
375 # In addition, we want the tarball/zipfile to have -SUMO in the
376 # name, and the unpacked directory to have -SUMO too. The easiest
377 # way to do this is to patch self.distribution and override the
378 # get_fullname() method. (an alternative is to modify
379 # self.distribution.metadata.version, but that also affects the
380 # contents of PKG-INFO).
381 fullname = self.distribution.get_fullname()
383 return fullname + "-SUMO"
384 self.distribution.get_fullname = get_fullname
386 return sdist.sdist.make_distribution(self)
388 # Tahoe's dependencies are managed by the find_links= entry in setup.cfg and
389 # the _auto_deps.install_requires list, which is used in the call to setup()
390 # at the end of this file
391 from _auto_deps import install_requires
393 setup(name='allmydata-tahoe',
395 description='secure, decentralized, fault-tolerant filesystem',
396 long_description=LONG_DESCRIPTION,
397 author='the allmydata.org Tahoe project',
398 author_email='tahoe-dev@allmydata.org',
399 url='http://allmydata.org/',
401 cmdclass={"show_supportlib": ShowSupportLib,
402 "show_pythonpath": ShowPythonPath,
403 "run_with_pythonpath": RunWithPythonPath,
404 "check_auto_deps": CheckAutoDeps,
405 "build_tahoe": BuildTahoe,
409 package_dir = {'':'src'},
410 packages=find_packages("src"),
411 classifiers=trove_classifiers,
412 test_suite="allmydata.test",
413 install_requires=install_requires,
414 include_package_data=True,
415 setup_requires=setup_requires,
416 entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
417 zip_safe=False, # We prefer unzipped for easier access.