source: trunk/setup.py

Last change on this file was b124454, checked in by Jean-Paul Calderone <exarkun@…>, at 2020-11-18T20:42:10Z

Bump to a Twisted that has Site.getContentFile support

  • Property mode set to 100644
File size: 16.3 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.0",
42
43    # * foolscap < 0.5.1 had a performance bug which spent O(N**2) CPU for
44    #   transferring large mutable files of size N.
45    # * foolscap < 0.6 is incompatible with Twisted 10.2.0.
46    # * foolscap 0.6.1 quiets a DeprecationWarning.
47    # * foolscap < 0.6.3 is incompatible with Twisted 11.1.0 and newer.
48    # * foolscap 0.8.0 generates 2048-bit RSA-with-SHA-256 signatures,
49    #   rather than 1024-bit RSA-with-MD5. This also allows us to work
50    #   with a FIPS build of OpenSSL.
51    # * foolscap >= 0.12.3 provides tcp/tor/i2p connection handlers we need,
52    #   and allocate_tcp_port
53    # * foolscap >= 0.12.5 has ConnectionInfo and ReconnectionInfo
54    # * foolscap >= 0.12.6 has an i2p.sam_endpoint() that takes kwargs
55    # * foolscap 0.13.2 drops i2p support completely
56    # * foolscap >= 20.4 is necessary for Python 3
57    "foolscap == 0.13.1 ; python_version < '3.0'",
58    "foolscap >= 20.4.0 ; python_version > '3.0'",
59
60    # * cryptography 2.6 introduced some ed25519 APIs we rely on.  Note that
61    #   Twisted[conch] also depends on cryptography and Twisted[tls]
62    #   transitively depends on cryptography.  So it's anyone's guess what
63    #   version of cryptography will *really* be installed.
64    "cryptography >= 2.6",
65
66    # * We need Twisted 10.1.0 for the FTP frontend in order for
67    #   Twisted's FTP server to support asynchronous close.
68    # * The SFTP frontend depends on Twisted 11.0.0 to fix the SSH server
69    #   rekeying bug <https://twistedmatrix.com/trac/ticket/4395>
70    # * The FTP frontend depends on Twisted >= 11.1.0 for
71    #   filepath.Permissions
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 19.10 introduces Site.getContentFile which we use to get
102    #   temporary upload files placed into a per-node temporary directory.
103    "Twisted[tls,conch] >= 19.10.0",
104
105    "PyYAML >= 3.11",
106
107    "six >= 1.10.0",
108
109    # for 'tahoe invite' and 'tahoe join'
110    "magic-wormhole >= 0.10.2",
111
112    # Eliot is contemplating dropping Python 2 support.  Stick to a version we
113    # know works on Python 2.7.
114    "eliot ~= 1.7",
115
116    # Pyrsistent 0.17.0 (which we use by way of Eliot) has dropped
117    # Python 2 entirely; stick to the version known to work for us.
118    # XXX: drop this bound: https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3404
119    "pyrsistent < 0.17.0",
120
121    # A great way to define types of values.
122    # XXX: drop the upper bound: https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3390
123    "attrs >= 18.2.0, < 20",
124
125    # WebSocket library for twisted and asyncio
126    "autobahn >= 19.5.2",
127
128    # Support for Python 3 transition
129    "future >= 0.18.2",
130
131    # Discover local network configuration
132    "netifaces",
133
134    # Utility code:
135    "pyutil >= 3.3.0",
136
137    # Linux distribution detection:
138    "distro >= 1.4.0",
139
140    # Backported configparser for Python 2:
141    "configparser ; python_version < '3.0'",
142]
143
144setup_requires = [
145    'setuptools >= 28.8.0',  # for PEP-440 style versions
146]
147
148tor_requires = [
149    # This is exactly what `foolscap[tor]` means but pip resolves the pair of
150    # dependencies "foolscap[i2p] foolscap[tor]" to "foolscap[i2p]" so we lose
151    # this if we don't declare it ourselves!
152    "txtorcon >= 0.17.0",
153]
154
155i2p_requires = [
156    # txi2p has Python 3 support, but it's unreleased: https://github.com/str4d/txi2p/issues/10.
157    # URL lookups are in PEP-508 (via https://stackoverflow.com/a/54794506).
158    # Also see the comment in tor_requires.
159    "txi2p @ git+https://github.com/str4d/txi2p@0611b9a86172cb70d2f5e415a88eee9f230590b3#egg=txi2p",
160]
161
162if len(sys.argv) > 1 and sys.argv[1] == '--fakedependency':
163    del sys.argv[1]
164    install_requires += ["fakedependency >= 1.0.0"]
165
166from setuptools import find_packages, setup
167from setuptools import Command
168from setuptools.command import install
169
170
171trove_classifiers=[
172    "Development Status :: 5 - Production/Stable",
173    "Environment :: Console",
174    "Environment :: Web Environment",
175    "License :: OSI Approved :: GNU General Public License (GPL)",
176    "License :: DFSG approved",
177    "License :: Other/Proprietary License",
178    "Intended Audience :: Developers",
179    "Intended Audience :: End Users/Desktop",
180    "Intended Audience :: System Administrators",
181    "Operating System :: Microsoft",
182    "Operating System :: Microsoft :: Windows",
183    "Operating System :: Unix",
184    "Operating System :: POSIX :: Linux",
185    "Operating System :: POSIX",
186    "Operating System :: MacOS :: MacOS X",
187    "Operating System :: OS Independent",
188    "Natural Language :: English",
189    "Programming Language :: C",
190    "Programming Language :: Python",
191    "Programming Language :: Python :: 2",
192    "Programming Language :: Python :: 2.7",
193    "Topic :: Utilities",
194    "Topic :: System :: Systems Administration",
195    "Topic :: System :: Filesystems",
196    "Topic :: System :: Distributed Computing",
197    "Topic :: Software Development :: Libraries",
198    "Topic :: System :: Archiving :: Backup",
199    "Topic :: System :: Archiving :: Mirroring",
200    "Topic :: System :: Archiving",
201    ]
202
203
204GIT_VERSION_BODY = '''
205# This _version.py is generated from git metadata by the tahoe setup.py.
206
207__pkgname__ = "%(pkgname)s"
208real_version = "%(version)s"
209full_version = "%(full)s"
210branch = "%(branch)s"
211verstr = "%(normalized)s"
212__version__ = verstr
213'''
214
215def run_command(args, cwd=None):
216    use_shell = sys.platform == "win32"
217    try:
218        p = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=cwd, shell=use_shell)
219    except EnvironmentError as e:  # if this gives a SyntaxError, note that Tahoe-LAFS requires Python 2.7+
220        print("Warning: unable to run %r." % (" ".join(args),))
221        print(e)
222        return None
223    stdout = p.communicate()[0].strip()
224    if p.returncode != 0:
225        print("Warning: %r returned error code %r." % (" ".join(args), p.returncode))
226        return None
227    return stdout
228
229
230def versions_from_git(tag_prefix):
231    # This runs 'git' from the directory that contains this file. That either
232    # means someone ran a setup.py command (and this code is in
233    # versioneer.py, thus the containing directory is the root of the source
234    # tree), or someone ran a project-specific entry point (and this code is
235    # in _version.py, thus the containing directory is somewhere deeper in
236    # the source tree). This only gets called if the git-archive 'subst'
237    # variables were *not* expanded, and _version.py hasn't already been
238    # rewritten with a short version string, meaning we're inside a checked
239    # out source tree.
240
241    # versions_from_git (as copied from python-versioneer) returns strings
242    # like "1.9.0-25-gb73aba9-dirty", which means we're in a tree with
243    # uncommited changes (-dirty), the latest checkin is revision b73aba9,
244    # the most recent tag was 1.9.0, and b73aba9 has 25 commits that weren't
245    # in 1.9.0 . The narrow-minded NormalizedVersion parser that takes our
246    # output (meant to enable sorting of version strings) refuses most of
247    # that. Tahoe uses a function named suggest_normalized_version() that can
248    # handle "1.9.0.post25", so dumb down our output to match.
249
250    try:
251        source_dir = os.path.dirname(os.path.abspath(__file__))
252    except NameError as e:
253        # some py2exe/bbfreeze/non-CPython implementations don't do __file__
254        print("Warning: unable to find version because we could not obtain the source directory.")
255        print(e)
256        return {}
257    stdout = run_command(["git", "describe", "--tags", "--dirty", "--always"],
258                         cwd=source_dir)
259    if stdout is None:
260        # run_command already complained.
261        return {}
262    stdout = stdout.decode("ascii")
263    if not stdout.startswith(tag_prefix):
264        print("Warning: tag %r doesn't start with prefix %r." % (stdout, tag_prefix))
265        return {}
266    version = stdout[len(tag_prefix):]
267    pieces = version.split("-")
268    if len(pieces) == 1:
269        normalized_version = pieces[0]
270    else:
271        normalized_version = "%s.post%s" % (pieces[0], pieces[1])
272
273    stdout = run_command(["git", "rev-parse", "HEAD"], cwd=source_dir)
274    if stdout is None:
275        # run_command already complained.
276        return {}
277    full = stdout.decode("ascii").strip()
278    if version.endswith("-dirty"):
279        full += "-dirty"
280        normalized_version += ".dev0"
281
282    # Thanks to Jistanidiot at <http://stackoverflow.com/questions/6245570/get-current-branch-name>.
283    stdout = run_command(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=source_dir)
284    branch = (stdout or b"unknown").decode("ascii").strip()
285
286    # this returns native strings (bytes on py2, unicode on py3)
287    return {"version": version, "normalized": normalized_version,
288            "full": full, "branch": branch}
289
290# setup.cfg has an [aliases] section which runs "update_version" before many
291# commands (like "build" and "sdist") that need to know our package version
292# ahead of time. If you add different commands (or if we forgot some), you
293# may need to add it to setup.cfg and configure it to run update_version
294# before your command.
295
296class UpdateVersion(Command):
297    description = "update _version.py from revision-control metadata"
298    user_options = install.install.user_options
299
300    def initialize_options(self):
301        pass
302    def finalize_options(self):
303        pass
304    def run(self):
305        global version
306        verstr = version
307        if os.path.isdir(os.path.join(basedir, ".git")):
308            verstr = self.try_from_git()
309
310        if verstr:
311            self.distribution.metadata.version = verstr
312        else:
313            print("""\
314********************************************************************
315Warning: no version information found. This may cause tests to fail.
316********************************************************************
317""")
318
319    def try_from_git(self):
320        # If we change the release tag names, we must change this too
321        versions = versions_from_git("tahoe-lafs-")
322
323        # setup.py might be run by either py2 or py3 (when run by tox, which
324        # uses py3 on modern debian/ubuntu distros). We want this generated
325        # file to contain native strings on both (str=bytes in py2,
326        # str=unicode in py3)
327        if versions:
328            body = GIT_VERSION_BODY % {
329                "pkgname": self.distribution.get_name(),
330                "version": versions["version"],
331                "normalized": versions["normalized"],
332                "full": versions["full"],
333                "branch": versions["branch"],
334                }
335            f = open(VERSION_PY_FILENAME, "wb")
336            f.write(body.encode("ascii"))
337            f.close()
338            print("Wrote normalized version %r into '%s'" % (versions["normalized"], VERSION_PY_FILENAME))
339
340        return versions.get("normalized", None)
341
342class PleaseUseTox(Command):
343    user_options = []
344    def initialize_options(self):
345        pass
346    def finalize_options(self):
347        pass
348
349    def run(self):
350        print("ERROR: Please use 'tox' to run the test suite.")
351        sys.exit(1)
352
353setup_args = {}
354if version:
355    setup_args["version"] = version
356
357setup(name="tahoe-lafs", # also set in __init__.py
358      description='secure, decentralized, fault-tolerant file store',
359      long_description=open('README.rst', 'rU').read(),
360      author='the Tahoe-LAFS project',
361      author_email='tahoe-dev@tahoe-lafs.org',
362      url='https://tahoe-lafs.org/',
363      license='GNU GPL', # see README.rst -- there is an alternative licence
364      cmdclass={"update_version": UpdateVersion,
365                "test": PleaseUseTox,
366                },
367      package_dir = {'':'src'},
368      packages=find_packages('src') + ['allmydata.test.plugins'],
369      classifiers=trove_classifiers,
370      # We support Python 2.7, and we're working on support for 3.6 (the
371      # highest version that PyPy currently supports).
372      python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*",
373      install_requires=install_requires,
374      extras_require={
375          # Duplicate the Twisted pywin32 dependency here.  See
376          # https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2392 for some
377          # discussion.
378          ':sys_platform=="win32"': ["pywin32 != 226"],
379          "test": [
380              "flake8",
381              # Pin a specific pyflakes so we don't have different folks
382              # disagreeing on what is or is not a lint issue.  We can bump
383              # this version from time to time, but we will do it
384              # intentionally.
385              "pyflakes == 2.2.0",
386              # coverage 5.0 breaks the integration tests in some opaque way.
387              # This probably needs to be addressed in a more permanent way
388              # eventually...
389              "coverage ~= 4.5",
390              "mock",
391              "tox",
392              "pytest",
393              "pytest-twisted",
394              "hypothesis >= 3.6.1",
395              "treq",
396              "towncrier",
397              "testtools",
398              "fixtures",
399              "beautifulsoup4",
400              "html5lib",
401              "junitxml",
402              "tenacity",
403          ] + tor_requires + i2p_requires,
404          "tor": tor_requires,
405          "i2p": i2p_requires,
406      },
407      package_data={"allmydata.web": ["*.xhtml",
408                                      "static/*.js", "static/*.png", "static/*.css",
409                                      "static/img/*.png",
410                                      "static/css/*.css",
411                                      ],
412                    "allmydata": ["ported-modules.txt"],
413                    },
414      include_package_data=True,
415      setup_requires=setup_requires,
416      entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
417      **setup_args
418      )
Note: See TracBrowser for help on using the repository browser.