2 # -*- coding: utf-8 -*-
4 # Tahoe-LAFS -- secure, distributed storage grid
6 # Copyright © 2008-2010 Allmydata, Inc.
8 # This file is part of Tahoe-LAFS.
10 # See the docs/about.html file for licensing information.
12 import os, shutil, stat, subprocess, sys, zipfile, re
14 ##### sys.path management
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")
21 return os.path.join(prefixdir, "lib", pyver, "site-packages")
23 basedir = os.path.dirname(os.path.abspath(__file__))
24 supportlib = pylibdir(os.path.join(basedir, "support"))
26 # locate our version number
28 def read_version_py(infname):
30 verstrline = open(infname, "rt").read()
31 except EnvironmentError:
34 VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
35 mo = re.search(VSRE, verstrline, re.M)
39 version = read_version_py("src/allmydata/_version.py")
42 from ez_setup import use_setuptools
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.
52 use_setuptools(download_delay=0, min_version="0.6c12dev")
54 from setuptools import find_packages, setup
55 from setuptools.command import sdist
56 from setuptools import Command
57 from pkg_resources import require
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"))
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",
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",
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')
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'])
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')
136 # trialcoverage is required if you want the "trial" unit test runner to have a
137 # "--reporter=bwverbose-coverage" option which produces code-coverage results.
138 if "--reporter=bwverbose-coverage" in sys.argv:
139 setup_requires.append('trialcoverage >= 0.3.10')
141 # stdeb is required to produce Debian files with the "sdist_dsc" command.
142 if "sdist_dsc" in sys.argv:
143 setup_requires.append('stdeb >= 0.3')
145 class ShowSupportLib(Command):
147 def initialize_options(self):
149 def finalize_options(self):
152 # TODO: --quiet suppresses the 'running show_supportlib' message.
153 # Find a way to do this all the time.
154 print supportlib # TODO windowsy
156 class ShowPythonPath(Command):
158 def initialize_options(self):
160 def finalize_options(self):
163 # TODO: --quiet suppresses the 'running show_supportlib' message.
164 # Find a way to do this all the time.
165 print "PYTHONPATH=%s" % os.environ.get("PYTHONPATH", '')
167 class RunWithPythonPath(Command):
168 description = "Run a subcommand with PYTHONPATH set appropriately"
170 user_options = [ ("python", "p",
171 "Treat command string as arguments to a python executable"),
172 ("command=", "c", "Command to be run"),
173 ("directory=", "d", "Directory to run the command in"),
175 boolean_options = ["python"]
177 def initialize_options(self):
180 self.directory = None
181 def finalize_options(self):
184 oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
186 # grr silly split() behavior
188 os.environ['PYTHONPATH'] = os.pathsep.join(oldpp + [supportlib,])
190 # We must require the command to be safe to split on
191 # whitespace, and have --python and --directory to make it
192 # easier to achieve this.
196 command.append(sys.executable)
198 command.extend(self.command.split())
200 raise RuntimeError("The --command argument is mandatory")
202 os.chdir(self.directory)
204 print "command =", " ".join(command)
205 rc = subprocess.call(command)
208 class TestMacDiskImage(Command):
210 def initialize_options(self):
212 def finalize_options(self):
216 sys.path.append('misc')
217 import test_mac_diskimage
218 return test_mac_diskimage.test_mac_diskimage('Allmydata', version=self.distribution.metadata.version)
220 class CheckAutoDeps(Command):
222 def initialize_options(self):
224 def finalize_options(self):
228 _auto_deps.require_auto_deps()
231 class MakeExecutable(Command):
233 def initialize_options(self):
235 def finalize_options(self):
238 bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
240 # Create the 'tahoe-script.py' file under the 'bin' directory. The
241 # 'tahoe-script.py' file is exactly the same as the
242 # 'tahoe-script.template' script except that the shebang line is
243 # rewritten to use our sys.executable for the interpreter. On
244 # Windows, create a tahoe.exe will execute it. On non-Windows, make a
245 # symlink to it from 'tahoe'. The tahoe.exe will be copied from the
246 # setuptools egg's cli.exe and this will work from a zip-safe and
247 # non-zip-safe setuptools egg.
248 f = open(bin_tahoe_template, "rU")
249 script_lines = f.readlines()
251 script_lines[0] = "#!%s\n" % sys.executable
252 tahoe_script = os.path.join("bin", "tahoe-script.py")
253 f = open(tahoe_script, "w")
254 for line in script_lines:
257 if sys.platform == "win32":
258 setuptools_egg = require("setuptools")[0].location
259 if os.path.isfile(setuptools_egg):
260 z = zipfile.ZipFile(setuptools_egg, 'r')
261 for filename in z.namelist():
262 if 'cli.exe' in filename:
263 cli_exe = z.read(filename)
265 cli_exe = os.path.join(setuptools_egg, 'setuptools', 'cli.exe')
266 tahoe_exe = os.path.join("bin", "tahoe.exe")
267 if os.path.isfile(setuptools_egg):
268 f = open(tahoe_exe, 'wb')
272 shutil.copy(cli_exe, tahoe_exe)
275 os.remove(os.path.join('bin', 'tahoe'))
277 # okay, probably it was already gone
279 os.symlink('tahoe-script.py', os.path.join('bin', 'tahoe'))
281 # chmod +x bin/tahoe-script.py
282 old_mode = stat.S_IMODE(os.stat(tahoe_script)[stat.ST_MODE])
283 new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
284 stat.S_IXGRP | stat.S_IRGRP |
285 stat.S_IXOTH | stat.S_IROTH )
286 os.chmod(tahoe_script, new_mode)
288 class MySdist(sdist.sdist):
289 """ A hook in the sdist command so that we can determine whether this the
290 tarball should be 'SUMO' or not, i.e. whether or not to include the
291 external dependency tarballs. Note that we always include
292 misc/dependencies/* in the tarball; --sumo controls whether tahoe-deps/*
296 user_options = sdist.sdist.user_options + \
298 "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
300 boolean_options = ['sumo']
302 def initialize_options(self):
303 sdist.sdist.initialize_options(self)
306 def make_distribution(self):
307 # add our extra files to the list just before building the
308 # tarball/zipfile. We override make_distribution() instead of run()
309 # because setuptools.command.sdist.run() does not lend itself to
310 # easy/robust subclassing (the code we need to add goes right smack
311 # in the middle of a 12-line method). If this were the distutils
312 # version, we'd override get_file_list().
315 # If '--sumo' was specified, include tahoe-deps/* in the sdist.
316 # We assume that the user has fetched the tahoe-deps.tar.gz
317 # tarball and unpacked it already.
318 self.filelist.extend([os.path.join("tahoe-deps", fn)
319 for fn in os.listdir("tahoe-deps")])
320 # In addition, we want the tarball/zipfile to have -SUMO in the
321 # name, and the unpacked directory to have -SUMO too. The easiest
322 # way to do this is to patch self.distribution and override the
323 # get_fullname() method. (an alternative is to modify
324 # self.distribution.metadata.version, but that also affects the
325 # contents of PKG-INFO).
326 fullname = self.distribution.get_fullname()
328 return fullname + "-SUMO"
329 self.distribution.get_fullname = get_fullname
331 return sdist.sdist.make_distribution(self)
333 # Tahoe's dependencies are managed by the find_links= entry in setup.cfg and
334 # the _auto_deps.install_requires list, which is used in the call to setup()
336 from _auto_deps import install_requires
338 APPNAME='allmydata-tahoe'
339 APPNAMEFILE = os.path.join('src', 'allmydata', '_appname.py')
340 APPNAMEFILESTR = "__appname__ = '%s'" % (APPNAME,)
342 curappnamefilestr = open(APPNAMEFILE, 'rU').read()
343 except EnvironmentError:
344 # No file, or unreadable or something, okay then let's try to write one.
345 open(APPNAMEFILE, "w").write(APPNAMEFILESTR)
347 if curappnamefilestr.strip() != APPNAMEFILESTR:
348 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)
353 setup_args["version"] = version
356 description='secure, decentralized, fault-tolerant filesystem',
357 long_description=open('README.txt', 'rU').read(),
358 author='the Tahoe-LAFS project',
359 author_email='tahoe-dev@allmydata.org',
360 url='http://tahoe-lafs.org/',
361 license='GNU GPL', # see README.txt -- there is an alternative licence
362 cmdclass={"show_supportlib": ShowSupportLib,
363 "show_pythonpath": ShowPythonPath,
364 "run_with_pythonpath": RunWithPythonPath,
365 "check_auto_deps": CheckAutoDeps,
366 "test_mac_diskimage": TestMacDiskImage,
367 "make_executable": MakeExecutable,
370 package_dir = {'':'src'},
371 packages=find_packages("src"),
372 classifiers=trove_classifiers,
373 test_suite="allmydata.test",
374 install_requires=install_requires,
375 include_package_data=True,
376 setup_requires=setup_requires,
377 entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
378 zip_safe=False, # We prefer unzipped for easier access.