Skip to content

Commit 347cf10

Browse files
committed
Add support & testing for Python 3.7
1 parent 90e046e commit 347cf10

File tree

10 files changed

+132
-71
lines changed

10 files changed

+132
-71
lines changed

.circleci/config.yml

+47-35
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,53 @@ orbs:
33
codecov: codecov/[email protected]
44

55
jobs:
6-
build:
6+
test:
7+
working_directory: ~/repo
8+
parameters:
9+
python-version:
10+
type: string
711
docker:
8-
- image: circleci/python:3.8.2
12+
- image: cimg/python:<< parameters.python-version >>
913
steps:
10-
- checkout
11-
- restore_cache:
12-
keys:
13-
- v1-dependencies-{{ checksum "poetry.lock" }}
14-
- run:
15-
name: Install Dependencies
16-
command: |
17-
pip install poetry --user --upgrade
18-
poetry config virtualenvs.in-project true
19-
poetry install
14+
- checkout
15+
- restore_cache:
16+
keys:
17+
- venv-<< parameters.python-version >>-{{ checksum "poetry.lock" }}
18+
- run:
19+
name: Install Dependencies
20+
command: |
21+
pip install poetry --user --upgrade
22+
poetry config virtualenvs.in-project true
23+
poetry install
2024
21-
- run:
22-
name: Run Tests
23-
command: |
24-
mkdir -p test-reports/safety test-reports/mypy test-reports/pytest
25-
poetry run black . --check
26-
poetry run isort
27-
poetry run safety check --json > test-reports/safety/results.json
28-
poetry run mypy openapi_python_client --junit-xml=test-reports/mypy/results.xml
29-
poetry run pytest --junitxml=test-reports/pytest/results.xml --cov=openapi_python_client tests
30-
poetry run pytest end_to_end_tests
31-
poetry run coverage xml
32-
- store_test_results:
33-
path: test-reports
34-
- codecov/upload:
35-
file: coverage.xml
36-
- run:
37-
command: poetry run pip uninstall openapi-python-client -y
38-
name: Uninstall Package
39-
- save_cache:
40-
key: v1-dependencies-{{ checksum "poetry.lock" }}
41-
paths:
42-
- ./.venv
43-
working_directory: ~/repo
25+
- run:
26+
name: Run Tests
27+
command: |
28+
mkdir -p test-reports/safety test-reports/mypy test-reports/pytest
29+
poetry run black . --check
30+
poetry run isort
31+
poetry run safety check --json > test-reports/safety/results.json
32+
poetry run mypy openapi_python_client --junit-xml=test-reports/mypy/results.xml
33+
poetry run pytest --junitxml=test-reports/pytest/results.xml --cov=openapi_python_client tests
34+
poetry run pytest end_to_end_tests
35+
poetry run coverage xml
36+
- store_test_results:
37+
path: test-reports
38+
- codecov/upload:
39+
file: coverage.xml
40+
- run:
41+
command: poetry run pip uninstall openapi-python-client -y
42+
name: Uninstall Package
43+
- save_cache:
44+
key: venv-<< parameters.python-version >>-{{ checksum "poetry.lock" }}
45+
paths:
46+
- ./.venv
47+
48+
49+
workflows:
50+
tests:
51+
jobs:
52+
- test:
53+
matrix:
54+
parameters:
55+
python-version: ["3.7", "3.8"]

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77

8+
## 0.4.1 - 2020-06-02
9+
### Additions
10+
- Support for Python 3.7 (#58)
11+
12+
813
## 0.4.0 - 2020-05-30
914
### Breaking Changes
1015
- Classes generated to be included within lists will now be named like <ListName>Item. For example, if a property

end_to_end_tests/test_end_to_end.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from openapi_python_client.cli import app
99

1010

11-
def _compare_directories(first: Path, second: Path, /):
11+
def _compare_directories(first: Path, second: Path):
1212
first_printable = first.relative_to(Path.cwd())
1313
second_printable = second.relative_to(Path.cwd())
1414
dc = dircmp(first, second)

mypy.ini

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
disallow_any_generics = True
33
disallow_untyped_defs = True
44
warn_redundant_casts = True
5-
warn_unused_ignores = True
65
strict_equality = True
76

87
[mypy-stringcase]

openapi_python_client/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
import shutil
66
import subprocess
7-
from importlib.metadata import version
7+
import sys
88
from pathlib import Path
99
from typing import Any, Dict, Optional
1010

@@ -17,6 +17,12 @@
1717
from .openapi_parser import OpenAPI, import_string_from_reference
1818
from .openapi_parser.errors import MultipleParseError
1919

20+
if sys.version_info.minor == 7: # version did not exist in 3.7, need to use a backport
21+
from importlib_metadata import version # type: ignore
22+
else:
23+
from importlib.metadata import version # type: ignore
24+
25+
2026
__version__ = version(__package__)
2127

2228

openapi_python_client/openapi_parser/openapi.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class EndpointCollection:
3232
parse_errors: List[ParseError] = field(default_factory=list)
3333

3434
@staticmethod
35-
def from_dict(d: Dict[str, Dict[str, Dict[str, Any]]], /) -> Dict[str, EndpointCollection]:
35+
def from_dict(d: Dict[str, Dict[str, Dict[str, Any]]]) -> Dict[str, EndpointCollection]:
3636
""" Parse the openapi paths data to get EndpointCollections by tag """
3737
endpoints_by_tag: Dict[str, EndpointCollection] = {}
3838

@@ -72,7 +72,7 @@ class Endpoint:
7272
multipart_body_reference: Optional[Reference] = None
7373

7474
@staticmethod
75-
def parse_request_form_body(body: Dict[str, Any], /) -> Optional[Reference]:
75+
def parse_request_form_body(body: Dict[str, Any]) -> Optional[Reference]:
7676
""" Return form_body_reference """
7777
body_content = body["content"]
7878
form_body = body_content.get("application/x-www-form-urlencoded")
@@ -81,7 +81,7 @@ def parse_request_form_body(body: Dict[str, Any], /) -> Optional[Reference]:
8181
return None
8282

8383
@staticmethod
84-
def parse_multipart_body(body: Dict[str, Any], /) -> Optional[Reference]:
84+
def parse_multipart_body(body: Dict[str, Any]) -> Optional[Reference]:
8585
""" Return form_body_reference """
8686
body_content = body["content"]
8787
body = body_content.get("multipart/form-data")
@@ -90,7 +90,7 @@ def parse_multipart_body(body: Dict[str, Any], /) -> Optional[Reference]:
9090
return None
9191

9292
@staticmethod
93-
def parse_request_json_body(body: Dict[str, Any], /) -> Optional[Property]:
93+
def parse_request_json_body(body: Dict[str, Any]) -> Optional[Property]:
9494
""" Return json_body """
9595
body_content = body["content"]
9696
json_body = body_content.get("application/json")
@@ -169,7 +169,7 @@ class Schema:
169169
relative_imports: Set[str]
170170

171171
@staticmethod
172-
def from_dict(d: Dict[str, Any], /, name: str) -> Schema:
172+
def from_dict(d: Dict[str, Any], name: str) -> Schema:
173173
""" A single Schema from its dict representation
174174
:param d: Dict representation of the schema
175175
:param name: Name by which the schema is referenced, such as a model name. Used to infer the type name if a `title` property is not available.
@@ -200,7 +200,7 @@ def from_dict(d: Dict[str, Any], /, name: str) -> Schema:
200200
return schema
201201

202202
@staticmethod
203-
def dict(d: Dict[str, Dict[str, Any]], /) -> Dict[str, Schema]:
203+
def dict(d: Dict[str, Dict[str, Any]]) -> Dict[str, Schema]:
204204
""" Get a list of Schemas from an OpenAPI dict """
205205
result = {}
206206
for name, data in d.items():
@@ -221,7 +221,7 @@ class OpenAPI:
221221
enums: Dict[str, EnumProperty]
222222

223223
@staticmethod
224-
def from_dict(d: Dict[str, Dict[str, Any]], /) -> OpenAPI:
224+
def from_dict(d: Dict[str, Dict[str, Any]]) -> OpenAPI:
225225
""" Create an OpenAPI from dict """
226226
schemas = Schema.dict(d["components"]["schemas"])
227227
endpoint_collections_by_tag = EndpointCollection.from_dict(d["paths"])

openapi_python_client/openapi_parser/properties.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def get_imports(self, *, prefix: str) -> Set[str]:
286286
return imports
287287

288288
@staticmethod
289-
def values_from_list(l: List[str], /) -> Dict[str, str]:
289+
def values_from_list(l: List[str]) -> Dict[str, str]:
290290
""" Convert a list of values into dict of {name: value} """
291291
output: Dict[str, str] = {}
292292

openapi_python_client/openapi_parser/responses.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from dataclasses import InitVar, dataclass, field
2-
from typing import Any, Dict, Literal, TypedDict, Union
2+
from typing import Any, Dict
33

44
from .errors import ParseError
55
from .reference import Reference
66

7-
ContentType = Union[Literal["application/json"], Literal["text/html"]]
8-
97

108
@dataclass
119
class Response:
@@ -79,18 +77,12 @@ def constructor(self) -> str:
7977
}
8078

8179

82-
class _ResponseDict(TypedDict):
83-
description: str
84-
content: Dict[ContentType, Any]
85-
86-
87-
def response_from_dict(*, status_code: int, data: _ResponseDict) -> Response:
80+
def response_from_dict(*, status_code: int, data: Dict[str, Any]) -> Response:
8881
""" Generate a Response from the OpenAPI dictionary representation of it """
8982
if "content" not in data:
9083
raise ParseError(data)
9184

9285
content = data["content"]
93-
content_type: ContentType
9486
if "application/json" in content:
9587
content_type = "application/json"
9688
elif "text/html" in content:

poetry.lock

+58-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)