source: trunk/setup.py

Last change on this file was da4deab, checked in by Itamar Turner-Trauring <itamar@…>, at 2022-05-16T15:19:46Z

Note version with fix.

  • Property mode set to 100644
File size: 15.9 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
14from io import open
15
16basedir = os.path.dirname(os.path.abspath(__file__))
17
18# locate our version number
19
20def read_version_py(infname):
21    try:
22        verstrline = open(infname, "rt").read()
23    except EnvironmentError:
24        return None
25    else:
26        VSRE = r"^verstr = ['\"]([^'\"]*)['\"]"
27        mo = re.search(VSRE, verstrline, re.M)
28        if mo:
29            return mo.group(1)
30
31VERSION_PY_FILENAME = 'src/allmydata/_version.py'
32version = read_version_py(VERSION_PY_FILENAME)
33
34install_requires = [
35    # we don't need much out of setuptools but the version checking stuff
36    # needs pkg_resources and PEP 440 version specifiers.
37    "setuptools >= 28.8.0",
38
39    "zfec >= 1.1.0",
40
41    # zope.interface >= 3.6.0 is required for Twisted >= 12.1.0.
42    "zope.interface >= 3.6.0",
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 >= 21.7 is necessary for Python 3 with i2p support.
58    "foolscap >= 21.7.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    # * The SFTP frontend depends on Twisted 11.0.0 to fix the SSH server
67    #   rekeying bug <https://twistedmatrix.com/trac/ticket/4395>
68    # * The SFTP frontend and manhole depend on the conch extra. However, we
69    #   can't explicitly declare that without an undesirable dependency on gmpy,
70    #   as explained in ticket #2740.
71    # * Due to a setuptools bug, we need to declare a dependency on the tls
72    #   extra even though we only depend on it via foolscap.
73    # * Twisted >= 15.1.0 is the first version that provided the [tls] extra.
74    # * Twisted-16.1.0 fixes https://twistedmatrix.com/trac/ticket/8223,
75    #   which otherwise causes test_system to fail (DirtyReactorError, due to
76    #   leftover timers)
77    # * Twisted-16.4.0 introduces `python -m twisted.trial` which is needed
78    #   for coverage testing
79    # * Twisted 16.6.0 drops the undesirable gmpy dependency from the conch
80    #   extra, letting us use that extra instead of trying to duplicate its
81    #   dependencies here.  Twisted[conch] >18.7 introduces a dependency on
82    #   bcrypt.  It is nice to avoid that if the user ends up with an older
83    #   version of Twisted.  That's hard to express except by using the extra.
84    #
85    # * Twisted 18.4.0 adds `client` and `host` attributes to `Request` in the
86    # * initializer, needed by logic in our custom `Request` subclass.
87    #
88    #   In a perfect world, Twisted[conch] would be a dependency of an "sftp"
89    #   extra.  However, pip fails to resolve the dependencies all
90    #   dependencies when asked for Twisted[tls] *and* Twisted[conch].
91    #   Specifically, "Twisted[conch]" (as the later requirement) is ignored.
92    #   If there were an Tahoe-LAFS sftp extra that dependended on
93    #   Twisted[conch] and install_requires only included Twisted[tls] then
94    #   `pip install tahoe-lafs[sftp]` would not install requirements
95    #   specified by Twisted[conch].  Since this would be the *whole point* of
96    #   an sftp extra in Tahoe-LAFS, there is no point in having one.
97    # * Twisted 19.10 introduces Site.getContentFile which we use to get
98    #   temporary upload files placed into a per-node temporary directory.
99    "Twisted[tls,conch] >= 19.10.0",
100
101    "PyYAML >= 3.11",
102
103    "six >= 1.10.0",
104
105    # for 'tahoe invite' and 'tahoe join'
106    "magic-wormhole >= 0.10.2",
107
108    # We want a new enough version to support custom JSON encoders.
109    "eliot >= 1.13.0",
110
111    "pyrsistent",
112
113    # A great way to define types of values.
114    "attrs >= 18.2.0",
115
116    # WebSocket library for twisted and asyncio
117    "autobahn < 22.4.1",  # remove this when 22.4.3 is released
118
119    # Support for Python 3 transition
120    "future >= 0.18.2",
121
122    # Discover local network configuration
123    "netifaces",
124
125    # Utility code:
126    "pyutil >= 3.3.0",
127
128    # Linux distribution detection:
129    "distro >= 1.4.0",
130
131    # For the RangeMap datastructure. Need 2.0.2 at least for bugfixes.
132    "collections-extended >= 2.0.2",
133
134    # HTTP server and client
135    "klein",
136    "werkzeug",
137    "treq",
138    "cbor2",
139    "pycddl",
140]
141
142setup_requires = [
143    'setuptools >= 28.8.0',  # for PEP-440 style versions
144]
145
146tor_requires = [
147    # This is exactly what `foolscap[tor]` means but pip resolves the pair of
148    # dependencies "foolscap[i2p] foolscap[tor]" to "foolscap[i2p]" so we lose
149    # this if we don't declare it ourselves!
150    "txtorcon >= 0.17.0",
151]
152
153i2p_requires = [
154    # txi2p has Python 3 support in master branch, but it has not been
155    # released -- see https://github.com/str4d/txi2p/issues/10.  We
156    # could use a fork for Python 3 until txi2p's maintainers are back
157    # in action.  For Python 2, we could continue using the txi2p
158    # version about which no one has complained to us so far.
159    "txi2p; python_version < '3.0'",
160    "txi2p-tahoe >= 0.3.5; python_version > '3.0'",
161]
162
163if len(sys.argv) > 1 and sys.argv[1] == '--fakedependency':
164    del sys.argv[1]
165    install_requires += ["fakedependency >= 1.0.0"]
166
167from setuptools import find_packages, setup
168from setuptools import Command
169from setuptools.command import install
170
171
172trove_classifiers=[
173    "Development Status :: 5 - Production/Stable",
174    "Environment :: Console",
175    "Environment :: Web Environment",
176    "License :: OSI Approved :: GNU General Public License (GPL)",
177    "License :: DFSG approved",
178    "License :: Other/Proprietary License",
179    "Intended Audience :: Developers",
180    "Intended Audience :: End Users/Desktop",
181    "Intended Audience :: System Administrators",
182    "Operating System :: Microsoft",
183    "Operating System :: Microsoft :: Windows",
184    "Operating System :: Unix",
185    "Operating System :: POSIX :: Linux",
186    "Operating System :: POSIX",
187    "Operating System :: MacOS :: MacOS X",
188    "Operating System :: OS Independent",
189    "Natural Language :: English",
190    "Programming Language :: C",
191    "Programming Language :: Python",
192    "Programming Language :: Python :: 3",
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 3.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', 'r', encoding='utf-8').read(),
360      author='the Tahoe-LAFS project',
361      author_email='tahoe-dev@lists.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 3.7 or later. 3.11 is not supported yet.
371      python_requires=">=3.7, <3.11",
372      install_requires=install_requires,
373      extras_require={
374          # Duplicate the Twisted pywin32 dependency here.  See
375          # https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2392 for some
376          # discussion.
377          ':sys_platform=="win32"': ["pywin32 != 226"],
378          "test": [
379              "flake8",
380              # Pin a specific pyflakes so we don't have different folks
381              # disagreeing on what is or is not a lint issue.  We can bump
382              # this version from time to time, but we will do it
383              # intentionally.
384              "pyflakes == 2.2.0",
385              "coverage ~= 5.0",
386              "mock",
387              "tox",
388              "pytest",
389              "pytest-twisted",
390              "hypothesis >= 3.6.1",
391              "towncrier",
392              "testtools",
393              "fixtures",
394              "beautifulsoup4",
395              "html5lib",
396              "junitxml",
397              "tenacity",
398              # Pin old version until
399              # https://github.com/paramiko/paramiko/issues/1961 is fixed.
400              "paramiko < 2.9",
401              "pytest-timeout",
402              # Does our OpenMetrics endpoint adhere to the spec:
403              "prometheus-client == 0.11.0",
404          ] + tor_requires + i2p_requires,
405          "tor": tor_requires,
406          "i2p": i2p_requires,
407      },
408      package_data={"allmydata.web": ["*.xhtml",
409                                      "static/*.js", "static/*.png", "static/*.css",
410                                      "static/img/*.png",
411                                      "static/css/*.css",
412                                      ],
413                    "allmydata": ["ported-modules.txt"],
414                    },
415      include_package_data=True,
416      setup_requires=setup_requires,
417      entry_points = { 'console_scripts': [ 'tahoe = allmydata.scripts.runner:run' ] },
418      **setup_args
419      )
Note: See TracBrowser for help on using the repository browser.