Skip to content

Commit 8a88ffe

Browse files
chore: cleanup codebase and fix flake errors (#188)
* deps: `flake8-strict` and `flake8-import-order` are not compatible with Black and modern Python anymore Signed-off-by: Yurii Serhiichuk <[email protected]> * chore: Cleanup imports and remove obsolete `#noqa`. Signed-off-by: Yurii Serhiichuk <[email protected]> * chore: sort imports. Signed-off-by: Yurii Serhiichuk <[email protected]> * chore: Define `__all__` Signed-off-by: Yurii Serhiichuk <[email protected]> * chore: Fix licenses and add __all__ to imports. Signed-off-by: Yurii Serhiichuk <[email protected]> * chore: Fix formatting Signed-off-by: Yurii Serhiichuk <[email protected]> * chore: Export `from_http` Signed-off-by: Yurii Serhiichuk <[email protected]> * fix: Do not export functions of other modules from this one. Signed-off-by: Yurii Serhiichuk <[email protected]> * chore: Resolve more flake8 errors Signed-off-by: Yurii Serhiichuk <[email protected]> * chore: Fix more warnings Signed-off-by: Yurii Serhiichuk <[email protected]> * docs: add a note in the changelog about the fixes. Signed-off-by: Yurii Serhiichuk <[email protected]> * fix: imports in tests. Signed-off-by: Yurii Serhiichuk <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: more import fixes. Signed-off-by: Yurii Serhiichuk <[email protected]> * fix: use proper implementations as replacements. Signed-off-by: Yurii Serhiichuk <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Signed-off-by: Yurii Serhiichuk <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f5bb285 commit 8a88ffe

27 files changed

+106
-120
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
moved under `cloudevents.http.conversion`.
2222
- Deprecated `cloudevents.http.util` module.
2323

24+
### Fixed
25+
- Multiple PEP issues, license headers, module-level exports. ([#188])
2426

2527

2628
## [1.5.0] — 2022-08-06
@@ -199,3 +201,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
199201
[#182]: https://github.com/cloudevents/sdk-python/pull/182
200202
[#184]: https://github.com/cloudevents/sdk-python/pull/184
201203
[#186]: https://github.com/cloudevents/sdk-python/pull/186
204+
[#188]: https://github.com/cloudevents/sdk-python/pull/188

cloudevents/__init__.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,5 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
#
15-
# Licensed under the Apache License, Version 2.0 (the "License"); you may
16-
# not use this file except in compliance with the License. You may obtain
17-
# a copy of the License at
18-
#
19-
# http://www.apache.org/licenses/LICENSE-2.0
20-
#
21-
# Unless required by applicable law or agreed to in writing, software
22-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
23-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
24-
# License for the specific language governing permissions and limitations
25-
# under the License.
26-
#
27-
# Licensed under the Apache License, Version 2.0 (the "License"); you may
28-
# not use this file except in compliance with the License. You may obtain
29-
# a copy of the License at
30-
#
31-
# http://www.apache.org/licenses/LICENSE-2.0
32-
#
33-
# Unless required by applicable law or agreed to in writing, software
34-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
35-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
36-
# License for the specific language governing permissions and limitations
37-
# under the License.
3814

3915
__version__ = "1.5.0"

cloudevents/abstract/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15-
from cloudevents.abstract.event import AnyCloudEvent, CloudEvent # noqa
15+
from cloudevents.abstract.event import AnyCloudEvent, CloudEvent
16+
17+
__all__ = [AnyCloudEvent, CloudEvent]

cloudevents/abstract/event.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import typing
1616
from abc import abstractmethod
17-
from typing import TypeVar
1817

1918

2019
class CloudEvent:
@@ -134,4 +133,4 @@ def __repr__(self) -> str:
134133
return str({"attributes": self._get_attributes(), "data": self._get_data()})
135134

136135

137-
AnyCloudEvent = TypeVar("AnyCloudEvent", bound=CloudEvent)
136+
AnyCloudEvent = typing.TypeVar("AnyCloudEvent", bound=CloudEvent)

cloudevents/conversion.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
#
15-
# Licensed under the Apache License, Version 2.0 (the "License"); you may
16-
# not use this file except in compliance with the License. You may obtain
17-
# a copy of the License at
18-
#
19-
# http://www.apache.org/licenses/LICENSE-2.0
20-
#
21-
# Unless required by applicable law or agreed to in writing, software
22-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
23-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
24-
# License for the specific language governing permissions and limitations
25-
# under the License.
2614
import datetime
2715
import enum
2816
import json
@@ -42,10 +30,10 @@ def _best_effort_serialize_to_json(
4230
Serializes the given value into a JSON-encoded string.
4331
4432
Given a None value returns None as is.
45-
Given a non-JSON-serializable value returns return the value as is.
33+
Given a non-JSON-serializable value returns the value as is.
4634
4735
:param value: The value to be serialized into a JSON string.
48-
:return: JSON string of the given value OR None OR given value.
36+
:returns: JSON string of the given value OR None OR given value.
4937
"""
5038
if value is None:
5139
return None

cloudevents/http/__init__.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,25 @@
1313
# under the License.
1414

1515

16-
from cloudevents.http.conversion import ( # noqa
17-
from_dict,
18-
from_http,
19-
from_json,
16+
from cloudevents.http.conversion import from_dict, from_http, from_json
17+
from cloudevents.http.event import CloudEvent
18+
from cloudevents.http.event_type import is_binary, is_structured # deprecated
19+
from cloudevents.http.http_methods import ( # deprecated
2020
to_binary,
21-
to_dict,
22-
to_json,
21+
to_binary_http,
2322
to_structured,
23+
to_structured_http,
2424
)
25-
from cloudevents.http.event import CloudEvent # noqa
26-
from cloudevents.http.http_methods import to_binary_http # deprecated # noqa
27-
from cloudevents.http.http_methods import to_structured_http # deprecated # noqa
28-
from cloudevents.sdk.converters.binary import is_binary # noqa
29-
from cloudevents.sdk.converters.structured import is_structured # noqa
25+
26+
__all__ = [
27+
to_binary,
28+
to_structured,
29+
from_json,
30+
from_http,
31+
from_dict,
32+
CloudEvent,
33+
is_binary,
34+
is_structured,
35+
to_binary_http,
36+
to_structured_http,
37+
]

cloudevents/http/conversion.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
# Copyright 2018-Present The CloudEvents Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
115
import typing
216

317
from cloudevents.conversion import from_dict as _abstract_from_dict
418
from cloudevents.conversion import from_http as _abstract_from_http
519
from cloudevents.conversion import from_json as _abstract_from_json
6-
from cloudevents.conversion import to_binary, to_dict, to_json, to_structured # noqa
720
from cloudevents.http.event import CloudEvent
821
from cloudevents.sdk import types
922

cloudevents/http/http_methods.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
from deprecation import deprecated
1818

1919
from cloudevents.abstract import AnyCloudEvent
20+
from cloudevents.conversion import to_binary as _moved_to_binary
21+
from cloudevents.conversion import to_structured as _moved_to_structured
2022
from cloudevents.http.conversion import from_http as _moved_from_http
21-
from cloudevents.http.conversion import to_binary as _moved_to_binary
22-
from cloudevents.http.conversion import to_structured as _moved_to_structured
2323
from cloudevents.http.event import CloudEvent
2424
from cloudevents.sdk import types
2525

@@ -28,7 +28,7 @@
2828

2929
@deprecated(
3030
deprecated_in="1.6.0",
31-
details="Use cloudevents.http.to_binary function instead",
31+
details="Use cloudevents.conversion.to_binary function instead",
3232
)
3333
def to_binary(
3434
event: AnyCloudEvent, data_marshaller: types.MarshallerType = None
@@ -38,7 +38,7 @@ def to_binary(
3838

3939
@deprecated(
4040
deprecated_in="1.6.0",
41-
details="Use cloudevents.http.to_structured function instead",
41+
details="Use cloudevents.conversion.to_structured function instead",
4242
)
4343
def to_structured(
4444
event: AnyCloudEvent,

cloudevents/http/json_methods.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
from deprecation import deprecated
1818

1919
from cloudevents.abstract import AnyCloudEvent
20+
from cloudevents.conversion import to_json as _moved_to_json
2021
from cloudevents.http import CloudEvent
2122
from cloudevents.http.conversion import from_json as _moved_from_json
22-
from cloudevents.http.conversion import to_json as _moved_to_json
2323
from cloudevents.sdk import types
2424

2525
# THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE
2626

2727

2828
@deprecated(
2929
deprecated_in="1.6.0",
30-
details="Use cloudevents.http.to_json function instead",
30+
details="Use cloudevents.conversion.to_json function instead",
3131
)
3232
def to_json(
3333
event: AnyCloudEvent,

cloudevents/http/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# under the License.
1414
from deprecation import deprecated
1515

16-
from cloudevents.conversion import ( # noqa
16+
from cloudevents.conversion import (
1717
_best_effort_serialize_to_json as _moved_default_marshaller,
1818
)
1919

cloudevents/pydantic/__init__.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from cloudevents.pydantic.conversion import ( # noqa
15-
from_dict,
16-
from_http,
17-
from_json,
18-
to_binary,
19-
to_dict,
20-
to_json,
21-
to_structured,
22-
)
23-
from cloudevents.pydantic.event import CloudEvent # noqa
14+
from cloudevents.pydantic.conversion import from_dict, from_http, from_json
15+
from cloudevents.pydantic.event import CloudEvent
16+
17+
__all__ = [CloudEvent, from_json, from_dict, from_http]

cloudevents/pydantic/conversion.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from cloudevents.conversion import from_dict as _abstract_from_dict
1717
from cloudevents.conversion import from_http as _abstract_from_http
1818
from cloudevents.conversion import from_json as _abstract_from_json
19-
from cloudevents.conversion import to_binary, to_dict, to_json, to_structured # noqa
2019
from cloudevents.pydantic.event import CloudEvent
2120
from cloudevents.sdk import types
2221

cloudevents/pydantic/event.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"Install it using pip install cloudevents[pydantic]"
2626
)
2727

28-
import cloudevents.conversion
2928
from cloudevents import abstract, conversion, http
3029
from cloudevents.exceptions import IncompatibleArgumentsError
3130
from cloudevents.sdk.event import attribute
@@ -74,7 +73,7 @@ def _ce_json_loads(
7473
"""
7574
# Using HTTP from dict due to performance issues.
7675
# Pydantic is known for initialization time lagging.
77-
return cloudevents.conversion.to_dict(http.from_json(data))
76+
return conversion.to_dict(http.from_json(data))
7877

7978

8079
class CloudEvent(abstract.CloudEvent, pydantic.BaseModel):

cloudevents/sdk/converters/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
# under the License.
1414

1515
from cloudevents.sdk.converters import binary, structured
16-
from cloudevents.sdk.converters.binary import is_binary # noqa
17-
from cloudevents.sdk.converters.structured import is_structured # noqa
16+
from cloudevents.sdk.converters.binary import is_binary
17+
from cloudevents.sdk.converters.structured import is_structured
1818

1919
TypeBinary = binary.BinaryHTTPCloudEventConverter.TYPE
2020
TypeStructured = structured.JSONHTTPCloudEventConverter.TYPE
21+
22+
__all__ = [binary, structured, is_binary, is_structured, TypeBinary, TypeStructured]

cloudevents/sdk/converters/util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717

1818
def has_binary_headers(headers: typing.Dict[str, str]) -> bool:
19+
"""Determines if all CloudEvents required headers are presents
20+
in the `headers`.
21+
22+
:returns: True if all the headers are present, False otherwise.
23+
"""
1924
return (
2025
"ce-specversion" in headers
2126
and "ce-source" in headers

cloudevents/tests/data.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,29 @@
1414

1515
from cloudevents.sdk.event import v1, v03
1616

17-
contentType = "application/json"
17+
content_type = "application/json"
1818
ce_type = "word.found.exclamation"
1919
ce_id = "16fb5f0b-211e-1102-3dfe-ea6e2806f124"
2020
source = "pytest"
21-
eventTime = "2018-10-23T12:28:23.3464579Z"
21+
event_time = "2018-10-23T12:28:23.3464579Z"
2222
body = '{"name":"john"}'
2323

2424
headers = {
2525
v03.Event: {
2626
"ce-specversion": "1.0",
2727
"ce-type": ce_type,
2828
"ce-id": ce_id,
29-
"ce-time": eventTime,
29+
"ce-time": event_time,
3030
"ce-source": source,
31-
"Content-Type": contentType,
31+
"Content-Type": content_type,
3232
},
3333
v1.Event: {
3434
"ce-specversion": "1.0",
3535
"ce-type": ce_type,
3636
"ce-id": ce_id,
37-
"ce-time": eventTime,
37+
"ce-time": event_time,
3838
"ce-source": source,
39-
"Content-Type": contentType,
39+
"Content-Type": content_type,
4040
},
4141
}
4242

@@ -45,16 +45,16 @@
4545
"specversion": "1.0",
4646
"type": ce_type,
4747
"id": ce_id,
48-
"time": eventTime,
48+
"time": event_time,
4949
"source": source,
50-
"datacontenttype": contentType,
50+
"datacontenttype": content_type,
5151
},
5252
v1.Event: {
5353
"specversion": "1.0",
5454
"type": ce_type,
5555
"id": ce_id,
56-
"time": eventTime,
56+
"time": event_time,
5757
"source": source,
58-
"datacontenttype": contentType,
58+
"datacontenttype": content_type,
5959
},
6060
}

cloudevents/tests/test_backwards_compatability.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def dummy_event():
2323

2424

2525
def test_json_methods(dummy_event):
26-
from cloudevents.http import from_json, to_json
26+
from cloudevents.conversion import to_json
27+
from cloudevents.http.conversion import from_json
2728
from cloudevents.http.json_methods import from_json as deprecated_from_json
2829
from cloudevents.http.json_methods import to_json as deprecated_to_json
2930

cloudevents/tests/test_data_encaps_refs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_general_binary_properties(event_class):
4040
assert event is not None
4141
assert event.type == data.ce_type
4242
assert event.id == data.ce_id
43-
assert event.content_type == data.contentType
43+
assert event.content_type == data.content_type
4444
assert event.source == data.source
4545

4646
# Test setters
@@ -80,7 +80,7 @@ def test_general_structured_properties(event_class):
8080
assert event is not None
8181
assert event.type == data.ce_type
8282
assert event.id == data.ce_id
83-
assert event.content_type == data.contentType
83+
assert event.content_type == data.content_type
8484
assert event.source == data.source
8585

8686
new_headers, _ = m.ToRequest(event, converters.TypeStructured, lambda x: x)

0 commit comments

Comments
 (0)