source: trunk/setup.py

Last change on this file was 76d6678, checked in by Jean-Paul Calderone <exarkun@…>, at 2020-02-13T15:21:45Z

Remove some top-level packaging related to magic-folders

  • Property mode set to 100644
File size: 15.1 KB
Line 
1#! /usr/bin/env python
2# -*- coding: utf-8 -*-
3import sys
4
5# Tahoe-LAFS -- secure, distributed storage grid
6#
7# Copyright © 2006-2012 The Tahoe-LAFS Software Foundation
8#
9# This file is part of Tahoe-LAFS.
10#
11# See the docs/about.rst file for licensing information.
12
13import os, subprocess, re
14
15basedir = os.path.dirname(os.path.abspath(__file__))
16
17# locate our version number
18
19def read_version_py(infname):
20    try:
21        verstrline = open(infname, "rt").read()
22    except EnvironmentError:
23        return None
24    else:
25        VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
26        mo = re.search(VSRE, verstrline, re.M)
27        if mo:
28            return mo.group(1)
29
30VERSION_PY_FILENAME = 'src/allmydata/_version.py'
31version = read_version_py(VERSION_PY_FILENAME)
32
33install_requires = [
34    # we don't need much out of setuptools but the version checking stuff
35    # needs pkg_resources and PEP 440 version specifiers.
36    "setuptools >= 28.8.0",
37
38    "zfec >= 1.1.0",
39
40    # zope.interface >= 3.6.0 is required for Twisted >= 12.1.0.
41    # zope.interface 3.6.3 and 3.6.4 are incompatible with Nevow (#1435).
42    "zope.interface >= 3.6.0, != 3.6.3, != 3.6.4",
43
44    # * foolscap < 0.5.1 had a performance bug which spent O(N**2) CPU for
45    #   transferring large mutable files of size N.
46    # * foolscap < 0.6 is incompatible with Twisted 10.2.0.
47    # * foolscap 0.6.1 quiets a DeprecationWarning.
48    # * foolscap < 0.6.3 is incompatible with Twisted 11.1.0 and newer.
49    # * foolscap 0.8.0 generates 2048-bit RSA-with-SHA-256 signatures,
50    #   rather than 1024-bit RSA-with-MD5. This also allows us to work
51    #   with a FIPS build of OpenSSL.
52    # * foolscap >= 0.12.3 provides tcp/tor/i2p connection handlers we need,
53    #   and allocate_tcp_port
54    # * foolscap >= 0.12.5 has ConnectionInfo and ReconnectionInfo
55    # * foolscap >= 0.12.6 has an i2p.sam_endpoint() that takes kwargs
56    # * foolscap 0.13.2 drops i2p support completely
57    "foolscap == 0.13.1",
58
59    # * cryptography 2.6 introduced some ed25519 APIs we rely on.  Note that
60    #   Twisted[conch] also depends on cryptography and Twisted[tls]
61    #   transitively depends on cryptography.  So it's anyone's guess what
62    #   version of cryptography will *really* be installed.
63    "cryptography >= 2.6",
64
65    # * We need Twisted 10.1.0 for the FTP frontend in order for
66    #   Twisted's FTP server to support asynchronous close.
67    # * The SFTP frontend depends on Twisted 11.0.0 to fix the SSH server
68    #   rekeying bug <https://twistedmatrix.com/trac/ticket/4395>
69    # * The FTP frontend depends on Twisted >= 11.1.0 for
70    #   filepath.Permissions
71    # * Nevow 0.11.1 depends on Twisted >= 13.0.0.
72    # * The SFTP frontend and manhole depend on the conch extra. However, we
73    #   can't explicitly declare that without an undesirable dependency on gmpy,
74    #   as explained in ticket #2740.
75    # * Due to a setuptools bug, we need to declare a dependency on the tls
76    #   extra even though we only depend on it via foolscap.
77    # * Twisted >= 15.1.0 is the first version that provided the [tls] extra.
78    # * Twisted-16.1.0 fixes https://twistedmatrix.com/trac/ticket/8223,
79    #   which otherwise causes test_system to fail (DirtyReactorError, due to
80    #   leftover timers)
81    # * Twisted-16.4.0 introduces `python -m twisted.trial` which is needed
82    #   for coverage testing
83    # * Twisted 16.6.0 drops the undesirable gmpy dependency from the conch
84    #   extra, letting us use that extra instead of trying to duplicate its
85    #   dependencies here.  Twisted[conch] >18.7 introduces a dependency on
86    #   bcrypt.  It is nice to avoid that if the user ends up with an older
87    #   version of Twisted.  That's hard to express except by using the extra.
88    #
89    # * Twisted 18.4.0 adds `client` and `host` attributes to `Request` in the
90    # * initializer, needed by logic in our custom `Request` subclass.
91    #
92    #   In a perfect world, Twisted[conch] would be a dependency of an "sftp"
93    #   extra.  However, pip fails to resolve the dependencies all
94    #   dependencies when asked for Twisted[tls] *and* Twisted[conch].
95    #   Specifically, "Twisted[conch]" (as the later requirement) is ignored.
96    #   If there were an Tahoe-LAFS sftp extra that dependended on
97    #   Twisted[conch] and install_requires only included Twisted[tls] then
98    #   `pip install tahoe-lafs[sftp]` would not install requirements
99    #   specified by Twisted[conch].  Since this would be the *whole point* of
100    #   an sftp extra in Tahoe-LAFS, there is no point in having one.
101    "Twisted[tls,conch] >= 18.4.0",
102
103    # We need Nevow >= 0.11.1 which can be installed using pip.
104    "Nevow >= 0.11.1",
105
106    "PyYAML >= 3.11",
107
108    "six >= 1.10.0",
109
110    # for 'tahoe invite' and 'tahoe join'
111    "magic-wormhole >= 0.10.2",
112
113    # Eliot is contemplating dropping Python 2 support.  Stick to a version we
114    # know works on Python 2.7.
115    "eliot ~= 1.7",
116
117    # A great way to define types of values.
118    "attrs >= 18.2.0",
119
120    # WebSocket library for twisted and asyncio
121    "autobahn >= 19.5.2",
122]
123
124setup_requires = [
125    'setuptools >= 28.8.0',  # for PEP-440 style versions
126]
127
128tor_requires = [
129    # This is exactly what `foolscap[tor]` means but pip resolves the pair of
130    # dependencies "foolscap[i2p] foolscap[tor]" to "foolscap[i2p]" so we lose
131    # this if we don't declare it ourselves!
132    "txtorcon >= 0.17.0",
133]
134
135i2p_requires = [
136    # See the comment in tor_requires.
137    "txi2p >= 0.3.2",
138]
139
140if len(sys.argv) > 1 and sys.argv[1] == '--fakedependency':
141    del sys.argv[1]
142    install_requires += ["fakedependency >= 1.0.0"]
143
144from setuptools import find_packages, setup
145from setuptools import Command
146from setuptools.command import install
147
148
149trove_classifiers=[
150    "Development Status :: 5 - Production/Stable",
151    "Environment :: Console",
152    "Environment :: Web Environment",
153    "License :: OSI Approved :: GNU General Public License (GPL)",
154    "License :: DFSG approved",
155    "License :: Other/Proprietary License",
156    "Intended Audience :: Developers",
157    "Intended Audience :: End Users/Desktop",
158    "Intended Audience :: System Administrators",
159    "Operating System :: Microsoft",
160    "Operating System :: Microsoft :: Windows",
161    "Operating System :: Unix",
162    "Operating System :: POSIX :: Linux",
163    "Operating System :: POSIX",
164    "Operating System :: MacOS :: MacOS X",
165    "Operating System :: OS Independent",
166    "Natural Language :: English",
167    "Programming Language :: C",
168    "Programming Language :: Python",
169    "Programming Language :: Python :: 2",
170    "Programming Language :: Python :: 2.7",
171    "Topic :: Utilities",
172    "Topic :: System :: Systems Administration",
173    "Topic :: System :: Filesystems",
174    "Topic :: System :: Distributed Computing",
175    "Topic :: Software Development :: Libraries",
176    "Topic :: System :: Archiving :: Backup",
177    "Topic :: System :: Archiving :: Mirroring",
178    "Topic :: System :: Archiving",
179    ]
180
181
182GIT_VERSION_BODY = '''
183# This _version.py is generated from git metadata by the tahoe setup.py.
184
185__pkgname__ = "%(pkgname)s"
186real_version = "%(version)s"
187full_version = "%(full)s"
188branch = "%(branch)s"
189verstr = "%(normalized)s"
190__version__ = verstr
191'''
192
193def run_command(args, cwd=None):
194    use_shell = sys.platform == "win32"
195    try:
196        p = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=cwd, shell=use_shell)
197    except EnvironmentError as e:  # if this gives a SyntaxError, note that Tahoe-LAFS requires Python 2.7+
198        print("Warning: unable to run %r." % (" ".join(args),))
199        print(e)
200        return None
201    stdout = p.communicate()[0].strip()
202    if p.returncode != 0:
203        print("Warning: %r returned error code %r." % (" ".join(args), p.returncode))
204        return None
205    return stdout
206
207
208def versions_from_git(tag_prefix):
209    # This runs 'git' from the directory that contains this file. That either
210    # means someone ran a setup.py command (and this code is in
211    # versioneer.py, thus the containing directory is the root of the source
212    # tree), or someone ran a project-specific entry point (and this code is
213    # in _version.py, thus the containing directory is somewhere deeper in
214    # the source tree). This only gets called if the git-archive 'subst'
215    # variables were *not* expanded, and _version.py hasn't already been
216    # rewritten with a short version string, meaning we're inside a checked
217    # out source tree.
218
219    # versions_from_git (as copied from python-versioneer) returns strings
220    # like "1.9.0-25-gb73aba9-dirty", which means we're in a tree with
221    # uncommited changes (-dirty), the latest checkin is revision b73aba9,
222    # the most recent tag was 1.9.0, and b73aba9 has 25 commits that weren't
223    # in 1.9.0 . The narrow-minded NormalizedVersion parser that takes our
224    # output (meant to enable sorting of version strings) refuses most of
225    # that. Tahoe uses a function named suggest_normalized_version() that can
226    # handle "1.9.0.post25", so dumb down our output to match.
227
228    try:
229        source_dir = os.path.dirname(os.path.abspath(__file__))
230    except NameError as e:
231        # some py2exe/bbfreeze/non-CPython implementations don't do __file__
232        print("Warning: unable to find version because we could not obtain the source directory.")
233        print(e)
234        return {}
235    stdout = run_command(["git", "describe", "--tags", "--dirty", "--always"],
236                         cwd=source_dir)
237    if stdout is None:
238        # run_command already complained.
239        return {}
240    stdout = stdout.decode("ascii")
241    if not stdout.startswith(tag_prefix):
242        print("Warning: tag %r doesn't start with prefix %r." % (stdout, tag_prefix))
243        return {}
244    version = stdout[len(tag_prefix):]
245    pieces = version.split("-")
246    if len(pieces) == 1:
247        normalized_version = pieces[0]
248    else:
249        normalized_version = "%s.post%s" % (pieces[0], pieces[1])
250
251    stdout = run_command(["git", "rev-parse", "HEAD"], cwd=source_dir)
252    if stdout is None:
253        # run_command already complained.
254        return {}
255    full = stdout.decode("ascii").strip()
256    if version.endswith("-dirty"):
257        full += "-dirty"
258        normalized_version += ".dev0"
259
260    # Thanks to Jistanidiot at <http://stackoverflow.com/questions/6245570/get-current-branch-name>.
261    stdout = run_command(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=source_dir)
262    branch = (stdout or b"unknown").decode("ascii").strip()
263
264    # this returns native strings (bytes on py2, unicode on py3)
265    return {"version": version, "normalized": normalized_version,
266            "full": full, "branch": branch}
267
268# setup.cfg has an [aliases] section which runs "update_version" before many
269# commands (like "build" and "sdist") that need to know our package version
270# ahead of time. If you add different commands (or if we forgot some), you
271# may need to add it to setup.cfg and configure it to run update_version
272# before your command.
273
274class UpdateVersion(Command):
275    description = "update _version.py from revision-control metadata"
276    user_options = install.install.user_options
277
278    def initialize_options(self):
279        pass
280    def finalize_options(self):
281        pass
282    def run(self):
283        global version
284        verstr = version
285        if os.path.isdir(os.path.join(basedir, ".git")):
286            verstr = self.try_from_git()
287
288        if verstr:
289            self.distribution.metadata.version = verstr
290        else:
291            print("""\
292********************************************************************
293Warning: no version information found. This may cause tests to fail.
294********************************************************************
295""")
296
297    def try_from_git(self):
298        # If we change the release tag names, we must change this too
299        versions = versions_from_git("tahoe-lafs-")
300
301        # setup.py might be run by either py2 or py3 (when run by tox, which
302        # uses py3 on modern debian/ubuntu distros). We want this generated
303        # file to contain native strings on both (str=bytes in py2,
304        # str=unicode in py3)
305        if versions:
306            body = GIT_VERSION_BODY % {
307                "pkgname": self.distribution.get_name(),
308                "version": versions["version"],
309                "normalized": versions["normalized"],
310                "full": versions["full"],
311                "branch": versions["branch"],
312                }
313            f = open(VERSION_PY_FILENAME, "wb")
314            f.write(body.encode("ascii"))
315            f.close()
316            print("Wrote normalized version %r into '%s'" % (versions["normalized"], VERSION_PY_FILENAME))
317
318        return versions.get("normalized", None)
319
320class PleaseUseTox(Command):
321    user_options = []
322    def initialize_options(self):
323        pass
324    def finalize_options(self):
325        pass
326
327    def run(self):
328        print("ERROR: Please use 'tox' to run the test suite.")
329        sys.exit(1)
330
331setup_args = {}
332if version:
333    setup_args["version"] = version
334
335setup(name="tahoe-lafs", # also set in __init__.py
336      description='secure, decentralized, fault-tolerant file store',
337      long_description=open('README.rst', 'rU').read(),
338      author='the Tahoe-LAFS project',
339      author_email='tahoe-dev@tahoe-lafs.org',
340      url='https://tahoe-lafs.org/',
341      license='GNU GPL', # see README.rst -- there is an alternative licence
342      cmdclass={"update_version": UpdateVersion,
343                "test": PleaseUseTox,
344                },
345      package_dir = {'':'src'},
346      packages=find_packages('src') + ['allmydata.test.plugins'],
347      classifiers=trove_classifiers,
348      python_requires="<3.0",
349      install_requires=install_requires,
350      extras_require={
351          # Duplicate the Twisted pywin32 dependency here.  See
352          # https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2392 for some
353          # discussion.
354          ':sys_platform=="win32"': ["pywin32 != 226"],
355          "test": [
356              # Pin a specific pyflakes so we don't have different folks
357              # disagreeing on what is or is not a lint issue.  We can bump
358              # this version from time to time, but we will do it
359              # intentionally.
360              "pyflakes == 2.1.0",
361              # coverage 5.0 breaks the integration tests in some opaque way.
362              # This probably needs to be addressed in a more permanent way
363              # eventually...
364              "coverage ~= 4.5",
365              "mock",
366              "tox",
367              "pytest",
368              "pytest-twisted",
369              "hypothesis >= 3.6.1",
370              "treq",
371              "towncrier",
372              "testtools",
373              "fixtures",
374              "beautifulsoup4",
375              "html5lib",
376          ] + tor_requires + i2p_requires,
377          "tor": tor_requires,
378          "i2p": i2p_requires,
379      },
380      package_data={"allmydata.web": ["*.xhtml",
381                                      "static/*.js", "static/*.png", "static/*.css",
382                                      "static/img/*.png",
383                                      "static/css/*.css",
384                                      ],
385                    "allmydata": ["ported-modules.txt"],
386                    },
387      include_package_data=True,
388      setup_requires=setup_requires,
389      entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
390      **setup_args
391      )
Note: See TracBrowser for help on using the repository browser.