Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Ran gen-setuppy to update openapi setup.py BNCH-42828 #127

Merged
merged 4 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,17 @@ Example:
package_version_override: 1.2.3
```

## How to publish changes
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)

After changes are made to this package, to publish a new version of this package:
* Bump the version on pyproject.toml
* Install `gnu-sed` (assuming that you're running on a mac) by running `brew install gnu-sed`
* 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
* Set GNU sed PATH by running `brew info gnu-sed` to check for PATH
* Run `poetry run task gen-setuppy` which updates setup.py
* Kick off a buildkite pipeline build as highlighted in the quip doc (would need to designate the branch of which to check for publish)


[changelog.md]: CHANGELOG.md
[poetry]: https://python-poetry.org/
2 changes: 1 addition & 1 deletion openapi_python_client/parser/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Endpoint:

@staticmethod
def parse_request_yaml_body(
*, body: oai.RequestBody, schemas: Schemas, parent_name: str
*, body: oai.RequestBody, schemas: Schemas, parent_name: str
) -> Tuple[Union[Property, PropertyError, None], Schemas]:
""" Return yaml_body """
body_content = body.content
Expand Down
13 changes: 5 additions & 8 deletions openapi_python_client/parser/properties/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def build_union_property(
sub_properties.append(sub_prop)
if data.discriminator is not None:
reference_name_to_subprop[sub_prop.reference.class_name] = sub_prop

discriminator_mappings: Dict[str, Property] = {}
if data.discriminator is not None:
for k, v in (data.discriminator.mapping if data.discriminator else {}).items():
Expand Down Expand Up @@ -571,13 +571,10 @@ def _property_from_data(
elif data.type == "object" or data.allOf:
return build_model_property(data=data, name=name, schemas=schemas, required=required, parent_name=parent_name)
elif not data.type:
return NoneProperty(
name=name,
required=required,
nullable=False,
default=None,
description=data.description
), schemas
return (
NoneProperty(name=name, required=required, nullable=False, default=None, description=data.description),
schemas,
)
return PropertyError(data=data, detail=f"unknown type {data.type}"), schemas


Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/parser/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Response:
"application/json": "response.json()",
"application/octet-stream": "response.content",
"text/html": "response.text",
"text/yaml": "response.yaml", # Only used as an identifier, not the actual source
"text/yaml": "response.yaml", # Only used as an identifier, not the actual source
}


Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/templates/endpoint_module.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, List, Optional, Union, cast

import httpx
from attr import asdict
import yaml
from attr import asdict

from ...client import AuthenticatedClient, Client
from ...types import Response
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[tool.poetry]
name = "openapi-python-client"
version = "0.7.3"
# Our versions have diverged and have no relation to upstream code changes
# Henceforth, openapi-python-package will be maintained internally
version = "1.0.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a comment that our versions have diverged and are maintained internally with no relation to the upstream.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a small note in regards to version divergence :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added sed statement to rename package on setup.py and also updated README to identify the change and needing to install/download GNU sed instead of BSD sed.

description = "Generate modern Python clients from OpenAPI"
repository = "https://github.com/triaxtec/openapi-python-client"
license = "MIT"
Expand Down Expand Up @@ -71,7 +73,8 @@ gen-setuppy = """
poetry build \
&& tar --strip-components=1 -xvf "$(ls -1 dist/*tar.gz | tail -1)" '*/setup.py' \
&& isort setup.py \
&& black setup.py
&& black setup.py \
&& sed -i 's/"openapi-python-client"/"benchling-openapi-python-client"/' setup.py
"""

[tool.black]
Expand Down
16 changes: 8 additions & 8 deletions setup.py

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions tests/test_parser/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ def test_from_dict_invalid_schema(self, mocker):
class TestEndpoint:
def test_parse_yaml_body(self, mocker):
from openapi_python_client.parser.openapi import Endpoint, Schemas

schema = mocker.MagicMock()
body = oai.RequestBody.construct(
content={"text/yaml": oai.MediaType.construct(media_type_schema=schema)}
)
body = oai.RequestBody.construct(content={"text/yaml": oai.MediaType.construct(media_type_schema=schema)})
property_from_data = mocker.patch(f"{MODULE_NAME}.property_from_data")
schemas = Schemas()

Expand Down
61 changes: 46 additions & 15 deletions tests/test_parser/test_properties/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,29 @@ def test_get_type_string(self, mocker):
inner_property = mocker.MagicMock()
inner_type_string = mocker.MagicMock()
inner_property.get_type_string.return_value = inner_type_string
p = ListProperty(name="test", required=True, default=None, inner_property=inner_property, nullable=False, description=None)
p = ListProperty(
name="test", required=True, default=None, inner_property=inner_property, nullable=False, description=None
)

base_type_string = f"List[{inner_type_string}]"

assert p.get_type_string() == base_type_string

p = ListProperty(name="test", required=True, default=None, inner_property=inner_property, nullable=True, description=None)
p = ListProperty(
name="test", required=True, default=None, inner_property=inner_property, nullable=True, description=None
)
assert p.get_type_string() == f"Optional[{base_type_string}]"
assert p.get_type_string(no_optional=True) == base_type_string

p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=True, description=None)
p = ListProperty(
name="test", required=False, default=None, inner_property=inner_property, nullable=True, description=None
)
assert p.get_type_string() == f"Union[Unset, None, {base_type_string}]"
assert p.get_type_string(no_optional=True) == base_type_string

p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=False, description=None)
p = ListProperty(
name="test", required=False, default=None, inner_property=inner_property, nullable=False, description=None
)
assert p.get_type_string() == f"Union[Unset, {base_type_string}]"
assert p.get_type_string(no_optional=True) == base_type_string

Expand All @@ -226,22 +234,28 @@ def test_get_type_imports(self, mocker):
inner_import = mocker.MagicMock()
inner_property.get_imports.return_value = {inner_import}
prefix = "..."
p = ListProperty(name="test", required=True, default=None, inner_property=inner_property, nullable=False, description=None)
p = ListProperty(
name="test", required=True, default=None, inner_property=inner_property, nullable=False, description=None
)

assert p.get_imports(prefix=prefix) == {
inner_import,
"from typing import cast, List",
}

p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=False, description=None)
p = ListProperty(
name="test", required=False, default=None, inner_property=inner_property, nullable=False, description=None
)
assert p.get_imports(prefix=prefix) == {
inner_import,
"from typing import cast, List",
"from typing import Union",
"from ...types import UNSET, Unset",
}

p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=True, description=None)
p = ListProperty(
name="test", required=False, default=None, inner_property=inner_property, nullable=True, description=None
)
assert p.get_imports(prefix=prefix) == {
inner_import,
"from typing import cast, List",
Expand Down Expand Up @@ -690,15 +704,19 @@ def test_property_from_data_simple_types(self, openapi_type, prop_type, python_t
name=name, required=required, data=data, schemas=schemas, parent_name="parent"
)

assert p == prop_type(name=name, required=required, default=python_type(data.default), nullable=False, description=None)
assert p == prop_type(
name=name, required=required, default=python_type(data.default), nullable=False, description=None
)
assert new_schemas == schemas

# Test nullable values
data.default = 0
data.nullable = True

p, _ = property_from_data(name=name, required=required, data=data, schemas=schemas, parent_name="parent")
assert p == prop_type(name=name, required=required, default=python_type(data.default), nullable=True, description=None)
assert p == prop_type(
name=name, required=required, default=python_type(data.default), nullable=True, description=None
)

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

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

FloatProperty.assert_called_once_with(name=name, required=required, default=0.0, nullable=False, description=None)
FloatProperty.assert_called_once_with(
name=name, required=required, default=0.0, nullable=False, description=None
)
IntProperty.assert_called_once_with(name=name, required=required, default=0, nullable=False, description=None)
UnionProperty.assert_called_once_with(
name=name,
Expand Down Expand Up @@ -940,7 +960,9 @@ def test__string_based_property_no_format(self):

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

assert p == StringProperty(name=name, required=required, nullable=True, default="'\\\\\"hello world\\\\\"'", description=None)
assert p == StringProperty(
name=name, required=required, nullable=True, default="'\\\\\"hello world\\\\\"'", description=None
)

data.pattern = "abcdef"
data.nullable = False
Expand All @@ -951,7 +973,12 @@ def test__string_based_property_no_format(self):
data=data,
)
assert p == StringProperty(
name=name, required=required, nullable=False, default="'\\\\\"hello world\\\\\"'", pattern="abcdef", description=None
name=name,
required=required,
nullable=False,
default="'\\\\\"hello world\\\\\"'",
pattern="abcdef",
description=None,
)

def test__string_based_property_datetime_format(self):
Expand Down Expand Up @@ -983,7 +1010,9 @@ def test__string_based_property_date_format(self):

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

assert p == DateProperty(name=name, required=required, nullable=True, default="isoparse('2020-11-06').date()", description=None)
assert p == DateProperty(
name=name, required=required, nullable=True, default="isoparse('2020-11-06').date()", description=None
)

# Test bad default
data.default = "a"
Expand Down Expand Up @@ -1088,7 +1117,7 @@ def test_build_enums(mocker):
(False, False),
(
oai.Schema.construct(type="string"),
StringProperty(name="AdditionalProperty", required=True, nullable=False, default=None,description=None),
StringProperty(name="AdditionalProperty", required=True, nullable=False, default=None, description=None),
),
],
)
Expand Down Expand Up @@ -1129,7 +1158,9 @@ def test_build_model_property(additional_properties_schema, expected_additional_
reference=Reference(class_name="ParentMyModel", module_name="parent_my_model"),
references=[],
required_properties=[StringProperty(name="req", required=True, nullable=False, default=None, description=None)],
optional_properties=[DateTimeProperty(name="opt", required=False, nullable=False, default=None, description=None)],
optional_properties=[
DateTimeProperty(name="opt", required=False, nullable=False, default=None, description=None)
],
description=data.description,
relative_imports={
"from dateutil.parser import isoparse",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_templates/endpoint_module.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, List, Optional, Union, cast

import httpx
from attr import asdict
import yaml
from attr import asdict

from ...client import AuthenticatedClient, Client
from ...types import Response
Expand Down