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, 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 from ez_setup import use_setuptools
30 # This invokes our own customized version of ez_setup.py to make sure
31 # that setuptools v0.6c12dev (which is our own toothpick of setuptools)
32 # is used to build. Note that we can use any version of setuptools >=
33 # 0.6c6 to *run* -- see _auto_deps.py for run-time dependencies (a.k.a.
34 # "install_requires") -- this is only for build-time dependencies (a.k.a.
36 use_setuptools(download_delay=0, min_version="0.6c12dev")
38 from setuptools import find_packages, setup
39 from setuptools.command import sdist
40 from setuptools import Command
41 from pkg_resources import require
43 # Make the dependency-version-requirement, which is used by the Makefile at
44 # build-time, also available to the app at runtime:
45 shutil.copyfile("_auto_deps.py",
46 os.path.join("src", "allmydata", "_auto_deps.py"))
49 "Development Status :: 5 - Production/Stable",
50 "Environment :: Console",
51 "Environment :: Web Environment",
52 "License :: OSI Approved :: GNU General Public License (GPL)",
53 "License :: DFSG approved",
54 "License :: Other/Proprietary License",
55 "Intended Audience :: Developers",
56 "Intended Audience :: End Users/Desktop",
57 "Intended Audience :: System Administrators",
58 "Operating System :: Microsoft",
59 "Operating System :: Microsoft :: Windows",
60 "Operating System :: Microsoft :: Windows :: Windows NT/2000",
61 "Operating System :: Unix",
62 "Operating System :: POSIX :: Linux",
63 "Operating System :: POSIX",
64 "Operating System :: MacOS :: MacOS X",
65 "Operating System :: OS Independent",
66 "Natural Language :: English",
67 "Programming Language :: C",
68 "Programming Language :: Python",
69 "Programming Language :: Python :: 2",
70 "Programming Language :: Python :: 2.4",
71 "Programming Language :: Python :: 2.5",
72 "Programming Language :: Python :: 2.6",
74 "Topic :: System :: Systems Administration",
75 "Topic :: System :: Filesystems",
76 "Topic :: System :: Distributed Computing",
77 "Topic :: Software Development :: Libraries",
78 "Topic :: Communications :: Usenet News",
79 "Topic :: System :: Archiving :: Backup",
80 "Topic :: System :: Archiving :: Mirroring",
81 "Topic :: System :: Archiving",
86 """Welcome to the Tahoe project, a secure, decentralized, fault-tolerant
87 filesystem. All of the source code is available under a Free Software, Open
90 This filesystem is encrypted and spread over multiple peers in such a way that
91 it remains available even when some of the peers are unavailable,
92 malfunctioning, or malicious."""
97 # The darcsver command from the darcsver plugin is needed to initialize the
98 # distribution's .version attribute correctly. (It does this either by
99 # examining darcs history, or if that fails by reading the
100 # src/allmydata/_version.py file). darcsver will also write a new version
101 # stamp in src/allmydata/_version.py, with a version number derived from
102 # darcs history. Note that the setup.cfg file has an "[aliases]" section
103 # which enumerates commands that you might run and specifies that it will run
104 # darcsver before each one. If you add different commands (or if I forgot
105 # some that are already in use), you may need to add it to setup.cfg and
106 # configure it to run darcsver before your command, if you want the version
107 # number to be correct when that command runs.
108 # http://pypi.python.org/pypi/darcsver
109 setup_requires.append('darcsver >= 1.2.0')
111 # Nevow requires Twisted to setup, but doesn't declare that requirement in a
112 # way that enables setuptools to satisfy that requirement before Nevow's
113 # setup.py tried to "import twisted". Fortunately we require setuptools_trial
114 # to setup and setuptools_trial requires Twisted to install, so hopefully
115 # everything will work out until the Nevow issue is fixed:
116 # http://divmod.org/trac/ticket/2629 setuptools_trial is needed if you want
117 # "./setup.py trial" or "./setup.py test" to execute the tests (and in order
118 # to make sure Twisted is installed early enough -- see the paragraph above).
119 # http://pypi.python.org/pypi/setuptools_trial
120 setup_requires.extend(['setuptools_trial >= 0.5'])
122 # setuptools_darcs is required to produce complete distributions (such as
123 # with "sdist" or "bdist_egg") (unless there is a PKG-INFO file present which
124 # shows that this is itself a source distribution). For simplicity, and
125 # because there is some unknown error with setuptools_darcs when building and
126 # testing tahoe all in one python command on some platforms, we always add it
127 # to setup_requires. http://pypi.python.org/pypi/setuptools_darcs
128 setup_requires.append('setuptools_darcs >= 1.1.0')
130 class ShowSupportLib(Command):
132 def initialize_options(self):
134 def finalize_options(self):
137 # TODO: --quiet suppresses the 'running show_supportlib' message.
138 # Find a way to do this all the time.
139 print supportlib # TODO windowsy
141 class ShowPythonPath(Command):
143 def initialize_options(self):
145 def finalize_options(self):
148 # TODO: --quiet suppresses the 'running show_supportlib' message.
149 # Find a way to do this all the time.
150 print "PYTHONPATH=%s" % os.environ.get("PYTHONPATH", '')
152 class RunWithPythonPath(Command):
153 description = "Run a subcommand with PYTHONPATH set appropriately"
155 user_options = [ ("python", "p",
156 "Treat command string as arguments to a python executable"),
157 ("command=", "c", "Command to be run"),
158 ("directory=", "d", "Directory to run the command in"),
160 boolean_options = ["python"]
162 def initialize_options(self):
165 self.directory = None
166 def finalize_options(self):
169 oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
171 # grr silly split() behavior
173 os.environ['PYTHONPATH'] = os.pathsep.join(oldpp + [supportlib,])
175 # We must require the command to be safe to split on
176 # whitespace, and have --python and --directory to make it
177 # easier to achieve this.
181 command.append(sys.executable)
183 command.extend(self.command.split())
185 raise RuntimeError("The --command argument is mandatory")
187 os.chdir(self.directory)
189 print "command =", " ".join(command)
190 rc = subprocess.call(command)
193 class TestMacDiskImage(Command):
195 def initialize_options(self):
197 def finalize_options(self):
201 sys.path.append('misc')
202 import test_mac_diskimage
203 return test_mac_diskimage.test_mac_diskimage('Allmydata', version=self.distribution.metadata.version)
205 class CheckAutoDeps(Command):
207 def initialize_options(self):
209 def finalize_options(self):
213 _auto_deps.require_auto_deps()
216 class MakeExecutable(Command):
218 def initialize_options(self):
220 def finalize_options(self):
223 bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
225 # Create the 'tahoe-script.py' file under the 'bin' directory. The
226 # 'tahoe-script.py' file is exactly the same as the
227 # 'tahoe-script.template' script except that the shebang line is
228 # rewritten to use our sys.executable for the interpreter. On
229 # Windows, create a tahoe.exe will execute it. On non-Windows, make a
230 # symlink to it from 'tahoe'. The tahoe.exe will be copied from the
231 # setuptools egg's cli.exe and this will work from a zip-safe and
232 # non-zip-safe setuptools egg.
233 f = open(bin_tahoe_template, "rU")
234 script_lines = f.readlines()
236 script_lines[0] = "#!%s\n" % sys.executable
237 tahoe_script = os.path.join("bin", "tahoe-script.py")
238 f = open(tahoe_script, "w")
239 for line in script_lines:
242 if sys.platform == "win32":
243 setuptools_egg = require("setuptools")[0].location
244 if os.path.isfile(setuptools_egg):
245 z = zipfile.ZipFile(setuptools_egg, 'r')
246 for filename in z.namelist():
247 if 'cli.exe' in filename:
248 cli_exe = z.read(filename)
250 cli_exe = os.path.join(setuptools_egg, 'setuptools', 'cli.exe')
251 tahoe_exe = os.path.join("bin", "tahoe.exe")
252 if os.path.isfile(setuptools_egg):
253 f = open(tahoe_exe, 'wb')
257 shutil.copy(cli_exe, tahoe_exe)
260 os.remove(os.path.join('bin', 'tahoe'))
262 # okay, probably it was already gone
264 os.symlink('tahoe-script.py', os.path.join('bin', 'tahoe'))
266 # chmod +x bin/tahoe-script.py
267 old_mode = stat.S_IMODE(os.stat(tahoe_script)[stat.ST_MODE])
268 new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
269 stat.S_IXGRP | stat.S_IRGRP |
270 stat.S_IXOTH | stat.S_IROTH )
271 os.chmod(tahoe_script, new_mode)
273 class MySdist(sdist.sdist):
274 """ A hook in the sdist command so that we can determine whether this the
275 tarball should be 'SUMO' or not, i.e. whether or not to include the
276 external dependency tarballs. Note that we always include
277 misc/dependencies/* in the tarball; --sumo controls whether tahoe-deps/*
281 user_options = sdist.sdist.user_options + \
283 "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
285 boolean_options = ['sumo']
287 def initialize_options(self):
288 sdist.sdist.initialize_options(self)
291 def make_distribution(self):
292 # add our extra files to the list just before building the
293 # tarball/zipfile. We override make_distribution() instead of run()
294 # because setuptools.command.sdist.run() does not lend itself to
295 # easy/robust subclassing (the code we need to add goes right smack
296 # in the middle of a 12-line method). If this were the distutils
297 # version, we'd override get_file_list().
300 # If '--sumo' was specified, include tahoe-deps/* in the sdist.
301 # We assume that the user has fetched the tahoe-deps.tar.gz
302 # tarball and unpacked it already.
303 self.filelist.extend([os.path.join("tahoe-deps", fn)
304 for fn in os.listdir("tahoe-deps")])
305 # In addition, we want the tarball/zipfile to have -SUMO in the
306 # name, and the unpacked directory to have -SUMO too. The easiest
307 # way to do this is to patch self.distribution and override the
308 # get_fullname() method. (an alternative is to modify
309 # self.distribution.metadata.version, but that also affects the
310 # contents of PKG-INFO).
311 fullname = self.distribution.get_fullname()
313 return fullname + "-SUMO"
314 self.distribution.get_fullname = get_fullname
316 return sdist.sdist.make_distribution(self)
318 # Tahoe's dependencies are managed by the find_links= entry in setup.cfg and
319 # the _auto_deps.install_requires list, which is used in the call to setup()
321 from _auto_deps import install_requires
323 APPNAME='allmydata-tahoe'
324 APPNAMEFILE = os.path.join('src', 'allmydata', '_appname.py')
325 APPNAMEFILESTR = "__appname__ = '%s'" % (APPNAME,)
327 curappnamefilestr = open(APPNAMEFILE, 'rU').read()
328 except EnvironmentError:
329 # No file, or unreadable or something, okay then let's try to write one.
330 open(APPNAMEFILE, "w").write(APPNAMEFILESTR)
332 if curappnamefilestr.strip() != APPNAMEFILESTR:
333 print "Error -- this setup.py file is configured with the 'application name' to be '%s', but there is already a file in place in '%s' which contains the contents '%s'. If the file is wrong, please remove it and setup.py will regenerate it and write '%s' into it." % (APPNAME, APPNAMEFILE, curappnamefilestr, APPNAMEFILESTR)
337 description='secure, decentralized, fault-tolerant filesystem',
338 long_description=LONG_DESCRIPTION,
339 author='the allmydata.org Tahoe project',
340 author_email='tahoe-dev@allmydata.org',
341 url='http://allmydata.org/',
343 cmdclass={"show_supportlib": ShowSupportLib,
344 "show_pythonpath": ShowPythonPath,
345 "run_with_pythonpath": RunWithPythonPath,
346 "check_auto_deps": CheckAutoDeps,
347 "test_mac_diskimage": TestMacDiskImage,
348 "make_executable": MakeExecutable,
351 package_dir = {'':'src'},
352 packages=find_packages("src"),
353 classifiers=trove_classifiers,
354 test_suite="allmydata.test",
355 install_requires=install_requires,
356 include_package_data=True,
357 setup_requires=setup_requires,
358 entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
359 zip_safe=False, # We prefer unzipped for easier access.