Skip to content

Commit 085e1e5

Browse files
Fix/remove support python2 option in flask aiohttp generators (OpenAPITools#13585)
* fix: remove option supportPython2. [python-flask][python-aiohttp][python-blueplanet] * fix: update samples * test only python servers * fix(tests): downgrade pytest version to ensure compatibility with python3.6 [python-flask][python-aiohttp] * Revert "fix(tests): downgrade pytest version to ensure compatibility with python3.6 [python-flask][python-aiohttp]" This reverts commit 9f47db2. * test in circlei * run commands directly * test in node 1 * update makefile * fix Makefile * fix test * revert some changes, remove python server tests from travis Co-authored-by: Kevin Bannier <[email protected]>
1 parent 57f5cc4 commit 085e1e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+83
-185
lines changed

docs/generators/python-aiohttp.md

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3434
|serverPort|TCP port to listen to in app.run| |8080|
3535
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
3636
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
37-
|supportPython2|support python2. This option has been deprecated and will be removed in the 5.x release.| |false|
3837
|testsUsePythonSrcRoot|generates test under the pythonSrcRoot folder.| |false|
3938
|useNose|use the nose test framework| |false|
4039
|usePythonSrcRootInImports|include pythonSrcRoot in import namespaces.| |false|

docs/generators/python-blueplanet.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ title: Documentation for the python-blueplanet Generator
1010
| generator stability | STABLE | |
1111
| generator type | SERVER | |
1212
| generator language | Python | |
13-
| generator language version | 2.7+ and 3.5.2+ | |
13+
| generator language version | 3.5.2+ | |
1414
| generator default templating engine | mustache | |
1515
| helpTxt | Generates a Python server library using the Connexion project. By default, it will also generate service classes -- which you can disable with the `-Dnoservice` environment variable. | |
1616

@@ -34,7 +34,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3434
|serverPort|TCP port to listen to in app.run| |8080|
3535
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
3636
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
37-
|supportPython2|support python2. This option has been deprecated and will be removed in the 5.x release.| |false|
3837
|testsUsePythonSrcRoot|generates test under the pythonSrcRoot folder.| |false|
3938
|useNose|use the nose test framework| |false|
4039
|usePythonSrcRootInImports|include pythonSrcRoot in import namespaces.| |false|

docs/generators/python-flask.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ title: Documentation for the python-flask Generator
1010
| generator stability | STABLE | |
1111
| generator type | SERVER | |
1212
| generator language | Python | |
13-
| generator language version | 2.7 and 3.5.2+ | |
13+
| generator language version | 3.5.2+ | |
1414
| generator default templating engine | mustache | |
1515
| helpTxt | Generates a Python server library using the Connexion project. By default, it will also generate service classes -- which you can disable with the `-Dnoservice` environment variable. | |
1616

@@ -34,7 +34,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3434
|serverPort|TCP port to listen to in app.run| |8080|
3535
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
3636
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
37-
|supportPython2|support python2. This option has been deprecated and will be removed in the 5.x release.| |false|
3837
|testsUsePythonSrcRoot|generates test under the pythonSrcRoot folder.| |false|
3938
|useNose|use the nose test framework| |false|
4039
|usePythonSrcRootInImports|include pythonSrcRoot in import namespaces.| |false|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonConnexionServerCodegen.java

-7
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public void serialize(Boolean value, JsonGenerator gen, SerializerProvider seria
6565

6666
public static final String CONTROLLER_PACKAGE = "controllerPackage";
6767
public static final String DEFAULT_CONTROLLER = "defaultController";
68-
public static final String SUPPORT_PYTHON2 = "supportPython2";
6968
public static final String FEATURE_CORS = "featureCORS";
7069
// nose is a python testing framework, we use pytest if USE_NOSE is unset
7170
public static final String USE_NOSE = "useNose";
@@ -152,8 +151,6 @@ public AbstractPythonConnexionServerCodegen(String templateDirectory, boolean fi
152151
defaultValue("controllers"));
153152
cliOptions.add(new CliOption(DEFAULT_CONTROLLER, "default controller").
154153
defaultValue("default_controller"));
155-
cliOptions.add(new CliOption(SUPPORT_PYTHON2, "support python2. This option has been deprecated and will be removed in the 5.x release.").
156-
defaultValue("false"));
157154
cliOptions.add(new CliOption("serverPort", "TCP port to listen to in app.run").
158155
defaultValue("8080"));
159156
cliOptions.add(CliOption.newBoolean(FEATURE_CORS, "use flask-cors for handling CORS requests").
@@ -200,10 +197,6 @@ public void processOpts() {
200197
this.defaultController = "default_controller";
201198
additionalProperties.put(DEFAULT_CONTROLLER, this.defaultController);
202199
}
203-
if (Boolean.TRUE.equals(additionalProperties.get(SUPPORT_PYTHON2))) {
204-
additionalProperties.put(SUPPORT_PYTHON2, Boolean.TRUE);
205-
typeMapping.put("long", "long");
206-
}
207200
if (additionalProperties.containsKey(FEATURE_CORS)) {
208201
setFeatureCORS(String.valueOf(additionalProperties.get(FEATURE_CORS)));
209202
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonBluePlanetServerCodegen.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ public void processOpts() {
101101
this.defaultController = "default_controller";
102102
additionalProperties.put(DEFAULT_CONTROLLER, this.defaultController);
103103
}
104-
if (Boolean.TRUE.equals(additionalProperties.get(SUPPORT_PYTHON2))) {
105-
additionalProperties.put(SUPPORT_PYTHON2, Boolean.TRUE);
106-
typeMapping.put("long", "long");
107-
}
108104

109105
String APP_PATH = "app" + File.separatorChar;
110106
String APP_PACKAGE_PATH = APP_PATH + packageName;
@@ -266,5 +262,5 @@ public String apiFileFolder() {
266262
}
267263

268264
@Override
269-
public String generatorLanguageVersion() { return "2.7+ and 3.5.2+"; };
265+
public String generatorLanguageVersion() { return "3.5.2+"; };
270266
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFlaskConnexionServerCodegen.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ protected void addSupportingFiles() {
5656
}
5757

5858
@Override
59-
public String generatorLanguageVersion() { return "2.7 and 3.5.2+"; };
59+
public String generatorLanguageVersion() { return "3.5.2+"; };
6060
}

modules/openapi-generator/src/main/resources/python-aiohttp/requirements.mustache

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ connexion[aiohttp,swagger-ui] <= 2.3.0; python_version=="3.5" or python_version=
55
# we must peg werkzeug versions below to fix connexion
66
# https://github.com/zalando/connexion/pull/1044
77
werkzeug == 0.16.1; python_version=="3.5" or python_version=="3.4"
8-
swagger-ui-bundle == 0.0.6
9-
aiohttp_jinja2 == 1.2.0
8+
swagger-ui-bundle == 0.0.9
9+
aiohttp_jinja2 == 1.5.0
1010
{{#featureCORS}}
1111
aiohttp_cors >= 0.7.0
1212
{{/featureCORS}}

modules/openapi-generator/src/main/resources/python-aiohttp/setup.mustache

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ VERSION = "{{packageVersion}}"
1414
# http://pypi.python.org/pypi/setuptools
1515

1616
REQUIRES = [
17-
"connexion==2.6.0",
18-
"swagger-ui-bundle==0.0.6",
19-
"aiohttp_jinja2==1.2.0",
17+
"connexion==2.14.1",
18+
"swagger-ui-bundle==0.0.9",
19+
"aiohttp_jinja2==1.5.0",
2020
]
2121

2222
setup(

modules/openapi-generator/src/main/resources/python-aiohttp/test-requirements.mustache

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ py>=1.4.31
66
randomize>=0.13
77
{{/useNose}}
88
{{^useNose}}
9-
pytest~=4.6.7 # needed for python 2.7+3.4
9+
pytest~=7.1.0
1010
pytest-cov>=2.8.1
11-
pytest-randomly==1.2.3 # needed for python 2.7+3.4
11+
pytest-randomly>=1.2.3
1212
pytest-aiohttp>=0.3.0
1313
{{/useNose}}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
{{#supportPython2}}
2-
FROM python:2-alpine
3-
{{/supportPython2}}
4-
{{^supportPython2}}
51
FROM python:3-alpine
6-
{{/supportPython2}}
72

83
ARG GLTOKEN
94

@@ -19,12 +14,7 @@ WORKDIR /bp2/src
1914

2015
COPY requirements.txt /bp2/src
2116

22-
{{#supportPython2}}
23-
RUN pip install --extra-index-url https://GLTOKEN:[email protected]/simple --no-cache-dir -r requirements.txt
24-
{{/supportPython2}}
25-
{{^supportPython2}}
2617
RUN pip3 install --extra-index-url https://GLTOKEN:[email protected]/simple --no-cache-dir -r requirements.txt
27-
{{/supportPython2}}
2818

2919
COPY . /bp2/src
3020

@@ -33,11 +23,6 @@ ENV SBIS=bpocore \
3323

3424
EXPOSE {{serverPort}}
3525

36-
{{#supportPython2}}
37-
ENTRYPOINT ["python"]
38-
{{/supportPython2}}
39-
{{^supportPython2}}
4026
ENTRYPOINT ["python3"]
41-
{{/supportPython2}}
4227

4328
CMD ["-B", "-m", "{{packageName}}"]

modules/openapi-generator/src/main/resources/python-blueplanet/app/README.mustache

-11
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,14 @@ is an example of building a swagger-enabled Flask server.
88
This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask.
99

1010
## Requirements
11-
{{#supportPython2}}
12-
Python 2.7+
13-
{{/supportPython2}}
14-
{{^supportPython2}}
1511
Python 3.5.2+
16-
{{/supportPython2}}
1712

1813
## Usage
1914
To run the server, please execute the following from the root directory:
2015

2116
```
22-
{{#supportPython2}}
23-
pip install -r requirements.txt
24-
python -m {{packageName}}
25-
{{/supportPython2}}
26-
{{^supportPython2}}
2717
pip3 install -r requirements.txt
2818
python3 -m {{packageName}}
29-
{{/supportPython2}}
3019
```
3120

3221
and open your browser to here:

modules/openapi-generator/src/main/resources/python-blueplanet/app/requirements.mustache

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
connexion == 1.1.15
22
python_dateutil == 2.6.0
3-
{{#supportPython2}}
4-
typing == 3.5.2.2
5-
{{/supportPython2}}
63
setuptools >= 21.0.0
74
bp2hookutil==3.3.0
85
plansdk

modules/openapi-generator/src/main/resources/python-blueplanet/app/tox.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = {{#supportPython2}}py27, {{/supportPython2}}py35
2+
envlist = py35
33

44
[testenv]
55
deps=-r{toxinidir}/requirements.txt

modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/__main__.mustache

-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
{{#supportPython2}}
2-
#!/usr/bin/env python
3-
{{/supportPython2}}
4-
{{^supportPython2}}
51
#!/usr/bin/env python3
6-
{{/supportPython2}}
72

83
import connexion
94
{{#featureCORS}}

modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/models/base_model_.mustache

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import pprint
22

33
import six
4-
{{^supportPython2}}
54
import typing
6-
{{/supportPython2}}
75

86
from {{packageName}} import util
9-
{{^supportPython2}}
107

118
T = typing.TypeVar('T')
12-
{{/supportPython2}}
139

1410

1511
class Model(object):
@@ -22,7 +18,7 @@ class Model(object):
2218
attribute_map = {}
2319

2420
@classmethod
25-
def from_dict(cls{{^supportPython2}}: typing.Type[T]{{/supportPython2}}, dikt){{^supportPython2}} -> T{{/supportPython2}}:
21+
def from_dict(cls: typing.Type[T], dikt) -> T:
2622
"""Returns the dict as a model"""
2723
return util.deserialize_model(dikt, cls)
2824

modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/models/model.mustache

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class {{classname}}(Model):
2727
{{/-last}}
2828
{{/enumVars}}{{/allowableValues}}
2929

30-
def __init__(self{{#vars}}, {{name}}{{^supportPython2}}: {{datatype}}{{/supportPython2}}={{{defaultValue}}}{{^defaultValue}}None{{/defaultValue}}{{/vars}}): # noqa: E501
30+
def __init__(self{{#vars}}, {{name}}: {{datatype}}={{{defaultValue}}}{{^defaultValue}}None{{/defaultValue}}{{/vars}}): # noqa: E501
3131
"""{{classname}} - a model defined in Swagger
3232

3333
{{#vars}}
@@ -52,7 +52,7 @@ class {{classname}}(Model):
5252
{{/vars}}
5353

5454
@classmethod
55-
def from_dict(cls, dikt){{^supportPython2}} -> '{{classname}}'{{/supportPython2}}:
55+
def from_dict(cls, dikt) -> '{{classname}}':
5656
"""Returns the dict as a model
5757

5858
:param dikt: A dict.
@@ -64,7 +64,7 @@ class {{classname}}(Model):
6464

6565
{{/-first}}
6666
@property
67-
def {{name}}(self){{^supportPython2}} -> {{datatype}}{{/supportPython2}}:
67+
def {{name}}(self) -> {{datatype}}:
6868
"""Gets the {{name}} of this {{classname}}.
6969

7070
{{#description}}
@@ -77,7 +77,7 @@ class {{classname}}(Model):
7777
return self._{{name}}
7878

7979
@{{name}}.setter
80-
def {{name}}(self, {{name}}{{^supportPython2}}: {{datatype}}{{/supportPython2}}):
80+
def {{name}}(self, {{name}}: {{datatype}}):
8181
"""Sets the {{name}} of this {{classname}}.
8282

8383
{{#description}}
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
1-
{{#supportPython2}}
2-
FROM python:2-alpine
3-
{{/supportPython2}}
4-
{{^supportPython2}}
51
FROM python:3-alpine
6-
{{/supportPython2}}
72

83
RUN mkdir -p /usr/src/app
94
WORKDIR /usr/src/app
105

116
COPY requirements.txt /usr/src/app/
127

13-
{{#supportPython2}}
14-
RUN pip install --no-cache-dir -r requirements.txt
15-
{{/supportPython2}}
16-
{{^supportPython2}}
178
RUN pip3 install --no-cache-dir -r requirements.txt
18-
{{/supportPython2}}
199

2010
COPY . /usr/src/app
2111

2212
EXPOSE {{serverPort}}
2313

24-
{{#supportPython2}}
25-
ENTRYPOINT ["python"]
26-
{{/supportPython2}}
27-
{{^supportPython2}}
2814
ENTRYPOINT ["python3"]
29-
{{/supportPython2}}
3015

3116
CMD ["-m", "{{packageName}}"]

modules/openapi-generator/src/main/resources/python-flask/README.mustache

-11
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,14 @@ is an example of building a OpenAPI-enabled Flask server.
88
This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask.
99

1010
## Requirements
11-
{{#supportPython2}}
12-
Python 2.7+
13-
{{/supportPython2}}
14-
{{^supportPython2}}
1511
Python 3.5.2+
16-
{{/supportPython2}}
1712

1813
## Usage
1914
To run the server, please execute the following from the root directory:
2015

2116
```
22-
{{#supportPython2}}
23-
pip install -r requirements.txt
24-
python -m {{packageName}}
25-
{{/supportPython2}}
26-
{{^supportPython2}}
2717
pip3 install -r requirements.txt
2818
python3 -m {{packageName}}
29-
{{/supportPython2}}
3019
```
3120

3221
and open your browser to here:

modules/openapi-generator/src/main/resources/python-flask/__main__.mustache

-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
{{#supportPython2}}
2-
#!/usr/bin/env python
3-
{{/supportPython2}}
4-
{{^supportPython2}}
51
#!/usr/bin/env python3
6-
{{/supportPython2}}
72

83
import connexion
94
{{#featureCORS}}

modules/openapi-generator/src/main/resources/python-flask/base_model_.mustache

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
import pprint
22

33
import six
4-
{{^supportPython2}}
54
import typing
6-
{{/supportPython2}}
75

86
from {{packageName}} import util
9-
{{^supportPython2}}
107

118
T = typing.TypeVar('T')
12-
{{/supportPython2}}
139

1410

15-
class Model({{#supportPython2}}object{{/supportPython2}}):
11+
class Model(object):
1612
# openapiTypes: The key is attribute name and the
1713
# value is attribute type.
18-
openapi_types{{^supportPython2}}: typing.Dict[str, type]{{/supportPython2}} = {}
14+
openapi_types: typing.Dict[str, type] = {}
1915

2016
# attributeMap: The key is attribute name and the
2117
# value is json key in definition.
22-
attribute_map{{^supportPython2}}: typing.Dict[str, str]{{/supportPython2}} = {}
18+
attribute_map: typing.Dict[str, str] = {}
2319

2420
@classmethod
25-
def from_dict(cls{{^supportPython2}}: typing.Type[T]{{/supportPython2}}, dikt){{^supportPython2}} -> T{{/supportPython2}}:
21+
def from_dict(cls: typing.Type[T], dikt) -> T:
2622
"""Returns the dict as a model"""
2723
return util.deserialize_model(dikt, cls)
2824

modules/openapi-generator/src/main/resources/python-flask/model.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class {{classname}}(Model):
6262
{{/vars}}
6363

6464
@classmethod
65-
def from_dict(cls, dikt){{^supportPython2}} -> '{{classname}}'{{/supportPython2}}:
65+
def from_dict(cls, dikt) -> '{{classname}}':
6666
"""Returns the dict as a model
6767

6868
:param dikt: A dict.

0 commit comments

Comments
 (0)