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 all 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:-3.7}

pip install -U -r .github/scripts/requirements.txt
python setup.py develop
python -m pytest # Run the tests without IPython.
Expand Down
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 @@ -378,19 +378,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 @@ -406,29 +397,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 @@ -443,26 +422,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 @@ -471,13 +438,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
10 changes: 2 additions & 8 deletions fire/inspectutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,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)
else: # Specifically Python 3.4.
(args, varargs, varkw, defaults,
kwonlyargs, kwonlydefaults, annotations) = inspect.getfullargspec(fn) # pylint: disable=deprecated-method,no-member

except TypeError:
# If we can't get the argspec, how do we know if the fn should take args?
Expand Down Expand Up @@ -200,9 +196,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 = 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
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
description=SHORT_DESCRIPTION,
long_description=LONG_DESCRIPTION,
url=URL,
python_requires='>=3.5',

author='David Bieber',
author_email='[email protected]',
Expand All @@ -61,6 +62,9 @@

'Programming Language :: Python',
'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',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
Expand Down
Loading