source: trunk/setup.py

Last change on this file was 5bd84895, checked in by GitHub <noreply@…>, at 2020-01-20T19:09:32Z

Merge pull request #685 from tahoe-lafs/2392.pywin32

Replace pypiwin32 with pywin32

Fixes: ticket:2392

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