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. 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 13fd8204..b3d9d82a 100644 --- a/fire/console/platforms.py +++ b/fire/console/platforms.py @@ -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 @@ -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. @@ -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: @@ -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 diff --git a/fire/inspectutils.py b/fire/inspectutils.py index a3ae7c27..eac417c0 100644 --- a/fire/inspectutils.py +++ b/fire/inspectutils.py @@ -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? @@ -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) diff --git a/setup.py b/setup.py index 82073be4..51dda0c6 100644 --- a/setup.py +++ b/setup.py @@ -46,6 +46,7 @@ description=SHORT_DESCRIPTION, long_description=LONG_DESCRIPTION, url=URL, + python_requires='>=3.5', author='David Bieber', author_email='dbieber@google.com', @@ -61,6 +62,9 @@ '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', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9',