2 # -*- coding: utf-8 -*-
3 import sys; assert sys.version_info < (3,), ur"Tahoe-LAFS does not run under Python 3. Please use a version of Python between 2.6 and 2.7.x inclusive."
5 # Tahoe-LAFS -- secure, distributed storage grid
7 # Copyright © 2006-2012 The Tahoe-LAFS Software Foundation
9 # This file is part of Tahoe-LAFS.
11 # See the docs/about.rst file for licensing information.
13 import glob, os, stat, subprocess, 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 import setuptools; setuptools.bootstrap_install_from = egg
77 from setuptools import setup
78 from setuptools.command import sdist
79 from setuptools import Command
82 "Development Status :: 5 - Production/Stable",
83 "Environment :: Console",
84 "Environment :: Web Environment",
85 "License :: OSI Approved :: GNU General Public License (GPL)",
86 "License :: DFSG approved",
87 "License :: Other/Proprietary License",
88 "Intended Audience :: Developers",
89 "Intended Audience :: End Users/Desktop",
90 "Intended Audience :: System Administrators",
91 "Operating System :: Microsoft",
92 "Operating System :: Microsoft :: Windows",
93 "Operating System :: Microsoft :: Windows :: Windows NT/2000",
94 "Operating System :: Unix",
95 "Operating System :: POSIX :: Linux",
96 "Operating System :: POSIX",
97 "Operating System :: MacOS :: MacOS X",
98 "Operating System :: OS Independent",
99 "Natural Language :: English",
100 "Programming Language :: C",
101 "Programming Language :: Python",
102 "Programming Language :: Python :: 2",
103 "Programming Language :: Python :: 2.4",
104 "Programming Language :: Python :: 2.5",
105 "Programming Language :: Python :: 2.6",
106 "Programming Language :: Python :: 2.7",
107 "Topic :: Utilities",
108 "Topic :: System :: Systems Administration",
109 "Topic :: System :: Filesystems",
110 "Topic :: System :: Distributed Computing",
111 "Topic :: Software Development :: Libraries",
112 "Topic :: Communications :: Usenet News",
113 "Topic :: System :: Archiving :: Backup",
114 "Topic :: System :: Archiving :: Mirroring",
115 "Topic :: System :: Archiving",
121 # Nevow imports itself when building, which causes Twisted and zope.interface
122 # to be imported. We need to make sure that the versions of Twisted and
123 # zope.interface used at build time satisfy Nevow's requirements. If not
124 # then there are two problems:
125 # - prior to Nevow v0.9.33, Nevow didn't declare its dependency on Twisted
126 # in a way that enabled setuptools to satisfy that requirement at
128 # - some versions of zope.interface, e.g. v3.6.4, are incompatible with
129 # Nevow, and we need to avoid those both at build and run-time.
131 # This only matters when compatible versions of Twisted and zope.interface
132 # are not already installed. Retire this hack when
133 # https://bugs.launchpad.net/nevow/+bug/812537 has been fixed.
134 setup_requires += [req for req in install_requires if req.startswith('Twisted') or req.startswith('zope.interface')]
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 # The required version is 0.3.3, because that is the latest version that only
139 # depends on a version of pycoverage for which binary packages are available.
140 if "--reporter=bwverbose-coverage" in sys.argv:
141 setup_requires.append('trialcoverage >= 0.3.3')
143 # stdeb is required to produce Debian files with the "sdist_dsc" command.
144 if "sdist_dsc" in sys.argv:
145 setup_requires.append('stdeb >= 0.3')
147 # We no longer have any requirements specific to tests.
151 class Trial(Command):
152 description = "run trial (use 'bin%stahoe debug trial' for the full set of trial options)" % (os.sep,)
153 # This is just a subset of the most useful options, for compatibility.
154 user_options = [ ("no-rterrors", None, "Don't print out tracebacks as they occur."),
155 ("rterrors", "e", "Print out tracebacks as they occur (default, so ignored)."),
156 ("until-failure", "u", "Repeat a test (specified by -s) until it fails."),
157 ("reporter=", None, "The reporter to use for this test run."),
158 ("suite=", "s", "Specify the test suite."),
159 ("quiet", None, "Don't display version numbers and paths of Tahoe dependencies."),
162 def initialize_options(self):
163 self.rterrors = False
164 self.no_rterrors = False
165 self.until_failure = False
167 self.suite = "allmydata"
170 def finalize_options(self):
174 args = [sys.executable, os.path.join('bin', 'tahoe')]
176 args.append('--version-and-path')
177 args += ['debug', 'trial']
178 if self.rterrors and self.no_rterrors:
179 raise AssertionError("--rterrors and --no-rterrors conflict.")
180 if not self.no_rterrors:
181 args.append('--rterrors')
182 if self.until_failure:
183 args.append('--until-failure')
185 args.append('--reporter=' + self.reporter)
187 args.append(self.suite)
188 rc = subprocess.call(args)
192 class MakeExecutable(Command):
193 description = "make the 'bin%stahoe' scripts" % (os.sep,)
196 def initialize_options(self):
198 def finalize_options(self):
201 bin_tahoe_template = os.path.join("bin", "tahoe-script.template")
203 # tahoe.pyscript is really only necessary for Windows, but we also
204 # create it on Unix for consistency.
205 script_names = ["tahoe.pyscript", "tahoe"]
207 # Create the tahoe script file under the 'bin' directory. This
208 # file is exactly the same as the 'tahoe-script.template' script
209 # except that the shebang line is rewritten to use our sys.executable
210 # for the interpreter.
211 f = open(bin_tahoe_template, "rU")
212 script_lines = f.readlines()
214 script_lines[0] = '#!%s\n' % (sys.executable,)
215 for script_name in script_names:
216 tahoe_script = os.path.join("bin", script_name)
218 os.remove(tahoe_script)
220 if os.path.exists(tahoe_script):
222 f = open(tahoe_script, "wb")
223 for line in script_lines:
228 unix_script = os.path.join("bin", "tahoe")
229 old_mode = stat.S_IMODE(os.stat(unix_script)[stat.ST_MODE])
230 new_mode = old_mode | (stat.S_IXUSR | stat.S_IRUSR |
231 stat.S_IXGRP | stat.S_IRGRP |
232 stat.S_IXOTH | stat.S_IROTH )
233 os.chmod(unix_script, new_mode)
235 old_tahoe_exe = os.path.join("bin", "tahoe.exe")
237 os.remove(old_tahoe_exe)
239 if os.path.exists(old_tahoe_exe):
243 GIT_VERSION_BODY = '''
244 # This _version.py is generated from git metadata by the tahoe setup.py.
246 __pkgname__ = %(pkgname)r
247 real_version = %(version)r
248 full_version = %(full)r
250 verstr = %(normalized)r
254 def run_command(args, cwd=None, verbose=False):
256 # remember shell=False, so use git.cmd on windows, not just git
257 p = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=cwd)
258 except EnvironmentError as e: # if this gives a SyntaxError, note that Tahoe-LAFS requires Python 2.6+
260 print("unable to run %s" % args[0])
263 stdout = p.communicate()[0].strip()
264 if p.returncode != 0:
266 print("unable to run %s (error)" % args[0])
271 def versions_from_git(tag_prefix, verbose=False):
272 # this runs 'git' from the directory that contains this file. That either
273 # means someone ran a setup.py command (and this code is in
274 # versioneer.py, thus the containing directory is the root of the source
275 # tree), or someone ran a project-specific entry point (and this code is
276 # in _version.py, thus the containing directory is somewhere deeper in
277 # the source tree). This only gets called if the git-archive 'subst'
278 # variables were *not* expanded, and _version.py hasn't already been
279 # rewritten with a short version string, meaning we're inside a checked
282 # versions_from_git (as copied from python-versioneer) returns strings
283 # like "1.9.0-25-gb73aba9-dirty", which means we're in a tree with
284 # uncommited changes (-dirty), the latest checkin is revision b73aba9,
285 # the most recent tag was 1.9.0, and b73aba9 has 25 commits that weren't
286 # in 1.9.0 . The narrow-minded NormalizedVersion parser that takes our
287 # output (meant to enable sorting of version strings) refuses most of
288 # that. Tahoe uses a function named suggest_normalized_version() that can
289 # handle "1.9.0.post25", so dumb down our output to match.
292 source_dir = os.path.dirname(os.path.abspath(__file__))
294 # some py2exe/bbfreeze/non-CPython implementations don't do __file__
295 return {} # not always correct
297 if sys.platform == "win32":
299 stdout = run_command([GIT, "describe", "--tags", "--dirty", "--always"],
303 if not stdout.startswith(tag_prefix):
305 print("tag '%s' doesn't start with prefix '%s'" % (stdout, tag_prefix))
307 version = stdout[len(tag_prefix):]
308 pieces = version.split("-")
310 normalized_version = pieces[0]
312 normalized_version = "%s.post%s" % (pieces[0], pieces[1])
314 stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=source_dir)
317 full = stdout.strip()
318 if version.endswith("-dirty"):
320 normalized_version += ".dev0"
322 # Thanks to Jistanidiot at <http://stackoverflow.com/questions/6245570/get-current-branch-name>.
323 stdout = run_command([GIT, "rev-parse", "--abbrev-ref", "HEAD"], cwd=source_dir)
324 branch = (stdout or "unknown").strip()
326 return {"version": version, "normalized": normalized_version, "full": full, "branch": branch}
328 # setup.cfg has an [aliases] section which runs "update_version" before many
329 # commands (like "build" and "sdist") that need to know our package version
330 # ahead of time. If you add different commands (or if we forgot some), you
331 # may need to add it to setup.cfg and configure it to run update_version
332 # before your command.
334 class UpdateVersion(Command):
335 description = "update _version.py from revision-control metadata"
338 def initialize_options(self):
340 def finalize_options(self):
343 if os.path.isdir(os.path.join(basedir, ".git")):
344 verstr = self.try_from_git()
346 print("no version-control data found, leaving _version.py alone")
349 self.distribution.metadata.version = verstr
351 def try_from_git(self):
352 versions = versions_from_git("allmydata-tahoe-", verbose=True)
354 fn = 'src/allmydata/_version.py'
356 f.write(GIT_VERSION_BODY %
357 { "pkgname": self.distribution.get_name(),
358 "version": versions["version"],
359 "normalized": versions["normalized"],
360 "full": versions["full"],
361 "branch": versions["branch"],
364 print("git-version: wrote '%s' into '%s'" % (versions["version"], fn))
365 return versions.get("normalized", None)
368 class MySdist(sdist.sdist):
369 """ A hook in the sdist command so that we can determine whether this the
370 tarball should be 'SUMO' or not, i.e. whether or not to include the
371 external dependency tarballs. Note that we always include
372 misc/dependencies/* in the tarball; --sumo controls whether tahoe-deps/*
376 user_options = sdist.sdist.user_options + \
378 "create a 'sumo' sdist which includes the contents of tahoe-deps/*"),
380 boolean_options = ['sumo']
382 def initialize_options(self):
383 sdist.sdist.initialize_options(self)
386 def make_distribution(self):
387 # add our extra files to the list just before building the
388 # tarball/zipfile. We override make_distribution() instead of run()
389 # because setuptools.command.sdist.run() does not lend itself to
390 # easy/robust subclassing (the code we need to add goes right smack
391 # in the middle of a 12-line method). If this were the distutils
392 # version, we'd override get_file_list().
395 # If '--sumo' was specified, include tahoe-deps/* in the sdist.
396 # We assume that the user has fetched the tahoe-deps.tar.gz
397 # tarball and unpacked it already.
398 self.filelist.extend([os.path.join("tahoe-deps", fn)
399 for fn in os.listdir("tahoe-deps")])
400 # In addition, we want the tarball/zipfile to have -SUMO in the
401 # name, and the unpacked directory to have -SUMO too. The easiest
402 # way to do this is to patch self.distribution and override the
403 # get_fullname() method. (an alternative is to modify
404 # self.distribution.metadata.version, but that also affects the
405 # contents of PKG-INFO).
406 fullname = self.distribution.get_fullname()
408 return fullname + "-SUMO"
409 self.distribution.get_fullname = get_fullname
412 old_mask = os.umask(int("022", 8))
413 return sdist.sdist.make_distribution(self)
420 setup_args["version"] = version
423 description='secure, decentralized, fault-tolerant filesystem',
424 long_description=open('README.txt', 'rU').read(),
425 author='the Tahoe-LAFS project',
426 author_email='tahoe-dev@tahoe-lafs.org',
427 url='https://tahoe-lafs.org/',
428 license='GNU GPL', # see README.txt -- there is an alternative licence
429 cmdclass={"trial": Trial,
430 "make_executable": MakeExecutable,
431 "update_version": UpdateVersion,
434 package_dir = {'':'src'},
435 packages=['allmydata',
436 'allmydata.frontends',
437 'allmydata.immutable',
438 'allmydata.immutable.downloader',
439 'allmydata.introducer',
443 'allmydata.storage.backends',
444 'allmydata.storage.backends.cloud',
445 'allmydata.storage.backends.cloud.s3',
446 'allmydata.storage.backends.cloud.openstack',
447 'allmydata.storage.backends.cloud.googlestorage',
448 'allmydata.storage.backends.cloud.msazure',
449 'allmydata.storage.backends.disk',
450 'allmydata.storage.backends.null',
454 'allmydata.web.static',
455 'allmydata.web.static.css',
458 classifiers=trove_classifiers,
459 test_suite="allmydata.test",
460 install_requires=install_requires,
461 tests_require=tests_require,
462 package_data={"allmydata.web": ["*.xhtml"],
463 "allmydata.web.static": ["*.js", "*.png", "*.css"],
464 "allmydata.web.static.css": ["*.css"],
465 "allmydata.web.static.img": ["*.png"],
467 setup_requires=setup_requires,
468 entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
469 zip_safe=False, # We prefer unzipped for easier access.