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 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:
46 shutil.copyfile("_auto_deps.py",
47 os.path.join("src", "allmydata", "_auto_deps.py"))
50 "Development Status :: 5 - Production/Stable",
51 "Environment :: Console",
52 "Environment :: Web Environment",
53 "License :: OSI Approved :: GNU General Public License (GPL)",
54 "License :: DFSG approved",
55 "License :: Other/Proprietary License",
56 "Intended Audience :: Developers",
57 "Intended Audience :: End Users/Desktop",
58 "Intended Audience :: System Administrators",
59 "Operating System :: Microsoft",
60 "Operating System :: Microsoft :: Windows",
61 "Operating System :: Microsoft :: Windows :: Windows NT/2000",
62 "Operating System :: Unix",
63 "Operating System :: POSIX :: Linux",
64 "Operating System :: POSIX",
65 "Operating System :: MacOS :: MacOS X",
66 "Operating System :: OS Independent",
67 "Natural Language :: English",
68 "Programming Language :: C",
69 "Programming Language :: Python",
70 "Programming Language :: Python :: 2",
71 "Programming Language :: Python :: 2.4",
72 "Programming Language :: Python :: 2.5",
73 "Programming Language :: Python :: 2.6",
75 "Topic :: System :: Systems Administration",
76 "Topic :: System :: Filesystems",
77 "Topic :: System :: Distributed Computing",
78 "Topic :: Software Development :: Libraries",
79 "Topic :: Communications :: Usenet News",
80 "Topic :: System :: Archiving :: Backup",
81 "Topic :: System :: Archiving :: Mirroring",
82 "Topic :: System :: Archiving",
87 """Welcome to the Tahoe project, a secure, decentralized, fault-tolerant
88 filesystem. All of the source code is available under a Free Software, Open
91 This filesystem is encrypted and spread over multiple peers in such a way that
92 it remains available even when some of the peers are unavailable,
93 malfunctioning, or malicious."""
98 # The darcsver command from the darcsver plugin is needed to initialize the
99 # distribution's .version attribute correctly. (It does this either by
100 # examining darcs history, or if that fails by reading the
101 # setuptools_trial/_version.py file). darcsver will also write a new version
102 # stamp in setuptools_trial/_version.py, with a version number derived from
103 # darcs history. Note that the setup.cfg file has an "[aliases]" section
104 # which enumerates commands that you might run and specifies that it will run
105 # darcsver before each one. If you add different commands (or if I forgot
106 # some that are already in use), you may need to add it to setup.cfg and
107 # configure it to run darcsver before your command, if you want the version
108 # number to be correct when that command runs.
109 # http://pypi.python.org/pypi/darcsver
110 setup_requires.append('darcsver >= 1.2.0')
112 # Nevow requires Twisted to setup, but doesn't declare that requirement in a
113 # way that enables setuptools to satisfy that requirement before Nevow's
114 # setup.py tried to "import twisted". Fortunately we require setuptools_trial
115 # to setup and setuptools_trial requires Twisted to install, so hopefully
116 # everything will work out until the Nevow issue is fixed:
117 # http://divmod.org/trac/ticket/2629 setuptools_trial is needed if you want
118 # "./setup.py trial" or "./setup.py test" to execute the tests (and in order
119 # to make sure Twisted is installed early enough -- see the paragraph above).
120 # http://pypi.python.org/pypi/setuptools_trial
121 setup_requires.extend(['setuptools_trial >= 0.5'])
123 # setuptools_darcs is required to produce complete distributions (such as
124 # with "sdist" or "bdist_egg") (unless there is a PKG-INFO file present which
125 # shows that this is itself a source distribution). For simplicity, and
126 # because there is some unknown error with setuptools_darcs when building and
127 # testing tahoe all in one python command on some platforms, we always add it
128 # to setup_requires. http://pypi.python.org/pypi/setuptools_darcs
129 setup_requires.append('setuptools_darcs >= 1.1.0')
131 class ShowSupportLib(Command):
133 def initialize_options(self):
135 def finalize_options(self):
138 # TODO: --quiet suppresses the 'running show_supportlib' message.
139 # Find a way to do this all the time.
140 print supportlib # TODO windowsy
142 class ShowPythonPath(Command):
144 def initialize_options(self):
146 def finalize_options(self):
149 # TODO: --quiet suppresses the 'running show_supportlib' message.
150 # Find a way to do this all the time.
151 print "PYTHONPATH=%s" % os.environ.get("PYTHONPATH", '')
153 class RunWithPythonPath(Command):
154 description = "Run a subcommand with PYTHONPATH set appropriately"
156 user_options = [ ("python", "p",
157 "Treat command string as arguments to a python executable"),
158 ("command=", "c", "Command to be run"),
159 ("directory=", "d", "Directory to run the command in"),
161 boolean_options = ["python"]
163 def initialize_options(self):
166 self.directory = None
167 def finalize_options(self):
170 oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
172 # grr silly split() behavior
174 os.environ['PYTHONPATH'] = os.pathsep.join(oldpp + [supportlib,])
176 # We must require the command to be safe to split on
177 # whitespace, and have --python and --directory to make it
178 # easier to achieve this.
182 command.append(sys.executable)
184 command.extend(self.command.split())
186 raise RuntimeError("The --command argument is mandatory")
188 os.chdir(self.directory)
190 print "command =", " ".join(command)
191 rc = subprocess.call(command)
194 class CheckAutoDeps(Command):
196 def initialize_options(self):
198 def finalize_options(self):
202 _auto_deps.require_auto_deps()
205 class MakeExecutable(Command):
207 def initialize_options(self):
209 def finalize_options(self):
212 bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
214 # Create the 'tahoe-script.py' file under the 'bin' directory. The
215 # 'tahoe-script.py' file is exactly the same as the
216 # 'tahoe-script.template' script except that the shebang line is
217 # rewritten to use our sys.executable for the interpreter. On
218 # Windows, create a tahoe.exe will execute it. On non-Windows, make a
219 # symlink to it from 'tahoe'. The tahoe.exe will be copied from the
220 # setuptools egg's cli.exe and this will work from a zip-safe and
221 # non-zip-safe setuptools egg.
222 f = open(bin_tahoe_template, "rU")
223 script_lines = f.readlines()
225 script_lines[0] = "#!%s\n" % sys.executable
226 tahoe_script = os.path.join("bin", "tahoe-script.py")
227 f = open(tahoe_script, "w")
228 for line in script_lines:
231 if sys.platform == "win32":
232 setuptools_egg = require("setuptools")[0].location
233 if os.path.isfile(setuptools_egg):
234 z = zipfile.ZipFile(setuptools_egg, 'r')
235 for filename in z.namelist():
236 if 'cli.exe' in filename:
237 cli_exe = z.read(filename)
239 cli_exe = os.path.join(setuptools_egg, 'setuptools', 'cli.exe')
240 tahoe_exe = os.path.join("bin", "tahoe.exe")
241 if os.path.isfile(setuptools_egg):
242 f = open(tahoe_exe, 'wb')
246 shutil.copy(cli_exe, tahoe_exe)
249 os.remove(os.path.join('bin', 'tahoe'))
251 # okay, probably it was already gone
253 os.symlink('tahoe-script.py', os.path.join('bin', 'tahoe'))
255 # chmod +x bin/tahoe-script.py
256 old_mode = stat.S_IMODE(os.stat(tahoe_script)[stat.ST_MODE])
257 new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
258 stat.S_IXGRP | stat.S_IRGRP |
259 stat.S_IXOTH | stat.S_IROTH )
260 os.chmod(tahoe_script, new_mode)
262 class MySdist(sdist.sdist):
263 """ A hook in the sdist command so that we can determine whether this the
264 tarball should be 'SUMO' or not, i.e. whether or not to include the
265 external dependency tarballs. Note that we always include
266 misc/dependencies/* in the tarball; --sumo controls whether tahoe-deps/*
270 user_options = sdist.sdist.user_options + \
272 "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
274 boolean_options = ['sumo']
276 def initialize_options(self):
277 sdist.sdist.initialize_options(self)
280 def make_distribution(self):
281 # add our extra files to the list just before building the
282 # tarball/zipfile. We override make_distribution() instead of run()
283 # because setuptools.command.sdist.run() does not lend itself to
284 # easy/robust subclassing (the code we need to add goes right smack
285 # in the middle of a 12-line method). If this were the distutils
286 # version, we'd override get_file_list().
289 # If '--sumo' was specified, include tahoe-deps/* in the sdist.
290 # We assume that the user has fetched the tahoe-deps.tar.gz
291 # tarball and unpacked it already.
292 self.filelist.extend([os.path.join("tahoe-deps", fn)
293 for fn in os.listdir("tahoe-deps")])
294 # In addition, we want the tarball/zipfile to have -SUMO in the
295 # name, and the unpacked directory to have -SUMO too. The easiest
296 # way to do this is to patch self.distribution and override the
297 # get_fullname() method. (an alternative is to modify
298 # self.distribution.metadata.version, but that also affects the
299 # contents of PKG-INFO).
300 fullname = self.distribution.get_fullname()
302 return fullname + "-SUMO"
303 self.distribution.get_fullname = get_fullname
305 return sdist.sdist.make_distribution(self)
307 # Tahoe's dependencies are managed by the find_links= entry in setup.cfg and
308 # the _auto_deps.install_requires list, which is used in the call to setup()
310 from _auto_deps import install_requires
312 APPNAME='allmydata-tahoe'
313 APPNAMEFILE = os.path.join('src', 'allmydata', '_appname.py')
314 APPNAMEFILESTR = "__appname__ = '%s'" % (APPNAME,)
316 curappnamefilestr = open(APPNAMEFILE, 'rU').read()
317 except EnvironmentError:
318 # No file, or unreadable or something, okay then let's try to write one.
319 open(APPNAMEFILE, "w").write(APPNAMEFILESTR)
321 if curappnamefilestr.strip() != APPNAMEFILESTR:
322 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)
326 description='secure, decentralized, fault-tolerant filesystem',
327 long_description=LONG_DESCRIPTION,
328 author='the allmydata.org Tahoe project',
329 author_email='tahoe-dev@allmydata.org',
330 url='http://allmydata.org/',
332 cmdclass={"show_supportlib": ShowSupportLib,
333 "show_pythonpath": ShowPythonPath,
334 "run_with_pythonpath": RunWithPythonPath,
335 "check_auto_deps": CheckAutoDeps,
336 "make_executable": MakeExecutable,
339 package_dir = {'':'src'},
340 packages=find_packages("src"),
341 classifiers=trove_classifiers,
342 test_suite="allmydata.test",
343 install_requires=install_requires,
344 include_package_data=True,
345 setup_requires=setup_requires,
346 entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
347 zip_safe=False, # We prefer unzipped for easier access.