Skip to content

Commit 7309360

Browse files
authored
[airbyte-ci] Format using a poe task (#38043)
1 parent 8d914d9 commit 7309360

File tree

10 files changed

+128
-70
lines changed

10 files changed

+128
-70
lines changed

airbyte-cdk/python/airbyte_cdk/connector_builder/connector_builder_handler.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ def create_source(config: Mapping[str, Any], limits: TestReadLimits) -> Manifest
5454

5555

5656
def read_stream(
57-
source: DeclarativeSource, config: Mapping[str, Any], configured_catalog: ConfiguredAirbyteCatalog, state: List[AirbyteStateMessage], limits: TestReadLimits
57+
source: DeclarativeSource,
58+
config: Mapping[str, Any],
59+
configured_catalog: ConfiguredAirbyteCatalog,
60+
state: List[AirbyteStateMessage],
61+
limits: TestReadLimits,
5862
) -> AirbyteMessage:
5963
try:
6064
handler = MessageGrouper(limits.max_pages_per_slice, limits.max_slices, limits.max_records)

airbyte-cdk/python/airbyte_cdk/connector_builder/message_grouper.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ def get_message_groups(
120120
raise ValueError(f"Unknown message group type: {type(message_group)}")
121121

122122
try:
123-
configured_stream = configured_catalog.streams[0] # The connector builder currently only supports reading from a single stream at a time
123+
# The connector builder currently only supports reading from a single stream at a time
124+
configured_stream = configured_catalog.streams[0]
124125
schema = schema_inferrer.get_stream_schema(configured_stream.stream.name)
125126
except SchemaValidationException as exception:
126127
for validation_error in exception.validation_errors:
@@ -183,7 +184,11 @@ def _get_message_groups(
183184
and message.type == MessageType.LOG
184185
and message.log.message.startswith(SliceLogger.SLICE_LOG_PREFIX)
185186
):
186-
yield StreamReadSlices(pages=current_slice_pages, slice_descriptor=current_slice_descriptor, state=[latest_state_message] if latest_state_message else [])
187+
yield StreamReadSlices(
188+
pages=current_slice_pages,
189+
slice_descriptor=current_slice_descriptor,
190+
state=[latest_state_message] if latest_state_message else [],
191+
)
187192
current_slice_descriptor = self._parse_slice_description(message.log.message)
188193
current_slice_pages = []
189194
at_least_one_page_in_group = False
@@ -230,7 +235,11 @@ def _get_message_groups(
230235
else:
231236
if current_page_request or current_page_response or current_page_records:
232237
self._close_page(current_page_request, current_page_response, current_slice_pages, current_page_records)
233-
yield StreamReadSlices(pages=current_slice_pages, slice_descriptor=current_slice_descriptor, state=[latest_state_message] if latest_state_message else [])
238+
yield StreamReadSlices(
239+
pages=current_slice_pages,
240+
slice_descriptor=current_slice_descriptor,
241+
state=[latest_state_message] if latest_state_message else [],
242+
)
234243

235244
@staticmethod
236245
def _need_to_close_page(at_least_one_page_in_group: bool, message: AirbyteMessage, json_message: Optional[Dict[str, Any]]) -> bool:
@@ -281,8 +290,11 @@ def _close_page(
281290
current_page_records.clear()
282291

283292
def _read_stream(
284-
self, source: DeclarativeSource, config: Mapping[str, Any], configured_catalog: ConfiguredAirbyteCatalog,
285-
state: List[AirbyteStateMessage]
293+
self,
294+
source: DeclarativeSource,
295+
config: Mapping[str, Any],
296+
configured_catalog: ConfiguredAirbyteCatalog,
297+
state: List[AirbyteStateMessage],
286298
) -> Iterator[AirbyteMessage]:
287299
# the generator can raise an exception
288300
# iterate over the generated messages. if next raise an exception, catch it and yield it as an AirbyteLogMessage

airbyte-cdk/python/airbyte_cdk/test/catalog_builder.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ def with_stream(self, name: Union[str, ConfiguredAirbyteStreamBuilder], sync_mod
5454

5555
# to avoid a breaking change, `name` needs to stay in the API but this can be either a name or a builder
5656
name_or_builder = name
57-
builder = name_or_builder if isinstance(name_or_builder, ConfiguredAirbyteStreamBuilder) else ConfiguredAirbyteStreamBuilder().with_name(name_or_builder).with_sync_mode(sync_mode)
57+
builder = (
58+
name_or_builder
59+
if isinstance(name_or_builder, ConfiguredAirbyteStreamBuilder)
60+
else ConfiguredAirbyteStreamBuilder().with_name(name_or_builder).with_sync_mode(sync_mode)
61+
)
5862
self._streams.append(builder)
5963
return self
6064

airbyte-cdk/python/airbyte_cdk/test/mock_http/response_builder.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,7 @@ def build(self) -> Dict[str, Any]:
138138

139139
class HttpResponseBuilder:
140140
def __init__(
141-
self,
142-
template: Dict[str, Any],
143-
records_path: Union[FieldPath, NestedPath],
144-
pagination_strategy: Optional[PaginationStrategy]
141+
self, template: Dict[str, Any], records_path: Union[FieldPath, NestedPath], pagination_strategy: Optional[PaginationStrategy]
145142
):
146143
self._response = template
147144
self._records: List[RecordBuilder] = []
@@ -198,16 +195,16 @@ def create_record_builder(
198195
try:
199196
record_template = records_path.extract(response_template)[0]
200197
if not record_template:
201-
raise ValueError(f"Could not extract any record from template at path `{records_path}`. "
202-
f"Please fix the template to provide a record sample or fix `records_path`.")
198+
raise ValueError(
199+
f"Could not extract any record from template at path `{records_path}`. "
200+
f"Please fix the template to provide a record sample or fix `records_path`."
201+
)
203202
return RecordBuilder(record_template, record_id_path, record_cursor_path)
204203
except (IndexError, KeyError):
205204
raise ValueError(f"Error while extracting records at path `{records_path}` from response template `{response_template}`")
206205

207206

208207
def create_response_builder(
209-
response_template: Dict[str, Any],
210-
records_path: Union[FieldPath, NestedPath],
211-
pagination_strategy: Optional[PaginationStrategy] = None
208+
response_template: Dict[str, Any], records_path: Union[FieldPath, NestedPath], pagination_strategy: Optional[PaginationStrategy] = None
212209
) -> HttpResponseBuilder:
213210
return HttpResponseBuilder(response_template, records_path, pagination_strategy)

airbyte-cdk/python/airbyte_cdk/test/state_builder.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@ def __init__(self) -> None:
1010
self._state: List[AirbyteStateMessage] = []
1111

1212
def with_stream_state(self, stream_name: str, state: Any) -> "StateBuilder":
13-
self._state.append(AirbyteStateMessage.parse_obj({
14-
"type": "STREAM",
15-
"stream": {
16-
"stream_state": state,
17-
"stream_descriptor": {
18-
"name": stream_name
19-
}
20-
}
21-
}))
13+
self._state.append(
14+
AirbyteStateMessage.parse_obj({"type": "STREAM", "stream": {"stream_state": state, "stream_descriptor": {"name": stream_name}}})
15+
)
2216
return self
2317

2418
def build(self) -> List[AirbyteStateMessage]:

airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/format/configuration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ class FormatConfiguration:
5151
Formatter.PYTHON,
5252
["**/*.py"],
5353
format_python_container,
54-
["poetry run isort --settings-file pyproject.toml .", "poetry run black --config pyproject.toml ."],
54+
["poetry run poe format"],
5555
),
5656
]

airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/format/consts.py

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"**/pnpm-lock.yaml", # This file is generated and should not be formatted
3636
"**/normalization_test_output",
3737
"**/source-amplitude/unit_tests/api_data/zipped.json", # Zipped file presents as non-UTF-8 making spotless sad
38-
"**/tools/git_hooks/tests/test_spec_linter.py",
3938
"airbyte-cdk/python/airbyte_cdk/sources/declarative/models/**", # These files are generated and should not be formatted
4039
"airbyte-ci/connectors/metadata_service/lib/metadata_service/models/generated/**", # These files are generated and should not be formatted
4140
"**/airbyte-ci/connectors/metadata_service/lib/tests/fixtures/**/invalid", # This is a test directory with invalid and sometimes unformatted code

airbyte-integrations/connectors/source-zendesk-chat/build_customization.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from dagger import Container
1010

1111

12-
1312
async def pre_connector_install(base_image_container: Container) -> Container:
1413
"""This function will run before the connector installation.
1514
We set these environment variable to match what was originally in the Dockerfile.

poetry.lock

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

pyproject.toml

+38-19
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,30 @@ python = "~3.10"
1111
isort = "5.6.4"
1212
black = "~22.3.0"
1313
ruff = "^0.4"
14+
poethepoet = "^0.26.1"
15+
16+
[tool.poe.tasks]
17+
isort = { cmd = "poetry run isort --settings-file pyproject.toml ." }
18+
black = { cmd = "poetry run black --config pyproject.toml ." }
19+
format = { sequence = [
20+
"isort",
21+
"black",
22+
], help = "Format Python code in the repository. This command is invoked in airbyte-ci format." }
1423

1524
[tool.black]
1625
line-length = 140
1726
target-version = ["py310"]
18-
extend-exclude = "(build|integration_tests|unit_tests|generated)"
19-
20-
[tool.coverage.report]
21-
fail_under = 0
22-
skip_empty = true
23-
sort = "-cover"
24-
omit = [
25-
".venv/*",
26-
"main.py",
27-
"setup.py",
28-
"unit_tests/*",
29-
"integration_tests/*",
30-
"**/generated/*",
31-
]
27+
extend-exclude = """
28+
/(
29+
build
30+
| integration_tests
31+
| unit_tests
32+
| generated
33+
| airbyte-cdk/python/airbyte_cdk/sources/declarative/models
34+
| invalid
35+
| non_formatted_code
36+
)/
37+
"""
3238

3339
[tool.flake8]
3440
extend-exclude = [
@@ -37,15 +43,12 @@ extend-exclude = [
3743
"build",
3844
"models",
3945
".eggs",
40-
"airbyte-cdk/python/airbyte_cdk/models/__init__.py",
41-
"airbyte-cdk/python/airbyte_cdk/sources/declarative/models/__init__.py",
42-
".tox",
43-
"airbyte_api_client",
46+
"**/__init__.py",
4447
"**/generated/*",
48+
"**/declarative/models/*",
4549
]
4650
max-complexity = 20
4751
max-line-length = 140
48-
4952
extend-ignore = [
5053
"E203", # whitespace before ':' (conflicts with Black)
5154
"E231", # Bad trailing comma (conflicts with Black)
@@ -54,6 +57,19 @@ extend-ignore = [
5457
"F811", # TODO: ella fix after pflake8 version update
5558
]
5659

60+
[tool.coverage.report]
61+
fail_under = 0
62+
skip_empty = true
63+
sort = "-cover"
64+
omit = [
65+
".venv/*",
66+
"main.py",
67+
"setup.py",
68+
"unit_tests/*",
69+
"integration_tests/*",
70+
"**/generated/*",
71+
]
72+
5773
# TODO: This will be removed in favor of the section below.
5874
[tool.isort]
5975
profile = "black"
@@ -65,6 +81,9 @@ include_trailing_comma = true
6581
force_grid_wrap = 0
6682
use_parentheses = true
6783
skip_glob = [
84+
"airbyte-cdk/python/airbyte_cdk/sources/declarative/models/**",
85+
"**/invalid/**",
86+
"**/non_formatted_code/**",
6887
"**/connector_builder/generated/**",
6988
# TODO: Remove this after we move to Ruff. Ruff is mono-repo-aware and
7089
# correctly handles first-party imports in subdirectories.

0 commit comments

Comments
 (0)