]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - setup.py
docs: update README, mv it to README.txt, update setup.py
[tahoe-lafs/tahoe-lafs.git] / setup.py
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # Tahoe-LAFS -- secure, distributed storage grid
5 #
6 # Copyright © 2008-2010 Allmydata, Inc.
7 #
8 # This file is part of Tahoe-LAFS.
9 #
10 # See the docs/about.html file for licensing information.
11
12 import os, shutil, stat, subprocess, sys, zipfile, re
13
14 ##### sys.path management
15
16 def pylibdir(prefixdir):
17     pyver = "python%d.%d" % (sys.version_info[:2])
18     if sys.platform == "win32":
19         return os.path.join(prefixdir, "Lib", "site-packages")
20     else:
21         return os.path.join(prefixdir, "lib", pyver, "site-packages")
22
23 basedir = os.path.dirname(os.path.abspath(__file__))
24 supportlib = pylibdir(os.path.join(basedir, "support"))
25
26 # locate our version number
27
28 def read_version_py(infname):
29     try:
30         verstrline = open(infname, "rt").read()
31     except EnvironmentError:
32         return None
33     else:
34         VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
35         mo = re.search(VSRE, verstrline, re.M)
36         if mo:
37             return mo.group(1)
38
39 version = read_version_py("src/allmydata/_version.py")
40
41 try:
42     from ez_setup import use_setuptools
43 except ImportError:
44     pass
45 else:
46     # This invokes our own customized version of ez_setup.py to make sure
47     # that setuptools v0.6c12dev (which is our own toothpick of setuptools)
48     # is used to build. Note that we can use any version of setuptools >=
49     # 0.6c6 to *run* -- see _auto_deps.py for run-time dependencies (a.k.a.
50     # "install_requires") -- this is only for build-time dependencies (a.k.a.
51     # "setup_requires").
52     use_setuptools(download_delay=0, min_version="0.6c12dev")
53
54 from setuptools import find_packages, setup
55 from setuptools.command import sdist
56 from setuptools import Command
57 from pkg_resources import require
58
59 # Make the dependency-version-requirement, which is used by the Makefile at
60 # build-time, also available to the app at runtime:
61 shutil.copyfile("_auto_deps.py",
62                 os.path.join("src", "allmydata", "_auto_deps.py"))
63
64 trove_classifiers=[
65     "Development Status :: 5 - Production/Stable",
66     "Environment :: Console",
67     "Environment :: Web Environment",
68     "License :: OSI Approved :: GNU General Public License (GPL)",
69     "License :: DFSG approved",
70     "License :: Other/Proprietary License",
71     "Intended Audience :: Developers",
72     "Intended Audience :: End Users/Desktop",
73     "Intended Audience :: System Administrators",
74     "Operating System :: Microsoft",
75     "Operating System :: Microsoft :: Windows",
76     "Operating System :: Microsoft :: Windows :: Windows NT/2000",
77     "Operating System :: Unix",
78     "Operating System :: POSIX :: Linux",
79     "Operating System :: POSIX",
80     "Operating System :: MacOS :: MacOS X",
81     "Operating System :: OS Independent",
82     "Natural Language :: English",
83     "Programming Language :: C",
84     "Programming Language :: Python",
85     "Programming Language :: Python :: 2",
86     "Programming Language :: Python :: 2.4",
87     "Programming Language :: Python :: 2.5",
88     "Programming Language :: Python :: 2.6",
89     "Topic :: Utilities",
90     "Topic :: System :: Systems Administration",
91     "Topic :: System :: Filesystems",
92     "Topic :: System :: Distributed Computing",
93     "Topic :: Software Development :: Libraries",
94     "Topic :: Communications :: Usenet News",
95     "Topic :: System :: Archiving :: Backup",
96     "Topic :: System :: Archiving :: Mirroring",
97     "Topic :: System :: Archiving",
98     ]
99
100
101 setup_requires = []
102
103 # The darcsver command from the darcsver plugin is needed to initialize the
104 # distribution's .version attribute correctly. (It does this either by
105 # examining darcs history, or if that fails by reading the
106 # src/allmydata/_version.py file). darcsver will also write a new version
107 # stamp in src/allmydata/_version.py, with a version number derived from
108 # darcs history. Note that the setup.cfg file has an "[aliases]" section
109 # which enumerates commands that you might run and specifies that it will run
110 # darcsver before each one. If you add different commands (or if I forgot
111 # some that are already in use), you may need to add it to setup.cfg and
112 # configure it to run darcsver before your command, if you want the version
113 # number to be correct when that command runs.
114 # http://pypi.python.org/pypi/darcsver
115 setup_requires.append('darcsver >= 1.2.0')
116
117 # Nevow requires Twisted to setup, but doesn't declare that requirement in a
118 # way that enables setuptools to satisfy that requirement before Nevow's
119 # setup.py tried to "import twisted". Fortunately we require setuptools_trial
120 # to setup and setuptools_trial requires Twisted to install, so hopefully
121 # everything will work out until the Nevow issue is fixed:
122 # http://divmod.org/trac/ticket/2629 setuptools_trial is needed if you want
123 # "./setup.py trial" or "./setup.py test" to execute the tests (and in order
124 # to make sure Twisted is installed early enough -- see the paragraph above).
125 # http://pypi.python.org/pypi/setuptools_trial
126 setup_requires.extend(['setuptools_trial >= 0.5'])
127
128 # setuptools_darcs is required to produce complete distributions (such as
129 # with "sdist" or "bdist_egg") (unless there is a PKG-INFO file present which
130 # shows that this is itself a source distribution). For simplicity, and
131 # because there is some unknown error with setuptools_darcs when building and
132 # testing tahoe all in one python command on some platforms, we always add it
133 # to setup_requires. http://pypi.python.org/pypi/setuptools_darcs
134 setup_requires.append('setuptools_darcs >= 1.1.0')
135
136 # stdeb is required to produce Debian files with the "sdist_dsc" command.
137 if "sdist_dsc" in sys.argv:
138     setup_requires.append('stdeb >= 0.3')
139
140 class ShowSupportLib(Command):
141     user_options = []
142     def initialize_options(self):
143         pass
144     def finalize_options(self):
145         pass
146     def run(self):
147         # TODO: --quiet suppresses the 'running show_supportlib' message.
148         # Find a way to do this all the time.
149         print supportlib # TODO windowsy
150
151 class ShowPythonPath(Command):
152     user_options = []
153     def initialize_options(self):
154         pass
155     def finalize_options(self):
156         pass
157     def run(self):
158         # TODO: --quiet suppresses the 'running show_supportlib' message.
159         # Find a way to do this all the time.
160         print "PYTHONPATH=%s" % os.environ.get("PYTHONPATH", '')
161
162 class RunWithPythonPath(Command):
163     description = "Run a subcommand with PYTHONPATH set appropriately"
164
165     user_options = [ ("python", "p",
166                       "Treat command string as arguments to a python executable"),
167                      ("command=", "c", "Command to be run"),
168                      ("directory=", "d", "Directory to run the command in"),
169                      ]
170     boolean_options = ["python"]
171
172     def initialize_options(self):
173         self.command = None
174         self.python = False
175         self.directory = None
176     def finalize_options(self):
177         pass
178     def run(self):
179         oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
180         if oldpp == [""]:
181             # grr silly split() behavior
182             oldpp = []
183         os.environ['PYTHONPATH'] = os.pathsep.join(oldpp + [supportlib,])
184
185         # We must require the command to be safe to split on
186         # whitespace, and have --python and --directory to make it
187         # easier to achieve this.
188
189         command = []
190         if self.python:
191             command.append(sys.executable)
192         if self.command:
193             command.extend(self.command.split())
194         if not command:
195             raise RuntimeError("The --command argument is mandatory")
196         if self.directory:
197             os.chdir(self.directory)
198         if self.verbose:
199             print "command =", " ".join(command)
200         rc = subprocess.call(command)
201         sys.exit(rc)
202
203 class TestMacDiskImage(Command):
204     user_options = []
205     def initialize_options(self):
206         pass
207     def finalize_options(self):
208         pass
209     def run(self):
210         import sys
211         sys.path.append('misc')
212         import test_mac_diskimage
213         return test_mac_diskimage.test_mac_diskimage('Allmydata', version=self.distribution.metadata.version)
214
215 class CheckAutoDeps(Command):
216     user_options = []
217     def initialize_options(self):
218         pass
219     def finalize_options(self):
220         pass
221     def run(self):
222         import _auto_deps
223         _auto_deps.require_auto_deps()
224
225
226 class MakeExecutable(Command):
227     user_options = []
228     def initialize_options(self):
229         pass
230     def finalize_options(self):
231         pass
232     def run(self):
233         bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
234
235         # Create the 'tahoe-script.py' file under the 'bin' directory. The
236         # 'tahoe-script.py' file is exactly the same as the
237         # 'tahoe-script.template' script except that the shebang line is
238         # rewritten to use our sys.executable for the interpreter. On
239         # Windows, create a tahoe.exe will execute it. On non-Windows, make a
240         # symlink to it from 'tahoe'. The tahoe.exe will be copied from the
241         # setuptools egg's cli.exe and this will work from a zip-safe and
242         # non-zip-safe setuptools egg.
243         f = open(bin_tahoe_template, "rU")
244         script_lines = f.readlines()
245         f.close()
246         script_lines[0] = "#!%s\n" % sys.executable
247         tahoe_script = os.path.join("bin", "tahoe-script.py")
248         f = open(tahoe_script, "w")
249         for line in script_lines:
250             f.write(line)
251         f.close()
252         if sys.platform == "win32":
253             setuptools_egg = require("setuptools")[0].location
254             if os.path.isfile(setuptools_egg):
255                 z = zipfile.ZipFile(setuptools_egg, 'r')
256                 for filename in z.namelist():
257                     if 'cli.exe' in filename:
258                         cli_exe = z.read(filename)
259             else:
260                 cli_exe = os.path.join(setuptools_egg, 'setuptools', 'cli.exe')
261             tahoe_exe = os.path.join("bin", "tahoe.exe")
262             if os.path.isfile(setuptools_egg):
263                 f = open(tahoe_exe, 'wb')
264                 f.write(cli_exe)
265                 f.close()
266             else:
267                 shutil.copy(cli_exe, tahoe_exe)
268         else:
269             try:
270                 os.remove(os.path.join('bin', 'tahoe'))
271             except:
272                 # okay, probably it was already gone
273                 pass
274             os.symlink('tahoe-script.py', os.path.join('bin', 'tahoe'))
275
276         # chmod +x bin/tahoe-script.py
277         old_mode = stat.S_IMODE(os.stat(tahoe_script)[stat.ST_MODE])
278         new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
279                                stat.S_IXGRP | stat.S_IRGRP |
280                                stat.S_IXOTH | stat.S_IROTH )
281         os.chmod(tahoe_script, new_mode)
282
283 class MySdist(sdist.sdist):
284     """ A hook in the sdist command so that we can determine whether this the
285     tarball should be 'SUMO' or not, i.e. whether or not to include the
286     external dependency tarballs. Note that we always include
287     misc/dependencies/* in the tarball; --sumo controls whether tahoe-deps/*
288     is included as well.
289     """
290
291     user_options = sdist.sdist.user_options + \
292         [('sumo', 's',
293           "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
294          ]
295     boolean_options = ['sumo']
296
297     def initialize_options(self):
298         sdist.sdist.initialize_options(self)
299         self.sumo = False
300
301     def make_distribution(self):
302         # add our extra files to the list just before building the
303         # tarball/zipfile. We override make_distribution() instead of run()
304         # because setuptools.command.sdist.run() does not lend itself to
305         # easy/robust subclassing (the code we need to add goes right smack
306         # in the middle of a 12-line method). If this were the distutils
307         # version, we'd override get_file_list().
308
309         if self.sumo:
310             # If '--sumo' was specified, include tahoe-deps/* in the sdist.
311             # We assume that the user has fetched the tahoe-deps.tar.gz
312             # tarball and unpacked it already.
313             self.filelist.extend([os.path.join("tahoe-deps", fn)
314                                   for fn in os.listdir("tahoe-deps")])
315             # In addition, we want the tarball/zipfile to have -SUMO in the
316             # name, and the unpacked directory to have -SUMO too. The easiest
317             # way to do this is to patch self.distribution and override the
318             # get_fullname() method. (an alternative is to modify
319             # self.distribution.metadata.version, but that also affects the
320             # contents of PKG-INFO).
321             fullname = self.distribution.get_fullname()
322             def get_fullname():
323                 return fullname + "-SUMO"
324             self.distribution.get_fullname = get_fullname
325
326         return sdist.sdist.make_distribution(self)
327
328 # Tahoe's dependencies are managed by the find_links= entry in setup.cfg and
329 # the _auto_deps.install_requires list, which is used in the call to setup()
330 # below.
331 from _auto_deps import install_requires
332
333 APPNAME='allmydata-tahoe'
334 APPNAMEFILE = os.path.join('src', 'allmydata', '_appname.py')
335 APPNAMEFILESTR = "__appname__ = '%s'" % (APPNAME,)
336 try:
337     curappnamefilestr = open(APPNAMEFILE, 'rU').read()
338 except EnvironmentError:
339     # No file, or unreadable or something, okay then let's try to write one.
340     open(APPNAMEFILE, "w").write(APPNAMEFILESTR)
341 else:
342     if curappnamefilestr.strip() != APPNAMEFILESTR:
343         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)
344         sys.exit(-1)
345
346 setup_args = {}
347 if version:
348     setup_args["version"] = version
349
350 setup(name=APPNAME,
351       description='secure, decentralized, fault-tolerant filesystem',
352       long_description=open('README.txt', 'rU').read(),
353       author='the Tahoe-LAFS project',
354       author_email='tahoe-dev@allmydata.org',
355       url='http://tahoe-lafs.org/',
356       license='GNU GPL', # see README.txt -- there is an alternative licence
357       cmdclass={"show_supportlib": ShowSupportLib,
358                 "show_pythonpath": ShowPythonPath,
359                 "run_with_pythonpath": RunWithPythonPath,
360                 "check_auto_deps": CheckAutoDeps,
361                 "test_mac_diskimage": TestMacDiskImage,
362                 "make_executable": MakeExecutable,
363                 "sdist": MySdist,
364                 },
365       package_dir = {'':'src'},
366       packages=find_packages("src"),
367       classifiers=trove_classifiers,
368       test_suite="allmydata.test",
369       install_requires=install_requires,
370       include_package_data=True,
371       setup_requires=setup_requires,
372       entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
373       zip_safe=False, # We prefer unzipped for easier access.
374       **setup_args
375       )