2 # -*- coding: utf-8 -*-
3 u"Tahoe-LAFS does not run under Python 3. Please use a version of Python between 2.4.4 and 2.7.x inclusive."
5 # Tahoe-LAFS -- secure, distributed storage grid
7 # Copyright © 2008-2011 Allmydata, Inc.
9 # This file is part of Tahoe-LAFS.
11 # See the docs/about.rst file for licensing information.
13 import glob, os, stat, subprocess, sys, re
15 ##### sys.path management
17 def pylibdir(prefixdir):
18 pyver = "python%d.%d" % (sys.version_info[:2])
19 if sys.platform == "win32":
20 return os.path.join(prefixdir, "Lib", "site-packages")
22 return os.path.join(prefixdir, "lib", pyver, "site-packages")
24 basedir = os.path.dirname(os.path.abspath(__file__))
25 supportlib = pylibdir(os.path.join(basedir, "support"))
27 # locate our version number
29 def read_version_py(infname):
31 verstrline = open(infname, "rt").read()
32 except EnvironmentError:
35 VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
36 mo = re.search(VSRE, verstrline, re.M)
40 version = read_version_py("src/allmydata/_version.py")
42 APPNAME='allmydata-tahoe'
43 APPNAMEFILE = os.path.join('src', 'allmydata', '_appname.py')
44 APPNAMEFILESTR = "__appname__ = '%s'" % (APPNAME,)
46 curappnamefilestr = open(APPNAMEFILE, 'rU').read()
47 except EnvironmentError:
48 # No file, or unreadable or something, okay then let's try to write one.
49 open(APPNAMEFILE, "w").write(APPNAMEFILESTR)
51 if curappnamefilestr.strip() != APPNAMEFILESTR:
52 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)
55 # setuptools/zetuptoolz looks in __main__.__requires__ for a list of
56 # requirements. When running "python setup.py test", __main__ is
57 # setup.py, so we put the list here so that the requirements will be
58 # available for tests:
60 # Tahoe's dependencies are managed by the find_links= entry in setup.cfg and
61 # the _auto_deps.install_requires list, which is used in the call to setup()
64 execfile('src/allmydata/_auto_deps.py', adglobals)
65 install_requires = adglobals['install_requires']
67 if len(sys.argv) > 1 and sys.argv[1] == '--fakedependency':
69 install_requires += ["fakedependency >= 1.0.0"]
71 __requires__ = install_requires[:]
73 egg = os.path.realpath(glob.glob('setuptools-*.egg')[0])
74 sys.path.insert(0, egg)
75 egg = os.path.realpath(glob.glob('darcsver-*.egg')[0])
76 sys.path.insert(0, egg)
77 import setuptools; setuptools.bootstrap_install_from = egg
79 from setuptools import setup
80 from setuptools.command import sdist
81 from setuptools import Command
84 "Development Status :: 5 - Production/Stable",
85 "Environment :: Console",
86 "Environment :: Web Environment",
87 "License :: OSI Approved :: GNU General Public License (GPL)",
88 "License :: DFSG approved",
89 "License :: Other/Proprietary License",
90 "Intended Audience :: Developers",
91 "Intended Audience :: End Users/Desktop",
92 "Intended Audience :: System Administrators",
93 "Operating System :: Microsoft",
94 "Operating System :: Microsoft :: Windows",
95 "Operating System :: Microsoft :: Windows :: Windows NT/2000",
96 "Operating System :: Unix",
97 "Operating System :: POSIX :: Linux",
98 "Operating System :: POSIX",
99 "Operating System :: MacOS :: MacOS X",
100 "Operating System :: OS Independent",
101 "Natural Language :: English",
102 "Programming Language :: C",
103 "Programming Language :: Python",
104 "Programming Language :: Python :: 2",
105 "Programming Language :: Python :: 2.4",
106 "Programming Language :: Python :: 2.5",
107 "Programming Language :: Python :: 2.6",
108 "Programming Language :: Python :: 2.7",
109 "Topic :: Utilities",
110 "Topic :: System :: Systems Administration",
111 "Topic :: System :: Filesystems",
112 "Topic :: System :: Distributed Computing",
113 "Topic :: Software Development :: Libraries",
114 "Topic :: Communications :: Usenet News",
115 "Topic :: System :: Archiving :: Backup",
116 "Topic :: System :: Archiving :: Mirroring",
117 "Topic :: System :: Archiving",
123 # The darcsver command from the darcsver plugin is needed to initialize the
124 # distribution's .version attribute correctly. (It does this either by
125 # examining darcs history, or if that fails by reading the
126 # src/allmydata/_version.py file). darcsver will also write a new version
127 # stamp in src/allmydata/_version.py, with a version number derived from
128 # darcs history. Note that the setup.cfg file has an "[aliases]" section
129 # which enumerates commands that you might run and specifies that it will run
130 # darcsver before each one. If you add different commands (or if I forgot
131 # some that are already in use), you may need to add it to setup.cfg and
132 # configure it to run darcsver before your command, if you want the version
133 # number to be correct when that command runs.
134 # http://pypi.python.org/pypi/darcsver
135 setup_requires.append('darcsver >= 1.7.2')
137 # Nevow imports itself when building, which causes Twisted and zope.interface
138 # to be imported. We need to make sure that the versions of Twisted and
139 # zope.interface used at build time satisfy Nevow's requirements. If not
140 # then there are two problems:
141 # - prior to Nevow v0.9.33, Nevow didn't declare its dependency on Twisted
142 # in a way that enabled setuptools to satisfy that requirement at
144 # - some versions of zope.interface, e.g. v3.6.4, are incompatible with
145 # Nevow, and we need to avoid those both at build and run-time.
147 # This only matters when compatible versions of Twisted and zope.interface
148 # are not already installed. Retire this hack when
149 # https://bugs.launchpad.net/nevow/+bug/812537 has been fixed.
150 setup_requires += [req for req in install_requires if req.startswith('Twisted') or req.startswith('zope.interface')]
152 # trialcoverage is required if you want the "trial" unit test runner to have a
153 # "--reporter=bwverbose-coverage" option which produces code-coverage results.
154 # The required version is 0.3.3, because that is the latest version that only
155 # depends on a version of pycoverage for which binary packages are available.
156 if "--reporter=bwverbose-coverage" in sys.argv:
157 setup_requires.append('trialcoverage >= 0.3.3')
159 # stdeb is required to produce Debian files with the "sdist_dsc" command.
160 if "sdist_dsc" in sys.argv:
161 setup_requires.append('stdeb >= 0.3')
163 # We no longer have any requirements specific to tests.
167 class Trial(Command):
168 description = "run trial (use 'bin%stahoe debug trial' for the full set of trial options)" % (os.sep,)
169 # This is just a subset of the most useful options, for compatibility.
170 user_options = [ ("rterrors", "e", "Print out tracebacks as soon as they occur."),
171 ("reporter=", None, "The reporter to use for this test run."),
172 ("suite=", "s", "Specify the test suite."),
173 ("quiet", None, "Don't display version numbers and paths of Tahoe dependencies."),
176 def initialize_options(self):
177 self.rterrors = False
179 self.suite = "allmydata"
182 def finalize_options(self):
186 args = [sys.executable, os.path.join('bin', 'tahoe')]
188 args.append('--version-and-path')
189 args += ['debug', 'trial']
191 args.append('--rterrors')
193 args.append('--reporter=' + self.reporter)
195 args.append(self.suite)
196 rc = subprocess.call(args)
200 class MakeExecutable(Command):
201 description = "make the 'bin%stahoe' scripts" % (os.sep,)
204 def initialize_options(self):
206 def finalize_options(self):
209 bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
211 # tahoe.pyscript is really only necessary for Windows, but we also
212 # create it on Unix for consistency.
213 script_names = ["tahoe.pyscript", "tahoe"]
215 # Create the tahoe script file under the 'bin' directory. This
216 # file is exactly the same as the 'tahoe-script.template' script
217 # except that the shebang line is rewritten to use our sys.executable
218 # for the interpreter.
219 f = open(bin_tahoe_template, "rU")
220 script_lines = f.readlines()
222 script_lines[0] = '#!%s\n' % (sys.executable,)
223 for script_name in script_names:
224 tahoe_script = os.path.join("bin", script_name)
226 os.remove(tahoe_script)
228 if os.path.exists(tahoe_script):
230 f = open(tahoe_script, "wb")
231 for line in script_lines:
236 unix_script = os.path.join("bin", "tahoe")
237 old_mode = stat.S_IMODE(os.stat(unix_script)[stat.ST_MODE])
238 new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
239 stat.S_IXGRP | stat.S_IRGRP |
240 stat.S_IXOTH | stat.S_IROTH )
241 os.chmod(unix_script, new_mode)
243 old_tahoe_exe = os.path.join("bin", "tahoe.exe")
245 os.remove(old_tahoe_exe)
247 if os.path.exists(old_tahoe_exe):
251 DARCS_VERSION_BODY = '''
252 # This _version.py is generated from darcs metadata by the tahoe setup.py
253 # and the "darcsver" package.
255 __pkgname__ = "%(pkgname)s"
256 verstr = "%(pkgversion)s"
260 GIT_VERSION_BODY = '''
261 # This _version.py is generated from git metadata by the tahoe setup.py.
263 __pkgname__ = "%(pkgname)s"
264 real_version = "%(version)s"
265 full_version = "%(full)s"
266 verstr = "%(normalized)s"
270 def run_command(args, cwd=None, verbose=False):
272 # remember shell=False, so use git.cmd on windows, not just git
273 p = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=cwd)
274 except EnvironmentError, e:
276 print "unable to run %s" % args[0]
279 stdout = p.communicate()[0].strip()
280 if p.returncode != 0:
282 print "unable to run %s (error)" % args[0]
287 def versions_from_git(tag_prefix, verbose=False):
288 # this runs 'git' from the directory that contains this file. That either
289 # means someone ran a setup.py command (and this code is in
290 # versioneer.py, thus the containing directory is the root of the source
291 # tree), or someone ran a project-specific entry point (and this code is
292 # in _version.py, thus the containing directory is somewhere deeper in
293 # the source tree). This only gets called if the git-archive 'subst'
294 # variables were *not* expanded, and _version.py hasn't already been
295 # rewritten with a short version string, meaning we're inside a checked
298 # versions_from_git (as copied from python-versioneer) returns strings
299 # like "1.9.0-25-gb73aba9-dirty", which means we're in a tree with
300 # uncommited changes (-dirty), the latest checkin is revision b73aba9,
301 # the most recent tag was 1.9.0, and b73aba9 has 25 commits that weren't
302 # in 1.9.0 . The narrow-minded NormalizedVersion parser that takes our
303 # output (meant to enable sorting of version strings) refuses most of
304 # that. Tahoe uses a function named suggest_normalized_version() that can
305 # handle "1.9.0.post25", so dumb down our output to match.
308 source_dir = os.path.dirname(os.path.abspath(__file__))
310 # some py2exe/bbfreeze/non-CPython implementations don't do __file__
311 return {} # not always correct
313 if sys.platform == "win32":
315 stdout = run_command([GIT, "describe", "--tags", "--dirty", "--always"],
319 if not stdout.startswith(tag_prefix):
321 print "tag '%s' doesn't start with prefix '%s'" % (stdout, tag_prefix)
323 version = stdout[len(tag_prefix):]
324 pieces = version.split("-")
326 normalized_version = pieces[0]
328 normalized_version = "%s.post%s" % (pieces[0], pieces[1])
329 stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=source_dir)
332 full = stdout.strip()
333 if version.endswith("-dirty"):
335 normalized_version += ".dev0"
336 return {"version": version, "normalized": normalized_version, "full": full}
339 class UpdateVersion(Command):
340 description = "update _version.py from revision-control metadata"
343 def initialize_options(self):
345 def finalize_options(self):
348 target = self.distribution.versionfiles[0]
349 if os.path.isdir(os.path.join(basedir, "_darcs")):
350 verstr = self.try_from_darcs(target)
351 elif os.path.isdir(os.path.join(basedir, ".git")):
352 verstr = self.try_from_git(target)
354 print "no version-control data found, leaving _version.py alone"
357 self.distribution.metadata.version = verstr
359 def try_from_darcs(self, target):
360 from darcsver.darcsvermodule import update
361 (rc, verstr) = update(pkgname=self.distribution.get_name(),
362 verfilename=self.distribution.versionfiles,
363 revision_number=True,
364 version_body=DARCS_VERSION_BODY)
368 def try_from_git(self, target):
369 versions = versions_from_git("allmydata-tahoe-", verbose=True)
371 for fn in self.distribution.versionfiles:
373 f.write(GIT_VERSION_BODY %
374 { "pkgname": self.distribution.get_name(),
375 "version": versions["version"],
376 "normalized": versions["normalized"],
377 "full": versions["full"] })
379 print "git-version: wrote '%s' into '%s'" % (versions["version"], fn)
380 return versions.get("normalized", None)
383 class MySdist(sdist.sdist):
384 """ A hook in the sdist command so that we can determine whether this the
385 tarball should be 'SUMO' or not, i.e. whether or not to include the
386 external dependency tarballs. Note that we always include
387 misc/dependencies/* in the tarball; --sumo controls whether tahoe-deps/*
391 user_options = sdist.sdist.user_options + \
393 "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
395 boolean_options = ['sumo']
397 def initialize_options(self):
398 sdist.sdist.initialize_options(self)
401 def make_distribution(self):
402 # add our extra files to the list just before building the
403 # tarball/zipfile. We override make_distribution() instead of run()
404 # because setuptools.command.sdist.run() does not lend itself to
405 # easy/robust subclassing (the code we need to add goes right smack
406 # in the middle of a 12-line method). If this were the distutils
407 # version, we'd override get_file_list().
410 # If '--sumo' was specified, include tahoe-deps/* in the sdist.
411 # We assume that the user has fetched the tahoe-deps.tar.gz
412 # tarball and unpacked it already.
413 self.filelist.extend([os.path.join("tahoe-deps", fn)
414 for fn in os.listdir("tahoe-deps")])
415 # In addition, we want the tarball/zipfile to have -SUMO in the
416 # name, and the unpacked directory to have -SUMO too. The easiest
417 # way to do this is to patch self.distribution and override the
418 # get_fullname() method. (an alternative is to modify
419 # self.distribution.metadata.version, but that also affects the
420 # contents of PKG-INFO).
421 fullname = self.distribution.get_fullname()
423 return fullname + "-SUMO"
424 self.distribution.get_fullname = get_fullname
427 old_mask = os.umask(int("022", 8))
428 return sdist.sdist.make_distribution(self)
435 setup_args["version"] = version
438 description='secure, decentralized, fault-tolerant filesystem',
439 long_description=open('README.txt', 'rU').read(),
440 author='the Tahoe-LAFS project',
441 author_email='tahoe-dev@tahoe-lafs.org',
442 url='https://tahoe-lafs.org/',
443 license='GNU GPL', # see README.txt -- there is an alternative licence
444 cmdclass={"trial": Trial,
445 "make_executable": MakeExecutable,
446 "update_version": UpdateVersion,
449 package_dir = {'':'src'},
450 packages=['allmydata',
451 'allmydata.frontends',
452 'allmydata.immutable',
453 'allmydata.immutable.downloader',
454 'allmydata.introducer',
461 'allmydata.web.static',
464 classifiers=trove_classifiers,
465 test_suite="allmydata.test",
466 install_requires=install_requires,
467 tests_require=tests_require,
468 package_data={"allmydata.web": ["*.xhtml"],
469 "allmydata.web.static": ["*.js", "*.png", "*.css"],
471 setup_requires=setup_requires,
472 entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
473 zip_safe=False, # We prefer unzipped for easier access.
474 versionfiles=['src/allmydata/_version.py',],