]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - setup.py
Change 'setup.py trial' and 'setup.py test' to use 'bin/tahoe debug trial'. refs...
[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 glob, 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 APPNAME='allmydata-tahoe'
42 APPNAMEFILE = os.path.join('src', 'allmydata', '_appname.py')
43 APPNAMEFILESTR = "__appname__ = '%s'" % (APPNAME,)
44 try:
45     curappnamefilestr = open(APPNAMEFILE, 'rU').read()
46 except EnvironmentError:
47     # No file, or unreadable or something, okay then let's try to write one.
48     open(APPNAMEFILE, "w").write(APPNAMEFILESTR)
49 else:
50     if curappnamefilestr.strip() != APPNAMEFILESTR:
51         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)
52         sys.exit(-1)
53
54 # setuptools/zetuptoolz looks in __main__.__requires__ for a list of
55 # requirements. When running "python setup.py test", __main__ is
56 # setup.py, so we put the list here so that the requirements will be
57 # available for tests:
58
59 # Tahoe's dependencies are managed by the find_links= entry in setup.cfg and
60 # the _auto_deps.install_requires list, which is used in the call to setup()
61 # below.
62 adglobals = {}
63 execfile('src/allmydata/_auto_deps.py', adglobals)
64 install_requires = adglobals['install_requires']
65
66 if len(sys.argv) > 1 and sys.argv[1] == '--fakedependency':
67     del sys.argv[1]
68     install_requires += ["fakedependency >= 1.0.0"]
69
70 __requires__ = install_requires[:]
71
72 egg = os.path.realpath(glob.glob('setuptools-*.egg')[0])
73 sys.path.insert(0, egg)
74 egg = os.path.realpath(glob.glob('darcsver-*.egg')[0])
75 sys.path.insert(0, egg)
76 egg = os.path.realpath(glob.glob('setuptools_darcs-*.egg')[0])
77 sys.path.insert(0, egg)
78 import setuptools; setuptools.bootstrap_install_from = egg
79
80 from setuptools import find_packages, setup
81 from setuptools.command import sdist
82 from setuptools import Command
83
84 trove_classifiers=[
85     "Development Status :: 5 - Production/Stable",
86     "Environment :: Console",
87     "Environment :: Web Environment",
88     "License :: OSI Approved :: GNU General Public License (GPL)",
89     "License :: DFSG approved",
90     "License :: Other/Proprietary License",
91     "Intended Audience :: Developers",
92     "Intended Audience :: End Users/Desktop",
93     "Intended Audience :: System Administrators",
94     "Operating System :: Microsoft",
95     "Operating System :: Microsoft :: Windows",
96     "Operating System :: Microsoft :: Windows :: Windows NT/2000",
97     "Operating System :: Unix",
98     "Operating System :: POSIX :: Linux",
99     "Operating System :: POSIX",
100     "Operating System :: MacOS :: MacOS X",
101     "Operating System :: OS Independent",
102     "Natural Language :: English",
103     "Programming Language :: C",
104     "Programming Language :: Python",
105     "Programming Language :: Python :: 2",
106     "Programming Language :: Python :: 2.4",
107     "Programming Language :: Python :: 2.5",
108     "Programming Language :: Python :: 2.6",
109     "Programming Language :: Python :: 2.7",
110     "Topic :: Utilities",
111     "Topic :: System :: Systems Administration",
112     "Topic :: System :: Filesystems",
113     "Topic :: System :: Distributed Computing",
114     "Topic :: Software Development :: Libraries",
115     "Topic :: Communications :: Usenet News",
116     "Topic :: System :: Archiving :: Backup",
117     "Topic :: System :: Archiving :: Mirroring",
118     "Topic :: System :: Archiving",
119     ]
120
121
122 setup_requires = []
123
124 # The darcsver command from the darcsver plugin is needed to initialize the
125 # distribution's .version attribute correctly. (It does this either by
126 # examining darcs history, or if that fails by reading the
127 # src/allmydata/_version.py file). darcsver will also write a new version
128 # stamp in src/allmydata/_version.py, with a version number derived from
129 # darcs history. Note that the setup.cfg file has an "[aliases]" section
130 # which enumerates commands that you might run and specifies that it will run
131 # darcsver before each one. If you add different commands (or if I forgot
132 # some that are already in use), you may need to add it to setup.cfg and
133 # configure it to run darcsver before your command, if you want the version
134 # number to be correct when that command runs.
135 # http://pypi.python.org/pypi/darcsver
136 setup_requires.append('darcsver >= 1.7.1')
137
138 # Nevow requires Twisted to setup, but prior to Nevow v0.9.33, didn't
139 # declare that requirement in a way that enables setuptools to satisfy
140 # the requirement before Nevow's setup.py tries to "import twisted".
141 # This only matters when Twisted is not already installed.
142 # See http://divmod.org/trac/ticket/2629
143 # Retire this hack if/when we require Nevow >= 0.9.33.
144 setup_requires.append('Twisted >= 2.4.0')
145
146 # setuptools_darcs is required to produce complete distributions (such
147 # as with "sdist" or "bdist_egg"), unless there is a
148 # src/allmydata_tahoe.egg-info/SOURCE.txt file, which if present
149 # contains a complete list of files that should be included.
150 # http://pypi.python.org/pypi/setuptools_darcs
151 setup_requires.append('setuptools_darcs >= 1.1.0')
152
153 # trialcoverage is required if you want the "trial" unit test runner to have a
154 # "--reporter=bwverbose-coverage" option which produces code-coverage results.
155 # The required version is 0.3.3, because that is the latest version that only
156 # depends on a version of pycoverage for which binary packages are available.
157 if "--reporter=bwverbose-coverage" in sys.argv:
158     setup_requires.append('trialcoverage >= 0.3.3')
159
160 # stdeb is required to produce Debian files with the "sdist_dsc" command.
161 if "sdist_dsc" in sys.argv:
162     setup_requires.append('stdeb >= 0.3')
163
164 # We no longer have any requirements specific to tests.
165 tests_require=[]
166
167
168 class ShowSupportLib(Command):
169     user_options = []
170     def initialize_options(self):
171         pass
172     def finalize_options(self):
173         pass
174     def run(self):
175         # TODO: --quiet suppresses the 'running show_supportlib' message.
176         # Find a way to do this all the time.
177         print supportlib # TODO windowsy
178
179 class ShowPythonPath(Command):
180     user_options = []
181     def initialize_options(self):
182         pass
183     def finalize_options(self):
184         pass
185     def run(self):
186         # TODO: --quiet suppresses the 'running show_supportlib' message.
187         # Find a way to do this all the time.
188         print "PYTHONPATH=%s" % os.environ.get("PYTHONPATH", '')
189
190 class RunWithPythonPath(Command):
191     description = "Run a subcommand with PYTHONPATH set appropriately"
192
193     user_options = [ ("python", "p",
194                       "Treat command string as arguments to a python executable"),
195                      ("command=", "c", "Command to be run"),
196                      ("directory=", "d", "Directory to run the command in"),
197                      ]
198     boolean_options = ["python"]
199
200     def initialize_options(self):
201         self.command = None
202         self.python = False
203         self.directory = None
204     def finalize_options(self):
205         pass
206     def run(self):
207         oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
208         if oldpp == [""]:
209             # grr silly split() behavior
210             oldpp = []
211         os.environ['PYTHONPATH'] = os.pathsep.join(oldpp + [supportlib,])
212
213         # We must require the command to be safe to split on
214         # whitespace, and have --python and --directory to make it
215         # easier to achieve this.
216
217         command = []
218         if self.python:
219             command.append(sys.executable)
220         if self.command:
221             command.extend(self.command.split())
222         if not command:
223             raise RuntimeError("The --command argument is mandatory")
224         if self.directory:
225             os.chdir(self.directory)
226         if self.verbose:
227             print "command =", " ".join(command)
228         rc = subprocess.call(command)
229         sys.exit(rc)
230
231 class TestMacDiskImage(Command):
232     user_options = []
233     def initialize_options(self):
234         pass
235     def finalize_options(self):
236         pass
237     def run(self):
238         import sys
239         sys.path.append(os.path.join('misc', 'build_helpers'))
240         import test_mac_diskimage
241         return test_mac_diskimage.test_mac_diskimage('Allmydata', version=self.distribution.metadata.version)
242
243
244 class Trial(Command):
245     description = "run trial (use 'bin%stahoe debug trial' for the full set of trial options)" % (os.sep,)
246     # This is just a subset of the most useful options, for compatibility.
247     user_options = [ ("rterrors", "e", "Print out tracebacks as soon as they occur."),
248                      ("reporter=", None, "The reporter to use for this test run."),
249                      ("suite=", "s", "Specify the test suite."),
250                      ("version-and-path", None, "Display version numbers and paths of Tahoe dependencies."),
251                    ]
252
253     def initialize_options(self):
254         self.rterrors = False
255         self.reporter = None
256         self.suite = "allmydata"
257         self.version_and_path = False
258
259     def finalize_options(self):
260         pass
261
262     def run(self):
263         args = [sys.executable, os.path.join('bin', 'tahoe')]
264         if self.version_and_path:
265             args.append('--version-and-path')
266         args += ['debug', 'trial']
267         if self.rterrors:
268             args.append('--rterrors')
269         if self.reporter:
270             args.append('--reporter=' + self.reporter)
271         if self.suite:
272             args.append(self.suite)
273         rc = subprocess.call(args)
274         sys.exit(rc)
275
276
277 class CheckAutoDeps(Command):
278     user_options = []
279     def initialize_options(self):
280         pass
281     def finalize_options(self):
282         pass
283     def run(self):
284         adglobals = {}
285         execfile('src/allmydata/_auto_deps.py', adglobals)
286         adglobals['require_auto_deps']()
287
288
289 class MakeExecutable(Command):
290     user_options = []
291     def initialize_options(self):
292         pass
293     def finalize_options(self):
294         pass
295     def run(self):
296         bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
297
298         if sys.platform == 'win32':
299             # 'tahoe' script is needed for cygwin
300             script_names = ["tahoe.pyscript", "tahoe"]
301         else:
302             script_names = ["tahoe"]
303
304         # Create the tahoe script file under the 'bin' directory. This
305         # file is exactly the same as the 'tahoe-script.template' script
306         # except that the shebang line is rewritten to use our sys.executable
307         # for the interpreter.
308         f = open(bin_tahoe_template, "rU")
309         script_lines = f.readlines()
310         f.close()
311         script_lines[0] = '#!%s\n' % (sys.executable,)
312         for script_name in script_names:
313             tahoe_script = os.path.join("bin", script_name)
314             try:
315                 os.remove(tahoe_script)
316             except Exception:
317                 if os.path.exists(tahoe_script):
318                    raise
319             f = open(tahoe_script, "wb")
320             for line in script_lines:
321                 f.write(line)
322             f.close()
323
324             # chmod +x
325             old_mode = stat.S_IMODE(os.stat(tahoe_script)[stat.ST_MODE])
326             new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
327                                    stat.S_IXGRP | stat.S_IRGRP |
328                                    stat.S_IXOTH | stat.S_IROTH )
329             os.chmod(tahoe_script, new_mode)
330
331         old_tahoe_exe = os.path.join("bin", "tahoe.exe")
332         try:
333             os.remove(old_tahoe_exe)
334         except Exception:
335             if os.path.exists(old_tahoe_exe):
336                 raise
337
338
339 class MySdist(sdist.sdist):
340     """ A hook in the sdist command so that we can determine whether this the
341     tarball should be 'SUMO' or not, i.e. whether or not to include the
342     external dependency tarballs. Note that we always include
343     misc/dependencies/* in the tarball; --sumo controls whether tahoe-deps/*
344     is included as well.
345     """
346
347     user_options = sdist.sdist.user_options + \
348         [('sumo', 's',
349           "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
350          ]
351     boolean_options = ['sumo']
352
353     def initialize_options(self):
354         sdist.sdist.initialize_options(self)
355         self.sumo = False
356
357     def make_distribution(self):
358         # add our extra files to the list just before building the
359         # tarball/zipfile. We override make_distribution() instead of run()
360         # because setuptools.command.sdist.run() does not lend itself to
361         # easy/robust subclassing (the code we need to add goes right smack
362         # in the middle of a 12-line method). If this were the distutils
363         # version, we'd override get_file_list().
364
365         if self.sumo:
366             # If '--sumo' was specified, include tahoe-deps/* in the sdist.
367             # We assume that the user has fetched the tahoe-deps.tar.gz
368             # tarball and unpacked it already.
369             self.filelist.extend([os.path.join("tahoe-deps", fn)
370                                   for fn in os.listdir("tahoe-deps")])
371             # In addition, we want the tarball/zipfile to have -SUMO in the
372             # name, and the unpacked directory to have -SUMO too. The easiest
373             # way to do this is to patch self.distribution and override the
374             # get_fullname() method. (an alternative is to modify
375             # self.distribution.metadata.version, but that also affects the
376             # contents of PKG-INFO).
377             fullname = self.distribution.get_fullname()
378             def get_fullname():
379                 return fullname + "-SUMO"
380             self.distribution.get_fullname = get_fullname
381
382         return sdist.sdist.make_distribution(self)
383
384 setup_args = {}
385 if version:
386     setup_args["version"] = version
387
388 setup(name=APPNAME,
389       description='secure, decentralized, fault-tolerant filesystem',
390       long_description=open('README.txt', 'rU').read(),
391       author='the Tahoe-LAFS project',
392       author_email='tahoe-dev@tahoe-lafs.org',
393       url='http://tahoe-lafs.org/',
394       license='GNU GPL', # see README.txt -- there is an alternative licence
395       cmdclass={"show_supportlib": ShowSupportLib,
396                 "show_pythonpath": ShowPythonPath,
397                 "run_with_pythonpath": RunWithPythonPath,
398                 "check_auto_deps": CheckAutoDeps,
399                 "test_mac_diskimage": TestMacDiskImage,
400                 "trial": Trial,
401                 "make_executable": MakeExecutable,
402                 "sdist": MySdist,
403                 },
404       package_dir = {'':'src'},
405       packages=find_packages("src"),
406       classifiers=trove_classifiers,
407       test_suite="allmydata.test",
408       install_requires=install_requires,
409       tests_require=tests_require,
410       include_package_data=True,
411       setup_requires=setup_requires,
412       entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
413       zip_safe=False, # We prefer unzipped for easier access.
414       versionfiles=['src/allmydata/_version.py',],
415       **setup_args
416       )