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 # setuptools_trial/_version.py file). darcsver will also write a new version
101 # stamp in setuptools_trial/_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 CheckAutoDeps(Command):
195 def initialize_options(self):
197 def finalize_options(self):
201 _auto_deps.require_auto_deps()
204 class MakeExecutable(Command):
206 def initialize_options(self):
208 def finalize_options(self):
211 bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
213 # Create the 'tahoe-script.py' file under the 'bin' directory. The
214 # 'tahoe-script.py' file is exactly the same as the
215 # 'tahoe-script.template' script except that the shebang line is
216 # rewritten to use our sys.executable for the interpreter. On
217 # Windows, create a tahoe.exe will execute it. On non-Windows, make a
218 # symlink to it from 'tahoe'. The tahoe.exe will be copied from the
219 # setuptools egg's cli.exe and this will work from a zip-safe and
220 # non-zip-safe setuptools egg.
221 f = open(bin_tahoe_template, "rU")
222 script_lines = f.readlines()
224 script_lines[0] = "#!%s\n" % sys.executable
225 tahoe_script = os.path.join("bin", "tahoe-script.py")
226 f = open(tahoe_script, "w")
227 for line in script_lines:
230 if sys.platform == "win32":
231 setuptools_egg = require("setuptools")[0].location
232 if os.path.isfile(setuptools_egg):
233 z = zipfile.ZipFile(setuptools_egg, 'r')
234 for filename in z.namelist():
235 if 'cli.exe' in filename:
236 cli_exe = z.read(filename)
238 cli_exe = os.path.join(setuptools_egg, 'setuptools', 'cli.exe')
239 tahoe_exe = os.path.join("bin", "tahoe.exe")
240 if os.path.isfile(setuptools_egg):
241 f = open(tahoe_exe, 'wb')
245 shutil.copy(cli_exe, tahoe_exe)
248 os.remove(os.path.join('bin', 'tahoe'))
250 # okay, probably it was already gone
252 os.symlink('tahoe-script.py', os.path.join('bin', 'tahoe'))
254 # chmod +x bin/tahoe-script.py
255 old_mode = stat.S_IMODE(os.stat(tahoe_script)[stat.ST_MODE])
256 new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
257 stat.S_IXGRP | stat.S_IRGRP |
258 stat.S_IXOTH | stat.S_IROTH )
259 os.chmod(tahoe_script, new_mode)
261 class MySdist(sdist.sdist):
262 """ A hook in the sdist command so that we can determine whether this the
263 tarball should be 'SUMO' or not, i.e. whether or not to include the
264 external dependency tarballs. Note that we always include
265 misc/dependencies/* in the tarball; --sumo controls whether tahoe-deps/*
269 user_options = sdist.sdist.user_options + \
271 "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
273 boolean_options = ['sumo']
275 def initialize_options(self):
276 sdist.sdist.initialize_options(self)
279 def make_distribution(self):
280 # add our extra files to the list just before building the
281 # tarball/zipfile. We override make_distribution() instead of run()
282 # because setuptools.command.sdist.run() does not lend itself to
283 # easy/robust subclassing (the code we need to add goes right smack
284 # in the middle of a 12-line method). If this were the distutils
285 # version, we'd override get_file_list().
288 # If '--sumo' was specified, include tahoe-deps/* in the sdist.
289 # We assume that the user has fetched the tahoe-deps.tar.gz
290 # tarball and unpacked it already.
291 self.filelist.extend([os.path.join("tahoe-deps", fn)
292 for fn in os.listdir("tahoe-deps")])
293 # In addition, we want the tarball/zipfile to have -SUMO in the
294 # name, and the unpacked directory to have -SUMO too. The easiest
295 # way to do this is to patch self.distribution and override the
296 # get_fullname() method. (an alternative is to modify
297 # self.distribution.metadata.version, but that also affects the
298 # contents of PKG-INFO).
299 fullname = self.distribution.get_fullname()
301 return fullname + "-SUMO"
302 self.distribution.get_fullname = get_fullname
304 return sdist.sdist.make_distribution(self)
306 # Tahoe's dependencies are managed by the find_links= entry in setup.cfg and
307 # the _auto_deps.install_requires list, which is used in the call to setup()
309 from _auto_deps import install_requires
311 APPNAME='allmydata-tahoe'
312 APPNAMEFILE = os.path.join('src', 'allmydata', '_appname.py')
313 APPNAMEFILESTR = "__appname__ = '%s'" % (APPNAME,)
315 curappnamefilestr = open(APPNAMEFILE, 'rU').read()
316 except EnvironmentError:
317 # No file, or unreadable or something, okay then let's try to write one.
318 open(APPNAMEFILE, "w").write(APPNAMEFILESTR)
320 if curappnamefilestr.strip() != APPNAMEFILESTR:
321 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)
325 description='secure, decentralized, fault-tolerant filesystem',
326 long_description=LONG_DESCRIPTION,
327 author='the allmydata.org Tahoe project',
328 author_email='tahoe-dev@allmydata.org',
329 url='http://allmydata.org/',
331 cmdclass={"show_supportlib": ShowSupportLib,
332 "show_pythonpath": ShowPythonPath,
333 "run_with_pythonpath": RunWithPythonPath,
334 "check_auto_deps": CheckAutoDeps,
335 "make_executable": MakeExecutable,
338 package_dir = {'':'src'},
339 packages=find_packages("src"),
340 classifiers=trove_classifiers,
341 test_suite="allmydata.test",
342 install_requires=install_requires,
343 include_package_data=True,
344 setup_requires=setup_requires,
345 entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
346 zip_safe=False, # We prefer unzipped for easier access.