]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - setup.py
setup.py: fix pyflakes complaints
[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 Allmydata, Inc.
6 #
7 # This file is part of tahoe.
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 # 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')
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 class ShowSupportLib(Command):
131     user_options = []
132     def initialize_options(self):
133         pass
134     def finalize_options(self):
135         pass
136     def run(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
140
141 class ShowPythonPath(Command):
142     user_options = []
143     def initialize_options(self):
144         pass
145     def finalize_options(self):
146         pass
147     def run(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", '')
151
152 class RunWithPythonPath(Command):
153     description = "Run a subcommand with PYTHONPATH set appropriately"
154
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"),
159                      ]
160     boolean_options = ["python"]
161
162     def initialize_options(self):
163         self.command = None
164         self.python = False
165         self.directory = None
166     def finalize_options(self):
167         pass
168     def run(self):
169         oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
170         if oldpp == [""]:
171             # grr silly split() behavior
172             oldpp = []
173         os.environ['PYTHONPATH'] = os.pathsep.join(oldpp + [supportlib,])
174
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.
178
179         command = []
180         if self.python:
181             command.append(sys.executable)
182         if self.command:
183             command.extend(self.command.split())
184         if not command:
185             raise RuntimeError("The --command argument is mandatory")
186         if self.directory:
187             os.chdir(self.directory)
188         if self.verbose:
189             print "command =", " ".join(command)
190         rc = subprocess.call(command)
191         sys.exit(rc)
192
193 class CheckAutoDeps(Command):
194     user_options = []
195     def initialize_options(self):
196         pass
197     def finalize_options(self):
198         pass
199     def run(self):
200         import _auto_deps
201         _auto_deps.require_auto_deps()
202
203
204 class MakeExecutable(Command):
205     user_options = []
206     def initialize_options(self):
207         pass
208     def finalize_options(self):
209         pass
210     def run(self):
211         bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
212
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()
223         f.close()
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:
228             f.write(line)
229         f.close()
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)
237             else:
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')
242                 f.write(cli_exe)
243                 f.close()
244             else:
245                 shutil.copy(cli_exe, tahoe_exe)
246         else:
247             try:
248                 os.remove(os.path.join('bin', 'tahoe'))
249             except:
250                 # okay, probably it was already gone
251                 pass
252             os.symlink('tahoe-script.py', os.path.join('bin', 'tahoe'))
253
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)
260
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/*
266     is included as well.
267     """
268
269     user_options = sdist.sdist.user_options + \
270         [('sumo', 's',
271           "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
272          ]
273     boolean_options = ['sumo']
274
275     def initialize_options(self):
276         sdist.sdist.initialize_options(self)
277         self.sumo = False
278
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().
286
287         if self.sumo:
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()
300             def get_fullname():
301                 return fullname + "-SUMO"
302             self.distribution.get_fullname = get_fullname
303
304         return sdist.sdist.make_distribution(self)
305
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()
308 # below.
309 from _auto_deps import install_requires
310
311 APPNAME='allmydata-tahoe'
312 APPNAMEFILE = os.path.join('src', 'allmydata', '_appname.py')
313 APPNAMEFILESTR = "__appname__ = '%s'" % (APPNAME,)
314 try:
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)
319 else:
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)
322         sys.exit(-1)
323
324 setup(name=APPNAME,
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/',
330       license='GNU GPL',
331       cmdclass={"show_supportlib": ShowSupportLib,
332                 "show_pythonpath": ShowPythonPath,
333                 "run_with_pythonpath": RunWithPythonPath,
334                 "check_auto_deps": CheckAutoDeps,
335                 "make_executable": MakeExecutable,
336                 "sdist": MySdist,
337                 },
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.
347       )