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

0 commit comments

Comments
 (0)