From 5b159d7031ee8306c071a8ce00b8576f37146ee0 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 12 Mar 2024 11:51:57 +0100 Subject: [PATCH 1/3] drop support for Py2 and Py3.4 --- .github/scripts/build.sh | 2 - .github/scripts/requirements.txt | 9 ++-- examples/diff/diff.py | 4 -- fire/console/platforms.py | 70 +++++++------------------------- fire/fire_test.py | 2 - fire/inspectutils.py | 13 +----- setup.py | 4 +- 7 files changed, 20 insertions(+), 84 deletions(-) diff --git a/.github/scripts/build.sh b/.github/scripts/build.sh index 1f9ed766..b9c56926 100755 --- a/.github/scripts/build.sh +++ b/.github/scripts/build.sh @@ -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. diff --git a/.github/scripts/requirements.txt b/.github/scripts/requirements.txt index 654f6079..3fe4a105 100644 --- a/.github/scripts/requirements.txt +++ b/.github/scripts/requirements.txt @@ -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 diff --git a/examples/diff/diff.py b/examples/diff/diff.py index f99e525e..ea64a0ef 100644 --- a/examples/diff/diff.py +++ b/examples/diff/diff.py @@ -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. diff --git a/fire/console/platforms.py b/fire/console/platforms.py index 018eb89e..22e4b451 100644 --- a/fire/console/platforms.py +++ b/fire/console/platforms.py @@ -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 @@ -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. @@ -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: @@ -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 diff --git a/fire/fire_test.py b/fire/fire_test.py index 8b904c29..ccc3f6f3 100644 --- a/fire/fire_test.py +++ b/fire/fire_test.py @@ -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): diff --git a/fire/inspectutils.py b/fire/inspectutils.py index 15f32f91..fce3ecbf 100644 --- a/fire/inspectutils.py +++ b/fire/inspectutils.py @@ -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? @@ -225,8 +217,7 @@ def GetFullArgSpec(fn): 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) diff --git a/setup.py b/setup.py index 24e0e325..ad6f48ed 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,6 @@ DEPENDENCIES = [ 'six', 'termcolor', - 'enum34; python_version < "3.4"' ] TEST_DEPENDENCIES = [ @@ -49,6 +48,7 @@ description=SHORT_DESCRIPTION, long_description=LONG_DESCRIPTION, url=URL, + python_requires='>=3.5', author='David Bieber', author_email='dbieber@google.com', @@ -63,8 +63,6 @@ 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', From 72b228b9aeeac44818250db45b3d35ad3435f70e Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+Borda@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:42:47 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- fire/inspectutils.py | 1 - setup.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/fire/inspectutils.py b/fire/inspectutils.py index fce3ecbf..e4e9a5ff 100644 --- a/fire/inspectutils.py +++ b/fire/inspectutils.py @@ -216,7 +216,6 @@ 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. if skip_arg and args: args.pop(0) # Remove 'self' or 'cls' from the list of arguments. return FullArgSpec(args, varargs, varkw, defaults, diff --git a/setup.py b/setup.py index ad6f48ed..fc6622fd 100644 --- a/setup.py +++ b/setup.py @@ -64,6 +64,7 @@ 'Programming Language :: Python', 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', From 6fc08ccc700b0ea981d6cb29fae86b486fb0ac25 Mon Sep 17 00:00:00 2001 From: Jirka B Date: Fri, 20 Sep 2024 16:46:06 +0200 Subject: [PATCH 3/3] update build --- .github/scripts/build.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/scripts/build.sh b/.github/scripts/build.sh index 111257ae..b9c56926 100755 --- a/.github/scripts/build.sh +++ b/.github/scripts/build.sh @@ -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.