mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-17 06:48:20 +00:00
setup.py: work with tox under py3
This allows a python3-based "tox" (as shipped with modern debian and ubuntu systems) to run setup.py egg_info, update_version, and sdist commands. It moves the main "tahoe requires py2" check out of setup.py and into allmydata.scripts.runner.run, where it gets applied at runtime rather than build time. It also changes the execfile(_auto_deps.py) and Versioneer-like "ask git what our version string should be" code to work under both py2 and py3. fixes ticket:2747
This commit is contained in:
50
setup.py
50
setup.py
@ -1,6 +1,6 @@
|
|||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import sys; assert sys.version_info < (3,), ur"Tahoe-LAFS does not run under Python 3. Please use Python 2.7.x."
|
import sys
|
||||||
|
|
||||||
# Tahoe-LAFS -- secure, distributed storage grid
|
# Tahoe-LAFS -- secure, distributed storage grid
|
||||||
#
|
#
|
||||||
@ -12,8 +12,6 @@ import sys; assert sys.version_info < (3,), ur"Tahoe-LAFS does not run under Pyt
|
|||||||
|
|
||||||
import os, subprocess, re
|
import os, subprocess, re
|
||||||
|
|
||||||
##### sys.path management
|
|
||||||
|
|
||||||
basedir = os.path.dirname(os.path.abspath(__file__))
|
basedir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
# locate our version number
|
# locate our version number
|
||||||
@ -49,7 +47,12 @@ else:
|
|||||||
# the _auto_deps.install_requires list, which is used in the call to setup()
|
# the _auto_deps.install_requires list, which is used in the call to setup()
|
||||||
# below.
|
# below.
|
||||||
adglobals = {}
|
adglobals = {}
|
||||||
execfile('src/allmydata/_auto_deps.py', adglobals)
|
auto_deps_fn = "src/allmydata/_auto_deps.py"
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
exec(compile(open(auto_deps_fn, 'rb').read(), auto_deps_fn, "exec"),
|
||||||
|
adglobals, adglobals)
|
||||||
|
else:
|
||||||
|
execfile(auto_deps_fn, adglobals)
|
||||||
install_requires = adglobals['install_requires']
|
install_requires = adglobals['install_requires']
|
||||||
setup_requires = adglobals['setup_requires']
|
setup_requires = adglobals['setup_requires']
|
||||||
|
|
||||||
@ -98,11 +101,11 @@ trove_classifiers=[
|
|||||||
GIT_VERSION_BODY = '''
|
GIT_VERSION_BODY = '''
|
||||||
# This _version.py is generated from git metadata by the tahoe setup.py.
|
# This _version.py is generated from git metadata by the tahoe setup.py.
|
||||||
|
|
||||||
__pkgname__ = %(pkgname)r
|
__pkgname__ = "%(pkgname)s"
|
||||||
real_version = %(version)r
|
real_version = "%(version)s"
|
||||||
full_version = %(full)r
|
full_version = "%(full)s"
|
||||||
branch = %(branch)r
|
branch = "%(branch)s"
|
||||||
verstr = %(normalized)r
|
verstr = "%(normalized)s"
|
||||||
__version__ = verstr
|
__version__ = verstr
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@ -153,6 +156,7 @@ def versions_from_git(tag_prefix):
|
|||||||
if stdout is None:
|
if stdout is None:
|
||||||
# run_command already complained.
|
# run_command already complained.
|
||||||
return {}
|
return {}
|
||||||
|
stdout = stdout.decode("ascii")
|
||||||
if not stdout.startswith(tag_prefix):
|
if not stdout.startswith(tag_prefix):
|
||||||
print("Warning: tag %r doesn't start with prefix %r." % (stdout, tag_prefix))
|
print("Warning: tag %r doesn't start with prefix %r." % (stdout, tag_prefix))
|
||||||
return {}
|
return {}
|
||||||
@ -167,16 +171,18 @@ def versions_from_git(tag_prefix):
|
|||||||
if stdout is None:
|
if stdout is None:
|
||||||
# run_command already complained.
|
# run_command already complained.
|
||||||
return {}
|
return {}
|
||||||
full = stdout.strip()
|
full = stdout.decode("ascii").strip()
|
||||||
if version.endswith("-dirty"):
|
if version.endswith("-dirty"):
|
||||||
full += "-dirty"
|
full += "-dirty"
|
||||||
normalized_version += ".dev0"
|
normalized_version += ".dev0"
|
||||||
|
|
||||||
# Thanks to Jistanidiot at <http://stackoverflow.com/questions/6245570/get-current-branch-name>.
|
# Thanks to Jistanidiot at <http://stackoverflow.com/questions/6245570/get-current-branch-name>.
|
||||||
stdout = run_command(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=source_dir)
|
stdout = run_command(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=source_dir)
|
||||||
branch = (stdout or "unknown").strip()
|
branch = (stdout or b"unknown").decode("ascii").strip()
|
||||||
|
|
||||||
return {"version": version, "normalized": normalized_version, "full": full, "branch": branch}
|
# this returns native strings (bytes on py2, unicode on py3)
|
||||||
|
return {"version": version, "normalized": normalized_version,
|
||||||
|
"full": full, "branch": branch}
|
||||||
|
|
||||||
# setup.cfg has an [aliases] section which runs "update_version" before many
|
# setup.cfg has an [aliases] section which runs "update_version" before many
|
||||||
# commands (like "build" and "sdist") that need to know our package version
|
# commands (like "build" and "sdist") that need to know our package version
|
||||||
@ -210,15 +216,21 @@ Warning: no version information found. This may cause tests to fail.
|
|||||||
def try_from_git(self):
|
def try_from_git(self):
|
||||||
# If we change APPNAME, the release tag names should also change from then on.
|
# If we change APPNAME, the release tag names should also change from then on.
|
||||||
versions = versions_from_git(APPNAME + '-')
|
versions = versions_from_git(APPNAME + '-')
|
||||||
|
|
||||||
|
# setup.py might be run by either py2 or py3 (when run by tox, which
|
||||||
|
# uses py3 on modern debian/ubuntu distros). We want this generated
|
||||||
|
# file to contain native strings on both (str=bytes in py2,
|
||||||
|
# str=unicode in py3)
|
||||||
if versions:
|
if versions:
|
||||||
|
body = GIT_VERSION_BODY % {
|
||||||
|
"pkgname": self.distribution.get_name(),
|
||||||
|
"version": versions["version"],
|
||||||
|
"normalized": versions["normalized"],
|
||||||
|
"full": versions["full"],
|
||||||
|
"branch": versions["branch"],
|
||||||
|
}
|
||||||
f = open(VERSION_PY_FILENAME, "wb")
|
f = open(VERSION_PY_FILENAME, "wb")
|
||||||
f.write(GIT_VERSION_BODY %
|
f.write(body.encode("ascii"))
|
||||||
{ "pkgname": self.distribution.get_name(),
|
|
||||||
"version": versions["version"],
|
|
||||||
"normalized": versions["normalized"],
|
|
||||||
"full": versions["full"],
|
|
||||||
"branch": versions["branch"],
|
|
||||||
})
|
|
||||||
f.close()
|
f.close()
|
||||||
print("Wrote normalized version %r into '%s'" % (versions["normalized"], VERSION_PY_FILENAME))
|
print("Wrote normalized version %r into '%s'" % (versions["normalized"], VERSION_PY_FILENAME))
|
||||||
|
|
||||||
|
@ -93,6 +93,8 @@ def runner(argv,
|
|||||||
stdin=None, stdout=None, stderr=None,
|
stdin=None, stdout=None, stderr=None,
|
||||||
install_node_control=True, additional_commands=None):
|
install_node_control=True, additional_commands=None):
|
||||||
|
|
||||||
|
assert sys.version_info < (3,), ur"Tahoe-LAFS does not run under Python 3. Please use Python 2.7.x."
|
||||||
|
|
||||||
stdin = stdin or sys.stdin
|
stdin = stdin or sys.stdin
|
||||||
stdout = stdout or sys.stdout
|
stdout = stdout or sys.stdout
|
||||||
stderr = stderr or sys.stderr
|
stderr = stderr or sys.stderr
|
||||||
|
Reference in New Issue
Block a user