]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - setup.py
docs: update relnotes.txt, relnotes-short.txt, and others documentation bits for...
[tahoe-lafs/tahoe-lafs.git] / setup.py
1 #! /usr/bin/env python
2
3 # Allmydata Tahoe -- secure, distributed storage grid
4 #
5 # Copyright (C) 2008-2009 Allmydata, Inc.
6 #
7 # This file is part of Tahoe-LAFS.
8 #
9 # See the docs/about.html file for licensing information.
10
11 import os, shutil, stat, subprocess, sys, zipfile
12
13 ##### sys.path management
14
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")
19     else:
20         return os.path.join(prefixdir, "lib", pyver, "site-packages")
21
22 basedir = os.path.dirname(os.path.abspath(__file__))
23 supportlib = pylibdir(os.path.join(basedir, "support"))
24
25 try:
26     from ez_setup import use_setuptools
27 except ImportError:
28     pass
29 else:
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.
35     # "setup_requires").
36     use_setuptools(download_delay=0, min_version="0.6c12dev")
37
38 from setuptools import find_packages, setup
39 from setuptools.command import sdist
40 from setuptools import Command
41 from pkg_resources import require
42
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"))
47
48 trove_classifiers=[
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",
73     "Topic :: Utilities",
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",
82     ]
83
84
85 LONG_DESCRIPTION=\
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
88 Source licence.
89
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."""
93
94
95 setup_requires = []
96
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')
110
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'])
121
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')
129
130 # stdeb is required to produce Debian files with the "sdist_dsc" command.
131 if "sdist_dsc" in sys.argv:
132     setup_requires.append('stdeb >= 0.3')
133
134 class ShowSupportLib(Command):
135     user_options = []
136     def initialize_options(self):
137         pass
138     def finalize_options(self):
139         pass
140     def run(self):
141         # TODO: --quiet suppresses the 'running show_supportlib' message.
142         # Find a way to do this all the time.
143         print supportlib # TODO windowsy
144
145 class ShowPythonPath(Command):
146     user_options = []
147     def initialize_options(self):
148         pass
149     def finalize_options(self):
150         pass
151     def run(self):
152         # TODO: --quiet suppresses the 'running show_supportlib' message.
153         # Find a way to do this all the time.
154         print "PYTHONPATH=%s" % os.environ.get("PYTHONPATH", '')
155
156 class RunWithPythonPath(Command):
157     description = "Run a subcommand with PYTHONPATH set appropriately"
158
159     user_options = [ ("python", "p",
160                       "Treat command string as arguments to a python executable"),
161                      ("command=", "c", "Command to be run"),
162                      ("directory=", "d", "Directory to run the command in"),
163                      ]
164     boolean_options = ["python"]
165
166     def initialize_options(self):
167         self.command = None
168         self.python = False
169         self.directory = None
170     def finalize_options(self):
171         pass
172     def run(self):
173         oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
174         if oldpp == [""]:
175             # grr silly split() behavior
176             oldpp = []
177         os.environ['PYTHONPATH'] = os.pathsep.join(oldpp + [supportlib,])
178
179         # We must require the command to be safe to split on
180         # whitespace, and have --python and --directory to make it
181         # easier to achieve this.
182
183         command = []
184         if self.python:
185             command.append(sys.executable)
186         if self.command:
187             command.extend(self.command.split())
188         if not command:
189             raise RuntimeError("The --command argument is mandatory")
190         if self.directory:
191             os.chdir(self.directory)
192         if self.verbose:
193             print "command =", " ".join(command)
194         rc = subprocess.call(command)
195         sys.exit(rc)
196
197 class TestMacDiskImage(Command):
198     user_options = []
199     def initialize_options(self):
200         pass
201     def finalize_options(self):
202         pass
203     def run(self):
204         import sys
205         sys.path.append('misc')
206         import test_mac_diskimage
207         return test_mac_diskimage.test_mac_diskimage('Allmydata', version=self.distribution.metadata.version)
208
209 class CheckAutoDeps(Command):
210     user_options = []
211     def initialize_options(self):
212         pass
213     def finalize_options(self):
214         pass
215     def run(self):
216         import _auto_deps
217         _auto_deps.require_auto_deps()
218
219
220 class MakeExecutable(Command):
221     user_options = []
222     def initialize_options(self):
223         pass
224     def finalize_options(self):
225         pass
226     def run(self):
227         bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
228
229         # Create the 'tahoe-script.py' file under the 'bin' directory. The
230         # 'tahoe-script.py' file is exactly the same as the
231         # 'tahoe-script.template' script except that the shebang line is
232         # rewritten to use our sys.executable for the interpreter. On
233         # Windows, create a tahoe.exe will execute it. On non-Windows, make a
234         # symlink to it from 'tahoe'. The tahoe.exe will be copied from the
235         # setuptools egg's cli.exe and this will work from a zip-safe and
236         # non-zip-safe setuptools egg.
237         f = open(bin_tahoe_template, "rU")
238         script_lines = f.readlines()
239         f.close()
240         script_lines[0] = "#!%s\n" % sys.executable
241         tahoe_script = os.path.join("bin", "tahoe-script.py")
242         f = open(tahoe_script, "w")
243         for line in script_lines:
244             f.write(line)
245         f.close()
246         if sys.platform == "win32":
247             setuptools_egg = require("setuptools")[0].location
248             if os.path.isfile(setuptools_egg):
249                 z = zipfile.ZipFile(setuptools_egg, 'r')
250                 for filename in z.namelist():
251                     if 'cli.exe' in filename:
252                         cli_exe = z.read(filename)
253             else:
254                 cli_exe = os.path.join(setuptools_egg, 'setuptools', 'cli.exe')
255             tahoe_exe = os.path.join("bin", "tahoe.exe")
256             if os.path.isfile(setuptools_egg):
257                 f = open(tahoe_exe, 'wb')
258                 f.write(cli_exe)
259                 f.close()
260             else:
261                 shutil.copy(cli_exe, tahoe_exe)
262         else:
263             try:
264                 os.remove(os.path.join('bin', 'tahoe'))
265             except:
266                 # okay, probably it was already gone
267                 pass
268             os.symlink('tahoe-script.py', os.path.join('bin', 'tahoe'))
269
270         # chmod +x bin/tahoe-script.py
271         old_mode = stat.S_IMODE(os.stat(tahoe_script)[stat.ST_MODE])
272         new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
273                                stat.S_IXGRP | stat.S_IRGRP |
274                                stat.S_IXOTH | stat.S_IROTH )
275         os.chmod(tahoe_script, new_mode)
276
277 class MySdist(sdist.sdist):
278     """ A hook in the sdist command so that we can determine whether this the
279     tarball should be 'SUMO' or not, i.e. whether or not to include the
280     external dependency tarballs. Note that we always include
281     misc/dependencies/* in the tarball; --sumo controls whether tahoe-deps/*
282     is included as well.
283     """
284
285     user_options = sdist.sdist.user_options + \
286         [('sumo', 's',
287           "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
288          ]
289     boolean_options = ['sumo']
290
291     def initialize_options(self):
292         sdist.sdist.initialize_options(self)
293         self.sumo = False
294
295     def make_distribution(self):
296         # add our extra files to the list just before building the
297         # tarball/zipfile. We override make_distribution() instead of run()
298         # because setuptools.command.sdist.run() does not lend itself to
299         # easy/robust subclassing (the code we need to add goes right smack
300         # in the middle of a 12-line method). If this were the distutils
301         # version, we'd override get_file_list().
302
303         if self.sumo:
304             # If '--sumo' was specified, include tahoe-deps/* in the sdist.
305             # We assume that the user has fetched the tahoe-deps.tar.gz
306             # tarball and unpacked it already.
307             self.filelist.extend([os.path.join("tahoe-deps", fn)
308                                   for fn in os.listdir("tahoe-deps")])
309             # In addition, we want the tarball/zipfile to have -SUMO in the
310             # name, and the unpacked directory to have -SUMO too. The easiest
311             # way to do this is to patch self.distribution and override the
312             # get_fullname() method. (an alternative is to modify
313             # self.distribution.metadata.version, but that also affects the
314             # contents of PKG-INFO).
315             fullname = self.distribution.get_fullname()
316             def get_fullname():
317                 return fullname + "-SUMO"
318             self.distribution.get_fullname = get_fullname
319
320         return sdist.sdist.make_distribution(self)
321
322 # Tahoe's dependencies are managed by the find_links= entry in setup.cfg and
323 # the _auto_deps.install_requires list, which is used in the call to setup()
324 # below.
325 from _auto_deps import install_requires
326
327 APPNAME='allmydata-tahoe'
328 APPNAMEFILE = os.path.join('src', 'allmydata', '_appname.py')
329 APPNAMEFILESTR = "__appname__ = '%s'" % (APPNAME,)
330 try:
331     curappnamefilestr = open(APPNAMEFILE, 'rU').read()
332 except EnvironmentError:
333     # No file, or unreadable or something, okay then let's try to write one.
334     open(APPNAMEFILE, "w").write(APPNAMEFILESTR)
335 else:
336     if curappnamefilestr.strip() != APPNAMEFILESTR:
337         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)
338         sys.exit(-1)
339
340 setup(name=APPNAME,
341       description='secure, decentralized, fault-tolerant filesystem',
342       long_description=LONG_DESCRIPTION,
343       author='the allmydata.org Tahoe project',
344       author_email='tahoe-dev@allmydata.org',
345       url='http://allmydata.org/',
346       license='GNU GPL',
347       cmdclass={"show_supportlib": ShowSupportLib,
348                 "show_pythonpath": ShowPythonPath,
349                 "run_with_pythonpath": RunWithPythonPath,
350                 "check_auto_deps": CheckAutoDeps,
351                 "test_mac_diskimage": TestMacDiskImage,
352                 "make_executable": MakeExecutable,
353                 "sdist": MySdist,
354                 },
355       package_dir = {'':'src'},
356       packages=find_packages("src"),
357       classifiers=trove_classifiers,
358       test_suite="allmydata.test",
359       install_requires=install_requires,
360       include_package_data=True,
361       setup_requires=setup_requires,
362       entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
363       zip_safe=False, # We prefer unzipped for easier access.
364       )