Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop support for Py2 and Py3.4 #498

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# Exit when any command fails.
set -e

PYTHON_VERSION=${PYTHON_VERSION:-2.7}

pip install -U -r .github/scripts/requirements.txt
python setup.py develop
python -m pytest # Run the tests without IPython.
Expand Down
9 changes: 3 additions & 6 deletions .github/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
setuptools <65.7.0 ; python_version == '2.7'
setuptools <=69.1.1 ; python_version >= '3.8'
pip <23.0 ; python_version == '2.7'
pip ; python_version >= '3.5'
setuptools <=69.1.1
pip
pylint <2.15.10
pytest <=8.1.1
pytest-pylint <=1.1.2
pytest-runner <7.0.0
termcolor <2.5.0
hypothesis <6.100.0
python-Levenshtein <0.20.9 ; python_version == '2.7'
levenshtein <=0.25.0 ; python_version >= '3.5'
levenshtein <=0.25.0
mock <6.0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency can be removed and replaced with stdlib's unittest.mock.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on the case #545

4 changes: 0 additions & 4 deletions examples/diff/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

r"""A command line tool for diffing files.

The Python 2.7 documentation demonstrates how to make a command line interface
for the difflib library using optparse:
https://docs.python.org/2/library/difflib.html#a-command-line-interface-to-difflib

This file demonstrates how to create a command line interface providing the same
functionality using Python Fire.

Expand Down
70 changes: 14 additions & 56 deletions fire/console/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,10 @@ def AsyncPopenArgs(self):


class PythonVersion(object):
"""Class to validate the Python version we are using.

The Cloud SDK officially supports Python 2.7.

However, many commands do work with Python 2.6, so we don't error out when
users are using this (we consider it sometimes "compatible" but not
"supported").
"""
"""Class to validate the Python version we are using."""

# See class docstring for descriptions of what these mean
MIN_REQUIRED_PY2_VERSION = (2, 6)
MIN_SUPPORTED_PY2_VERSION = (2, 7)
MIN_SUPPORTED_PY3_VERSION = (3, 4)
MIN_SUPPORTED_PY3_VERSION = (3, 5)
ENV_VAR_MESSAGE = """\

If you have a compatible Python interpreter installed, you can use it by setting
Expand All @@ -404,29 +395,17 @@ def __init__(self, version=None):
else:
self.version = None

def SupportedVersionMessage(self, allow_py3):
if allow_py3:
return 'Please use Python version {0}.{1}.x or {2}.{3} and up.'.format(
PythonVersion.MIN_SUPPORTED_PY2_VERSION[0],
PythonVersion.MIN_SUPPORTED_PY2_VERSION[1],
PythonVersion.MIN_SUPPORTED_PY3_VERSION[0],
PythonVersion.MIN_SUPPORTED_PY3_VERSION[1])
else:
return 'Please use Python version {0}.{1}.x.'.format(
PythonVersion.MIN_SUPPORTED_PY2_VERSION[0],
PythonVersion.MIN_SUPPORTED_PY2_VERSION[1])
def SupportedVersionMessage(self):
return 'Please use Python version {0}.{1} and up.'.format(
PythonVersion.MIN_SUPPORTED_PY3_VERSION[0],
PythonVersion.MIN_SUPPORTED_PY3_VERSION[1])

def IsCompatible(self, allow_py3=False, raise_exception=False):
def IsCompatible(self, raise_exception=False):
"""Ensure that the Python version we are using is compatible.

This will print an error message if not compatible.

Compatible versions are 2.6 and 2.7 and > 3.4 if allow_py3 is True.
We don't guarantee support for 2.6 so we want to warn about it.

Args:
allow_py3: bool, True if we should allow a Python 3 interpreter to run
gcloud. If False, this returns an error for Python 3.
raise_exception: bool, True to raise an exception rather than printing
the error and exiting.

Expand All @@ -441,26 +420,14 @@ def IsCompatible(self, allow_py3=False, raise_exception=False):
# We don't know the version, not a good sign.
error = ('ERROR: Your current version of Python is not compatible with '
'the Google Cloud SDK. {0}\n'
.format(self.SupportedVersionMessage(allow_py3)))
.format(self.SupportedVersionMessage()))
else:
if self.version[0] < 3:
# Python 2 Mode
if self.version < PythonVersion.MIN_REQUIRED_PY2_VERSION:
error = ('ERROR: Python {0}.{1} is not compatible with the Google '
'Cloud SDK. {2}\n'
.format(self.version[0], self.version[1],
self.SupportedVersionMessage(allow_py3)))
else:
# Python 3 Mode
if not allow_py3:
error = ('ERROR: Python 3 and later is not compatible with the '
'Google Cloud SDK. {0}\n'
.format(self.SupportedVersionMessage(allow_py3)))
elif self.version < PythonVersion.MIN_SUPPORTED_PY3_VERSION:
error = ('ERROR: Python {0}.{1} is not compatible with the Google '
'Cloud SDK. {2}\n'
.format(self.version[0], self.version[1],
self.SupportedVersionMessage(allow_py3)))
# Python 3 Mode
if self.version < PythonVersion.MIN_SUPPORTED_PY3_VERSION:
error = ('ERROR: Python {0}.{1} is not compatible with the Google '
'Cloud SDK. {2}\n'
.format(self.version[0], self.version[1],
self.SupportedVersionMessage()))

if error:
if raise_exception:
Expand All @@ -469,13 +436,4 @@ def IsCompatible(self, allow_py3=False, raise_exception=False):
sys.stderr.write(PythonVersion.ENV_VAR_MESSAGE)
return False

# Warn that 2.6 might not work.
if (self.version >= self.MIN_REQUIRED_PY2_VERSION and
self.version < self.MIN_SUPPORTED_PY2_VERSION):
sys.stderr.write("""\
WARNING: Python 2.6.x is no longer officially supported by the Google Cloud SDK
and may not function correctly. {0}
{1}""".format(self.SupportedVersionMessage(allow_py3),
PythonVersion.ENV_VAR_MESSAGE))

return True
2 changes: 0 additions & 2 deletions fire/fire_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,6 @@ def testClassWithInvalidProperty(self):
fire.Fire(tc.InvalidProperty, command=['double', '10']), 20
)

@testutils.skipIf(sys.version_info[0:2] <= (3, 4),
'Cannot inspect wrapped signatures in Python 2 or 3.4.')
def testHelpKwargsDecorator(self):
# Issue #190, follow the wrapped method instead of crashing.
with self.assertRaisesFireExit(0):
Expand Down
14 changes: 2 additions & 12 deletions fire/inspectutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,8 @@ def GetFullArgSpec(fn):
fn, skip_arg = _GetArgSpecInfo(fn)

try:
if sys.version_info[0:2] >= (3, 5):
(args, varargs, varkw, defaults,
(args, varargs, varkw, defaults,
kwonlyargs, kwonlydefaults, annotations) = Py3GetFullArgSpec(fn)
elif six.PY3: # Specifically Python 3.4.
(args, varargs, varkw, defaults,
kwonlyargs, kwonlydefaults, annotations) = inspect.getfullargspec(fn) # pylint: disable=deprecated-method,no-member
else: # six.PY2
args, varargs, varkw, defaults = Py2GetArgSpec(fn)
kwonlyargs = kwonlydefaults = None
annotations = getattr(fn, '__annotations__', None)

except TypeError:
# If we can't get the argspec, how do we know if the fn should take args?
Expand Down Expand Up @@ -224,9 +216,7 @@ def GetFullArgSpec(fn):
# Case 3: Other known slot wrappers do not accept args.
return FullArgSpec()

# In Python 3.5+ Py3GetFullArgSpec uses skip_bound_arg=True already.
skip_arg_required = six.PY2 or sys.version_info[0:2] == (3, 4)
if skip_arg_required and skip_arg and args:
if skip_arg and args:
args.pop(0) # Remove 'self' or 'cls' from the list of arguments.
return FullArgSpec(args, varargs, varkw, defaults,
kwonlyargs, kwonlydefaults, annotations)
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
DEPENDENCIES = [
'six',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The six dependency can be replaced and removed.

Running pyupgrade **/**.py --py3-plus can help, and also upgrade a lot of other syntax.

https://github.com/asottile/pyupgrade

'termcolor',
'enum34; python_version < "3.4"'
]

TEST_DEPENDENCIES = [
Expand All @@ -49,6 +48,7 @@
description=SHORT_DESCRIPTION,
long_description=LONG_DESCRIPTION,
url=URL,
python_requires='>=3.5',

author='David Bieber',
author_email='[email protected]',
Expand All @@ -63,9 +63,8 @@
'License :: OSI Approved :: Apache Software License',

'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
Borda marked this conversation as resolved.
Show resolved Hide resolved
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
Expand Down