[python-experimental] Removes python2 (#6991)

* Removes future from python-exp v3 sample

* Removes future from python-exp v2 sample

* Deletes future from remaining python-exp files

* Removes six from python-exp templates

* Removes six from python-exp samples

* Removes mock from python-exp

* Python-exp switched to py3

* Removes python 2.7 for python-exp ci testing

* Requires python>=3.3 for python-exp

* Reverts unnecessary changes to two templates
This commit is contained in:
Justin Black
2020-07-19 09:45:56 -07:00
committed by GitHub
parent ed84280108
commit 0e0f8eb74c
447 changed files with 1512 additions and 1859 deletions

View File

@@ -10,9 +10,6 @@ stages:
- pip install -r test-requirements.txt
- pytest --cov=dynamic_servers
nosetest-2.7:
extends: .nosetest
image: python:2.7-alpine
nosetest-3.3:
extends: .nosetest
image: python:3.3-alpine

View File

@@ -1,7 +1,6 @@
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"

View File

@@ -9,7 +9,7 @@ This Python package is automatically generated by the [OpenAPI Generator](https:
## Requirements.
Python 2.7 and 3.4+
Python 3.4+
## Installation & Usage
### pip install
@@ -45,7 +45,6 @@ import dynamic_servers
Please follow the [installation procedure](#installation--usage) and then run the following:
```python
from __future__ import print_function
import time
import dynamic_servers

View File

@@ -18,7 +18,6 @@ Use custom server
### Example
```python
from __future__ import print_function
import time
import dynamic_servers
from dynamic_servers.api import usage_api
@@ -77,7 +76,6 @@ Use default server
### Example
```python
from __future__ import print_function
import time
import dynamic_servers
from dynamic_servers.api import usage_api

View File

@@ -12,8 +12,6 @@
"""
from __future__ import absolute_import
__version__ = "1.0.0"
# import ApiClient

View File

@@ -1,6 +1,3 @@
from __future__ import absolute_import
# flake8: noqa
# import apis into api package
from dynamic_servers.api.usage_api import UsageApi
# do not import all apis into this module because that uses a lot of memory and stack frames
# if you need the ability to import all apis from one package, import them with
# from {{packageName}.apis import DefaultApi, PetApi

View File

@@ -10,14 +10,9 @@
"""
from __future__ import absolute_import
import re # noqa: F401
import sys # noqa: F401
# python 2 and python 3 compatibility library
import six
from dynamic_servers.api_client import ApiClient, Endpoint
from dynamic_servers.model_utils import ( # noqa: F401
check_allowed_values,
@@ -25,9 +20,7 @@ from dynamic_servers.model_utils import ( # noqa: F401
date,
datetime,
file_type,
int,
none_type,
str,
validate_and_convert_types
)

View File

@@ -8,7 +8,6 @@
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import json
import atexit
@@ -16,10 +15,8 @@ import mimetypes
from multiprocessing.pool import ThreadPool
import os
import re
from urllib.parse import quote
# python 2 and python 3 compatibility library
import six
from six.moves.urllib.parse import quote
from dynamic_servers import rest
from dynamic_servers.configuration import Configuration
@@ -34,10 +31,8 @@ from dynamic_servers.model_utils import (
datetime,
deserialize_file,
file_type,
int,
model_to_dict,
none_type,
str,
validate_and_convert_types
)
@@ -64,10 +59,8 @@ class ApiClient(object):
to the API. More threads means more concurrent API requests.
"""
# six.binary_type python2=str, python3=bytes
# six.text_type python2=unicode, python3=str
PRIMITIVE_TYPES = (
(float, bool, six.binary_type, six.text_type) + six.integer_types
float, bool, bytes, str, int
)
_pool = None
@@ -191,7 +184,7 @@ class ApiClient(object):
_preload_content=_preload_content,
_request_timeout=_request_timeout)
except ApiException as e:
e.body = e.body.decode('utf-8') if six.PY3 else e.body
e.body = e.body.decode('utf-8')
raise e
content_type = response_data.getheader('content-type')
@@ -204,7 +197,7 @@ class ApiClient(object):
return (return_data)
return return_data
if six.PY3 and response_type not in ["file", "bytes"]:
if response_type not in ["file", "bytes"]:
match = None
if content_type is not None:
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s\;]?", content_type)
@@ -265,7 +258,7 @@ class ApiClient(object):
return self.sanitize_for_serialization(obj.value)
return {key: self.sanitize_for_serialization(val)
for key, val in six.iteritems(obj_dict)}
for key, val in obj_dict.items()}
def deserialize(self, response, response_type, _check_type):
"""Deserializes response into an object.
@@ -465,7 +458,7 @@ class ApiClient(object):
new_params = []
if collection_formats is None:
collection_formats = {}
for k, v in six.iteritems(params) if isinstance(params, dict) else params: # noqa: E501
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
if k in collection_formats:
collection_format = collection_formats[k]
if collection_format == 'multi':
@@ -496,7 +489,7 @@ class ApiClient(object):
return []
params = []
for param_name, file_instances in six.iteritems(files):
for param_name, file_instances in files.items():
if file_instances is None:
# if the file field is nullable, skip None values
continue
@@ -671,7 +664,7 @@ class Endpoint(object):
if kwargs['_check_input_type'] is False:
return
for key, value in six.iteritems(kwargs):
for key, value in kwargs.items():
fixed_val = validate_and_convert_types(
value,
self.openapi_types[key],
@@ -693,7 +686,7 @@ class Endpoint(object):
'query': []
}
for param_name, param_value in six.iteritems(kwargs):
for param_name, param_value in kwargs.items():
param_location = self.location_map.get(param_name)
if param_location is None:
continue
@@ -751,7 +744,7 @@ class Endpoint(object):
)
_host = None
for key, value in six.iteritems(kwargs):
for key, value in kwargs.items():
if key not in self.params_map['all']:
raise ApiTypeError(
"Got an unexpected parameter '%s'"

View File

@@ -10,16 +10,13 @@
"""
from __future__ import absolute_import
import copy
import logging
import multiprocessing
import sys
import urllib3
import six
from six.moves import http_client as httplib
from http import client as http_client
from dynamic_servers.exceptions import ApiValueError
@@ -268,7 +265,7 @@ class Configuration(object):
# then add file handler and remove stream handler.
self.logger_file_handler = logging.FileHandler(self.__logger_file)
self.logger_file_handler.setFormatter(self.logger_formatter)
for _, logger in six.iteritems(self.logger):
for _, logger in self.logger.items():
logger.addHandler(self.logger_file_handler)
@property
@@ -290,17 +287,17 @@ class Configuration(object):
self.__debug = value
if self.__debug:
# if debug status is True, turn on debug logging
for _, logger in six.iteritems(self.logger):
for _, logger in self.logger.items():
logger.setLevel(logging.DEBUG)
# turn on httplib debug
httplib.HTTPConnection.debuglevel = 1
# turn on http_client debug
http_client.HTTPConnection.debuglevel = 1
else:
# if debug status is False, turn off debug logging,
# setting log level to default `logging.WARNING`
for _, logger in six.iteritems(self.logger):
for _, logger in self.logger.items():
logger.setLevel(logging.WARNING)
# turn off httplib debug
httplib.HTTPConnection.debuglevel = 0
# turn off http_client debug
http_client.HTTPConnection.debuglevel = 0
@property
def logger_format(self):

View File

@@ -10,8 +10,6 @@
"""
import six
class OpenApiException(Exception):
"""The base exception class for all OpenAPIExceptions"""
@@ -132,7 +130,7 @@ def render_path(path_to_item):
"""Returns a string representation of a path"""
result = ""
for pth in path_to_item:
if isinstance(pth, six.integer_types):
if isinstance(pth, int):
result += "[{0}]".format(pth)
else:
result += "['{0}']".format(pth)

View File

@@ -12,13 +12,13 @@
from datetime import date, datetime # noqa: F401
import inspect
import io
import os
import pprint
import re
import tempfile
from dateutil.parser import parse
import six
from dynamic_servers.exceptions import (
ApiKeyError,
@@ -28,20 +28,7 @@ from dynamic_servers.exceptions import (
)
none_type = type(None)
if six.PY3:
import io
file_type = io.IOBase
# these are needed for when other modules import str and int from here
str = str
int = int
else:
file_type = file # noqa: F821
str_py2 = str
unicode_py2 = unicode # noqa: F821
long_py2 = long # noqa: F821
int_py2 = int
# this requires that the future library is installed
from builtins import int, str
file_type = io.IOBase
class cached_property(object):
@@ -344,13 +331,7 @@ class ModelSimple(OpenApiModel):
types.add(this_val.__class__)
types.add(that_val.__class__)
vals_equal = this_val == that_val
if not six.PY3 and len(types) == 2 and unicode in types: # noqa: F821
vals_equal = (
this_val.encode('utf-8') == that_val.encode('utf-8')
)
if not vals_equal:
return False
return True
return vals_equal
class ModelNormal(OpenApiModel):
@@ -398,17 +379,12 @@ class ModelNormal(OpenApiModel):
if not set(self._data_store.keys()) == set(other._data_store.keys()):
return False
for _var_name, this_val in six.iteritems(self._data_store):
for _var_name, this_val in self._data_store.items():
that_val = other._data_store[_var_name]
types = set()
types.add(this_val.__class__)
types.add(that_val.__class__)
vals_equal = this_val == that_val
if (not six.PY3 and
len(types) == 2 and unicode in types): # noqa: F821
vals_equal = (
this_val.encode('utf-8') == that_val.encode('utf-8')
)
if not vals_equal:
return False
return True
@@ -527,17 +503,12 @@ class ModelComposed(OpenApiModel):
if not set(self._data_store.keys()) == set(other._data_store.keys()):
return False
for _var_name, this_val in six.iteritems(self._data_store):
for _var_name, this_val in self._data_store.items():
that_val = other._data_store[_var_name]
types = set()
types.add(this_val.__class__)
types.add(that_val.__class__)
vals_equal = this_val == that_val
if (not six.PY3 and
len(types) == 2 and unicode in types): # noqa: F821
vals_equal = (
this_val.encode('utf-8') == that_val.encode('utf-8')
)
if not vals_equal:
return False
return True
@@ -647,8 +618,6 @@ def get_simple_class(input_value):
# isinstance(True, int) == True
return bool
elif isinstance(input_value, int):
# for python2 input_value==long_instance -> return int
# where int is the python3 int backport
return int
elif isinstance(input_value, datetime):
# this must be higher than the date check because
@@ -656,8 +625,7 @@ def get_simple_class(input_value):
return datetime
elif isinstance(input_value, date):
return date
elif (six.PY2 and isinstance(input_value, (str_py2, unicode_py2, str)) or
isinstance(input_value, str)):
elif isinstance(input_value, str):
return str
return type(input_value)
@@ -1102,12 +1070,12 @@ def deserialize_primitive(data, klass, path_to_item):
return converted_value
except (OverflowError, ValueError) as ex:
# parse can raise OverflowError
six.raise_from(ApiValueError(
raise ApiValueError(
"{0}Failed to parse {1} as {2}".format(
additional_message, repr(data), get_py3_class_name(klass)
additional_message, repr(data), klass.__name__
),
path_to_item=path_to_item
), ex)
) from ex
def get_discriminator_class(model_class,
@@ -1231,8 +1199,8 @@ def deserialize_file(response_data, configuration, content_disposition=None):
path = os.path.join(os.path.dirname(path), filename)
with open(path, "wb") as f:
if six.PY3 and isinstance(response_data, str):
# in python3 change str to bytes so we can write it
if isinstance(response_data, str):
# change str to bytes so we can write it
response_data = response_data.encode('utf-8')
f.write(response_data)
@@ -1451,7 +1419,7 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
if input_value == {}:
# allow an empty dict
return input_value
for inner_key, inner_val in six.iteritems(input_value):
for inner_key, inner_val in input_value.items():
inner_path = list(path_to_item)
inner_path.append(inner_key)
if get_simple_class(inner_key) != str:
@@ -1485,7 +1453,7 @@ def model_to_dict(model_instance, serialize=True):
if model_instance._composed_schemas:
model_instances.extend(model_instance._composed_instances)
for model_instance in model_instances:
for attr, value in six.iteritems(model_instance._data_store):
for attr, value in model_instance._data_store.items():
if serialize:
# we use get here because additional property key names do not
# exist in attribute_map
@@ -1542,13 +1510,8 @@ def type_error_message(var_value=None, var_name=None, valid_classes=None,
def get_valid_classes_phrase(input_classes):
"""Returns a string phrase describing what types are allowed
Note: Adds the extra valid classes in python2
"""
all_classes = list(input_classes)
if six.PY2 and str in input_classes:
all_classes.extend([str_py2, unicode_py2])
if six.PY2 and int in input_classes:
all_classes.extend([int_py2, long_py2])
all_classes = sorted(all_classes, key=lambda cls: cls.__name__)
all_class_names = [cls.__name__ for cls in all_classes]
if len(all_class_names) == 1:
@@ -1556,15 +1519,6 @@ def get_valid_classes_phrase(input_classes):
return "is one of [{0}]".format(", ".join(all_class_names))
def get_py3_class_name(input_class):
if six.PY2:
if input_class == str:
return 'str'
elif input_class == int:
return 'int'
return input_class.__name__
def convert_js_args_to_python_args(fn):
from functools import wraps
@wraps(fn)
@@ -1607,7 +1561,7 @@ def get_allof_instances(self, model_args, constant_args):
allof_instance = allof_class(**kwargs)
composed_instances.append(allof_instance)
except Exception as ex:
six.raise_from(ApiValueError(
raise ApiValueError(
"Invalid inputs given to generate an instance of '%s'. The "
"input data was invalid for the allOf schema '%s' in the composed "
"schema '%s'. Error=%s" % (
@@ -1616,7 +1570,7 @@ def get_allof_instances(self, model_args, constant_args):
self.__class__.__name__,
str(ex)
)
), ex)
) from ex
return composed_instances

View File

@@ -10,18 +10,14 @@
"""
from __future__ import absolute_import
import io
import json
import logging
import re
import ssl
from urllib.parse import urlencode
import certifi
# python 2 and python 3 compatibility library
import six
from six.moves.urllib.parse import urlencode
import urllib3
from dynamic_servers.exceptions import ApiException, ApiValueError
@@ -141,7 +137,7 @@ class RESTClientObject(object):
timeout = None
if _request_timeout:
if isinstance(_request_timeout, (int, ) if six.PY3 else (int, long)): # noqa: E501,F821
if isinstance(_request_timeout, int): # noqa: E501,F821
timeout = urllib3.Timeout(total=_request_timeout)
elif (isinstance(_request_timeout, tuple) and
len(_request_timeout) == 2):

View File

@@ -1,7 +1,5 @@
nulltype
certifi >= 14.05.14
future; python_version<="2.7"
six >= 1.10
python_dateutil >= 2.5.3
setuptools >= 21.0.0
urllib3 >= 1.15.1

View File

@@ -23,12 +23,10 @@ VERSION = "1.0.0"
REQUIRES = [
"urllib3 >= 1.15",
"six >= 1.10",
"certifi",
"python-dateutil",
"nulltype",
]
EXTRAS = {':python_version <= "2.7"': ['future']}
setup(
name=NAME,
@@ -38,8 +36,8 @@ setup(
author_email="team@openapitools.org",
url="",
keywords=["OpenAPI", "OpenAPI-Generator", "OpenAPI Extension with dynamic servers"],
python_requires=">=3.3",
install_requires=REQUIRES,
extras_require=EXTRAS,
packages=find_packages(exclude=["test", "tests"]),
include_package_data=True,
license="Apache-2.0",

View File

@@ -1,4 +1,3 @@
pytest~=4.6.7 # needed for python 2.7+3.4
pytest~=4.6.7 # needed for python 3.4
pytest-cov>=2.8.1
pytest-randomly==1.2.3 # needed for python 2.7+3.4
mock; python_version<="2.7"
pytest-randomly==1.2.3 # needed for python 3.4

View File

@@ -9,8 +9,6 @@
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import functools
import unittest

View File

@@ -1,5 +1,5 @@
[tox]
envlist = py27, py3
envlist = py3
[testenv]
deps=-r{toxinidir}/requirements.txt