Skip to content

Commit b002218

Browse files
refactor: use generator comprehension instead of list comprehension
Co-Authored-By: Aaron <AJ> Steers <[email protected]>
1 parent 36d7f1f commit b002218

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed

airbyte_cdk/entrypoint.py

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -141,54 +141,53 @@ def run(self, parsed_args: argparse.Namespace) -> Iterable[str]:
141141
)
142142
if cmd == "spec":
143143
message = AirbyteMessage(type=Type.SPEC, spec=source_spec)
144-
yield from [
144+
yield from (
145145
self.airbyte_message_to_string(queued_message)
146146
for queued_message in self._emit_queued_messages(self.source)
147-
]
147+
)
148148
yield self.airbyte_message_to_string(message)
149+
elif (
150+
cmd == "discover"
151+
and not parsed_args.config
152+
and not self.source.check_config_against_spec
153+
):
154+
empty_config: dict[str, Any] = {}
155+
yield from (
156+
self.airbyte_message_to_string(queued_message)
157+
for queued_message in self._emit_queued_messages(self.source)
158+
)
159+
yield from map(
160+
AirbyteEntrypoint.airbyte_message_to_string,
161+
self.discover(source_spec, empty_config),
162+
)
149163
else:
150-
if (
151-
cmd == "discover"
152-
and not parsed_args.config
153-
and not self.source.check_config_against_spec
154-
):
155-
empty_config: dict[str, Any] = {}
156-
yield from [
157-
self.airbyte_message_to_string(queued_message)
158-
for queued_message in self._emit_queued_messages(self.source)
159-
]
164+
raw_config = self.source.read_config(parsed_args.config)
165+
config = self.source.configure(raw_config, temp_dir)
166+
167+
yield from (
168+
self.airbyte_message_to_string(queued_message)
169+
for queued_message in self._emit_queued_messages(self.source)
170+
)
171+
if cmd == "check":
172+
yield from map(
173+
AirbyteEntrypoint.airbyte_message_to_string,
174+
self.check(source_spec, config),
175+
)
176+
elif cmd == "discover":
177+
yield from map(
178+
AirbyteEntrypoint.airbyte_message_to_string,
179+
self.discover(source_spec, config),
180+
)
181+
elif cmd == "read":
182+
config_catalog = self.source.read_catalog(parsed_args.catalog)
183+
state = self.source.read_state(parsed_args.state)
184+
160185
yield from map(
161186
AirbyteEntrypoint.airbyte_message_to_string,
162-
self.discover(source_spec, empty_config),
187+
self.read(source_spec, config, config_catalog, state),
163188
)
164189
else:
165-
raw_config = self.source.read_config(parsed_args.config)
166-
config = self.source.configure(raw_config, temp_dir)
167-
168-
yield from [
169-
self.airbyte_message_to_string(queued_message)
170-
for queued_message in self._emit_queued_messages(self.source)
171-
]
172-
if cmd == "check":
173-
yield from map(
174-
AirbyteEntrypoint.airbyte_message_to_string,
175-
self.check(source_spec, config),
176-
)
177-
elif cmd == "discover":
178-
yield from map(
179-
AirbyteEntrypoint.airbyte_message_to_string,
180-
self.discover(source_spec, config),
181-
)
182-
elif cmd == "read":
183-
config_catalog = self.source.read_catalog(parsed_args.catalog)
184-
state = self.source.read_state(parsed_args.state)
185-
186-
yield from map(
187-
AirbyteEntrypoint.airbyte_message_to_string,
188-
self.read(source_spec, config, config_catalog, state),
189-
)
190-
else:
191-
raise Exception("Unexpected command " + cmd)
190+
raise Exception("Unexpected command " + cmd)
192191
finally:
193192
yield from [
194193
self.airbyte_message_to_string(queued_message)

0 commit comments

Comments
 (0)