diff --git a/python/invoke_release/tasks.py b/python/invoke_release/tasks.py index e96d57e..5e79a1d 100644 --- a/python/invoke_release/tasks.py +++ b/python/invoke_release/tasks.py @@ -3,21 +3,18 @@ import codecs from contextlib import closing import datetime -from distutils.version import LooseVersion +import importlib import json import os -from pkg_resources import parse_version import re import shlex import subprocess import sys import tempfile +import urllib.request from invoke import task -import six -from six import moves -from six.moves import urllib -from wheel import archive +from packaging.version import Version, parse as parse_version RE_CHANGELOG_FILE_HEADER = re.compile(r'^=+$') RE_CHANGELOG_VERSION_HEADER = re.compile(r'^-+$') @@ -143,12 +140,8 @@ def _standard_output(message, *args, **kwargs): def _prompt(message, *args, **kwargs): _print_output(COLOR_WHITE, message + ' ', *args, **kwargs) - # noinspection PyCompatibility - response = moves.input() + response = input() if response: - if not isinstance(response, six.text_type): - # Input returns a bytestring in Python 2 and a unicode string in Python 3 - return response.decode('utf8').strip() return response.strip() return '' @@ -329,7 +322,7 @@ def _prompt_for_changelog(verbose): if len(built_up_changelog) > 0: _verbose_output(verbose, 'Read {} lines of built-up changelog text:', len(built_up_changelog)) if verbose: - _verbose_output(verbose, six.text_type(built_up_changelog)) + _verbose_output(verbose, str(built_up_changelog)) _standard_output('There are existing changelog details for this release. You can "edit" the changes, ' '"accept" them as-is, delete them and create a "new" changelog message, or "delete" ' 'them and enter no changelog.') @@ -1242,9 +1235,9 @@ def branch(_, verbose=False, no_stash=False): if branch_version not in tags: raise ReleaseFailure('Version number {} not in the list of available tags.'.format(branch_version)) - _v = LooseVersion(branch_version) - minor_branch = '.'.join(list(map(six.text_type, _v.version[:2])) + ['x']) - major_branch = '.'.join(list(map(six.text_type, _v.version[:1])) + ['x', 'x']) + _v = Version(branch_version).release + minor_branch = '.'.join(list(map(str, _v[:2])) + ['x']) + major_branch = '.'.join(list(map(str, _v[:1])) + ['x', 'x']) proceed_instruction = _prompt( 'Using tag {tag}, would you like to create a minor branch for patch versions (branch {minor}, ' @@ -1419,7 +1412,7 @@ def release(_, verbose=False, no_stash=False): else: version_info = list(map(int, version_info)) release_version = version_separator.join( - filter(None, ['.'.join(map(six.text_type, version_info[:3])), (version_info[3:] or [None])[0]]) + filter(None, ['.'.join(map(str, version_info[:3])), (version_info[3:] or [None])[0]]) ) # This must match the code in VERSION_VARIABLE_TEMPLATE at the top of this file if not (parse_version(release_version) > parse_version(__version__)): @@ -1586,8 +1579,7 @@ def rollback_release(_, verbose=False, no_stash=False): _standard_output('The commit was not reverted.') version_module = __import__('{}.version'.format(MODULE_NAME), fromlist=[str('__version__')]) - # noinspection PyCompatibility - moves.reload_module(version_module) + importlib.reload(version_module) _post_rollback(__version__, version_module.__version__) _standard_output('Release rollback is complete.') @@ -1615,6 +1607,17 @@ def wheel(_): Future possible changes: Upload to the wheel server. """ + # `wheel.archive` was removed in wheel 0.32. On modern environments we + # cannot run this task; on older environments (wheel <0.32) it still works. + try: + from wheel import archive # noqa: F401 (lazy import on purpose) + except ImportError: + raise ReleaseFailure( + 'The `invoke wheel` task requires `wheel<0.32` (the `wheel.archive` ' + 'module was removed in wheel 0.32). Build wheels with ' + '`python -m build --wheel` instead.' + ) + build_instruction = _prompt('Build a wheel archive of {}? (Y/n):'.format(MODULE_DISPLAY_NAME)).lower() if build_instruction == INSTRUCTION_NO: @@ -1630,11 +1633,10 @@ def wheel(_): def open_pull_request(branch_name, current_branch_name, display_name, version_to_release, github_token): - remote = six.text_type( - subprocess.check_output( - ['git', 'remote', 'get-url', 'origin'], - stderr=subprocess.STDOUT, - ) + remote = subprocess.check_output( + ['git', 'remote', 'get-url', 'origin'], + stderr=subprocess.STDOUT, + universal_newlines=True, ) repo = (remote.split(':')[1].split('.')[0]) url = 'https://api.github.com/repos/{}/pulls'.format(repo) diff --git a/setup.py b/setup.py index 1940a5d..d73f631 100644 --- a/setup.py +++ b/setup.py @@ -13,9 +13,9 @@ # No dependencies to keep the library lightweight install_requires = [ - 'invoke~=0.22.0', - 'six~=1.11.0', - 'wheel~=0.31.1' + 'invoke>=1.0,<3.0', + 'packaging>=20.0', + 'wheel>=0.31.1', ] tests_require = [