Skip to content

Commit c286ac9

Browse files
author
miggyst
authored
chore: Ran gen-setuppy to update openapi setup.py BNCH-42828 (#127)
* chore: Ran gen-setuppy to update openapi setup.py BNCH-42828 * Updated readme * Added note on package version * Added a sed statement to update package name on build
1 parent 50ee795 commit c286ac9

File tree

10 files changed

+82
-40
lines changed

10 files changed

+82
-40
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,17 @@ Example:
146146
package_version_override: 1.2.3
147147
```
148148

149+
## How to publish changes
150+
Quip doc that highlights how to pull the dependency to Aurelia and publish using a buildkite pipeline can be found [here](https://benchling.quip.com/PgytA283Rlyo/2022-02-16-Guide-for-Publishing-a-Package)
151+
152+
After changes are made to this package, to publish a new version of this package:
153+
* Bump the version on pyproject.toml
154+
* Install `gnu-sed` (assuming that you're running on a mac) by running `brew install gnu-sed`
155+
* macOS uses BSD sed, which is similar to Linux's GNU sed but cannot explicitly edit files in place i.e. cannot utilize `-i` tag
156+
* Set GNU sed PATH by running `brew info gnu-sed` to check for PATH
157+
* Run `poetry run task gen-setuppy` which updates setup.py
158+
* Kick off a buildkite pipeline build as highlighted in the quip doc (would need to designate the branch of which to check for publish)
159+
160+
149161
[changelog.md]: CHANGELOG.md
150162
[poetry]: https://python-poetry.org/

openapi_python_client/parser/openapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Endpoint:
102102

103103
@staticmethod
104104
def parse_request_yaml_body(
105-
*, body: oai.RequestBody, schemas: Schemas, parent_name: str
105+
*, body: oai.RequestBody, schemas: Schemas, parent_name: str
106106
) -> Tuple[Union[Property, PropertyError, None], Schemas]:
107107
""" Return yaml_body """
108108
body_content = body.content

openapi_python_client/parser/properties/__init__.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def build_union_property(
443443
sub_properties.append(sub_prop)
444444
if data.discriminator is not None:
445445
reference_name_to_subprop[sub_prop.reference.class_name] = sub_prop
446-
446+
447447
discriminator_mappings: Dict[str, Property] = {}
448448
if data.discriminator is not None:
449449
for k, v in (data.discriminator.mapping if data.discriminator else {}).items():
@@ -571,13 +571,10 @@ def _property_from_data(
571571
elif data.type == "object" or data.allOf:
572572
return build_model_property(data=data, name=name, schemas=schemas, required=required, parent_name=parent_name)
573573
elif not data.type:
574-
return NoneProperty(
575-
name=name,
576-
required=required,
577-
nullable=False,
578-
default=None,
579-
description=data.description
580-
), schemas
574+
return (
575+
NoneProperty(name=name, required=required, nullable=False, default=None, description=data.description),
576+
schemas,
577+
)
581578
return PropertyError(data=data, detail=f"unknown type {data.type}"), schemas
582579

583580

openapi_python_client/parser/responses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Response:
2222
"application/json": "response.json()",
2323
"application/octet-stream": "response.content",
2424
"text/html": "response.text",
25-
"text/yaml": "response.yaml", # Only used as an identifier, not the actual source
25+
"text/yaml": "response.yaml", # Only used as an identifier, not the actual source
2626
}
2727

2828

openapi_python_client/templates/endpoint_module.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Any, Dict, List, Optional, Union, cast
22

33
import httpx
4-
from attr import asdict
54
import yaml
5+
from attr import asdict
66

77
from ...client import AuthenticatedClient, Client
88
from ...types import Response

pyproject.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[tool.poetry]
22
name = "openapi-python-client"
3-
version = "0.7.3"
3+
# Our versions have diverged and have no relation to upstream code changes
4+
# Henceforth, openapi-python-package will be maintained internally
5+
version = "1.0.0"
46
description = "Generate modern Python clients from OpenAPI"
57
repository = "https://github.com/triaxtec/openapi-python-client"
68
license = "MIT"
@@ -71,7 +73,8 @@ gen-setuppy = """
7173
poetry build \
7274
&& tar --strip-components=1 -xvf "$(ls -1 dist/*tar.gz | tail -1)" '*/setup.py' \
7375
&& isort setup.py \
74-
&& black setup.py
76+
&& black setup.py \
77+
&& sed -i 's/"openapi-python-client"/"benchling-openapi-python-client"/' setup.py
7578
"""
7679

7780
[tool.black]

setup.py

+8-8
Large diffs are not rendered by default.

tests/test_parser/test_openapi.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ def test_from_dict_invalid_schema(self, mocker):
6868
class TestEndpoint:
6969
def test_parse_yaml_body(self, mocker):
7070
from openapi_python_client.parser.openapi import Endpoint, Schemas
71+
7172
schema = mocker.MagicMock()
72-
body = oai.RequestBody.construct(
73-
content={"text/yaml": oai.MediaType.construct(media_type_schema=schema)}
74-
)
73+
body = oai.RequestBody.construct(content={"text/yaml": oai.MediaType.construct(media_type_schema=schema)})
7574
property_from_data = mocker.patch(f"{MODULE_NAME}.property_from_data")
7675
schemas = Schemas()
7776

tests/test_parser/test_properties/test_init.py

+46-15
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,29 @@ def test_get_type_string(self, mocker):
201201
inner_property = mocker.MagicMock()
202202
inner_type_string = mocker.MagicMock()
203203
inner_property.get_type_string.return_value = inner_type_string
204-
p = ListProperty(name="test", required=True, default=None, inner_property=inner_property, nullable=False, description=None)
204+
p = ListProperty(
205+
name="test", required=True, default=None, inner_property=inner_property, nullable=False, description=None
206+
)
205207

206208
base_type_string = f"List[{inner_type_string}]"
207209

208210
assert p.get_type_string() == base_type_string
209211

210-
p = ListProperty(name="test", required=True, default=None, inner_property=inner_property, nullable=True, description=None)
212+
p = ListProperty(
213+
name="test", required=True, default=None, inner_property=inner_property, nullable=True, description=None
214+
)
211215
assert p.get_type_string() == f"Optional[{base_type_string}]"
212216
assert p.get_type_string(no_optional=True) == base_type_string
213217

214-
p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=True, description=None)
218+
p = ListProperty(
219+
name="test", required=False, default=None, inner_property=inner_property, nullable=True, description=None
220+
)
215221
assert p.get_type_string() == f"Union[Unset, None, {base_type_string}]"
216222
assert p.get_type_string(no_optional=True) == base_type_string
217223

218-
p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=False, description=None)
224+
p = ListProperty(
225+
name="test", required=False, default=None, inner_property=inner_property, nullable=False, description=None
226+
)
219227
assert p.get_type_string() == f"Union[Unset, {base_type_string}]"
220228
assert p.get_type_string(no_optional=True) == base_type_string
221229

@@ -226,22 +234,28 @@ def test_get_type_imports(self, mocker):
226234
inner_import = mocker.MagicMock()
227235
inner_property.get_imports.return_value = {inner_import}
228236
prefix = "..."
229-
p = ListProperty(name="test", required=True, default=None, inner_property=inner_property, nullable=False, description=None)
237+
p = ListProperty(
238+
name="test", required=True, default=None, inner_property=inner_property, nullable=False, description=None
239+
)
230240

231241
assert p.get_imports(prefix=prefix) == {
232242
inner_import,
233243
"from typing import cast, List",
234244
}
235245

236-
p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=False, description=None)
246+
p = ListProperty(
247+
name="test", required=False, default=None, inner_property=inner_property, nullable=False, description=None
248+
)
237249
assert p.get_imports(prefix=prefix) == {
238250
inner_import,
239251
"from typing import cast, List",
240252
"from typing import Union",
241253
"from ...types import UNSET, Unset",
242254
}
243255

244-
p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=True, description=None)
256+
p = ListProperty(
257+
name="test", required=False, default=None, inner_property=inner_property, nullable=True, description=None
258+
)
245259
assert p.get_imports(prefix=prefix) == {
246260
inner_import,
247261
"from typing import cast, List",
@@ -690,15 +704,19 @@ def test_property_from_data_simple_types(self, openapi_type, prop_type, python_t
690704
name=name, required=required, data=data, schemas=schemas, parent_name="parent"
691705
)
692706

693-
assert p == prop_type(name=name, required=required, default=python_type(data.default), nullable=False, description=None)
707+
assert p == prop_type(
708+
name=name, required=required, default=python_type(data.default), nullable=False, description=None
709+
)
694710
assert new_schemas == schemas
695711

696712
# Test nullable values
697713
data.default = 0
698714
data.nullable = True
699715

700716
p, _ = property_from_data(name=name, required=required, data=data, schemas=schemas, parent_name="parent")
701-
assert p == prop_type(name=name, required=required, default=python_type(data.default), nullable=True, description=None)
717+
assert p == prop_type(
718+
name=name, required=required, default=python_type(data.default), nullable=True, description=None
719+
)
702720

703721
# Test bad default value
704722
data.default = "a"
@@ -900,7 +918,9 @@ def test_property_from_data_union(self, mocker):
900918

901919
p, s = property_from_data(name=name, required=required, data=data, schemas=Schemas(), parent_name="parent")
902920

903-
FloatProperty.assert_called_once_with(name=name, required=required, default=0.0, nullable=False, description=None)
921+
FloatProperty.assert_called_once_with(
922+
name=name, required=required, default=0.0, nullable=False, description=None
923+
)
904924
IntProperty.assert_called_once_with(name=name, required=required, default=0, nullable=False, description=None)
905925
UnionProperty.assert_called_once_with(
906926
name=name,
@@ -940,7 +960,9 @@ def test__string_based_property_no_format(self):
940960

941961
p = _string_based_property(name=name, required=required, data=data)
942962

943-
assert p == StringProperty(name=name, required=required, nullable=True, default="'\\\\\"hello world\\\\\"'", description=None)
963+
assert p == StringProperty(
964+
name=name, required=required, nullable=True, default="'\\\\\"hello world\\\\\"'", description=None
965+
)
944966

945967
data.pattern = "abcdef"
946968
data.nullable = False
@@ -951,7 +973,12 @@ def test__string_based_property_no_format(self):
951973
data=data,
952974
)
953975
assert p == StringProperty(
954-
name=name, required=required, nullable=False, default="'\\\\\"hello world\\\\\"'", pattern="abcdef", description=None
976+
name=name,
977+
required=required,
978+
nullable=False,
979+
default="'\\\\\"hello world\\\\\"'",
980+
pattern="abcdef",
981+
description=None,
955982
)
956983

957984
def test__string_based_property_datetime_format(self):
@@ -983,7 +1010,9 @@ def test__string_based_property_date_format(self):
9831010

9841011
p = _string_based_property(name=name, required=required, data=data)
9851012

986-
assert p == DateProperty(name=name, required=required, nullable=True, default="isoparse('2020-11-06').date()", description=None)
1013+
assert p == DateProperty(
1014+
name=name, required=required, nullable=True, default="isoparse('2020-11-06').date()", description=None
1015+
)
9871016

9881017
# Test bad default
9891018
data.default = "a"
@@ -1088,7 +1117,7 @@ def test_build_enums(mocker):
10881117
(False, False),
10891118
(
10901119
oai.Schema.construct(type="string"),
1091-
StringProperty(name="AdditionalProperty", required=True, nullable=False, default=None,description=None),
1120+
StringProperty(name="AdditionalProperty", required=True, nullable=False, default=None, description=None),
10921121
),
10931122
],
10941123
)
@@ -1129,7 +1158,9 @@ def test_build_model_property(additional_properties_schema, expected_additional_
11291158
reference=Reference(class_name="ParentMyModel", module_name="parent_my_model"),
11301159
references=[],
11311160
required_properties=[StringProperty(name="req", required=True, nullable=False, default=None, description=None)],
1132-
optional_properties=[DateTimeProperty(name="opt", required=False, nullable=False, default=None, description=None)],
1161+
optional_properties=[
1162+
DateTimeProperty(name="opt", required=False, nullable=False, default=None, description=None)
1163+
],
11331164
description=data.description,
11341165
relative_imports={
11351166
"from dateutil.parser import isoparse",

tests/test_templates/endpoint_module.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Any, Dict, List, Optional, Union, cast
22

33
import httpx
4-
from attr import asdict
54
import yaml
5+
from attr import asdict
66

77
from ...client import AuthenticatedClient, Client
88
from ...types import Response

0 commit comments

Comments
 (0)