Skip to content

Commit 331dc24

Browse files
author
octavia-squidington-iii
committed
Auto-fix lint and format issues
1 parent 202b0d0 commit 331dc24

File tree

4 files changed

+51
-65
lines changed

4 files changed

+51
-65
lines changed

airbyte_cdk/sources/declarative/checks/check_dynamic_stream.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ def check_connection(
4141
availability_strategy = HttpAvailabilityStrategy()
4242

4343
try:
44-
for stream in streams[:min(self.stream_count, len(streams))]:
45-
stream_is_available, reason = availability_strategy.check_availability(stream, logger)
44+
for stream in streams[: min(self.stream_count, len(streams))]:
45+
stream_is_available, reason = availability_strategy.check_availability(
46+
stream, logger
47+
)
4648
if not stream_is_available:
4749
logger.warning(f"Stream {stream.name} is not available: {reason}")
4850
return False, reason
4951
except Exception as error:
50-
error_message = f"Encountered an error trying to connect to stream {stream.name}. Error: {error}"
52+
error_message = (
53+
f"Encountered an error trying to connect to stream {stream.name}. Error: {error}"
54+
)
5155
logger.error(error_message, exc_info=True)
5256
return False, error_message
5357

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

+32-58
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,7 @@ class OAuthAuthenticator(BaseModel):
609609
scopes: Optional[List[str]] = Field(
610610
None,
611611
description="List of scopes that should be granted to the access token.",
612-
examples=[
613-
["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]
614-
],
612+
examples=[["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]],
615613
title="Scopes",
616614
)
617615
token_expiry_date: Optional[str] = Field(
@@ -1047,28 +1045,24 @@ class OAuthConfigSpecification(BaseModel):
10471045
class Config:
10481046
extra = Extra.allow
10491047

1050-
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = (
1051-
Field(
1052-
None,
1053-
description="OAuth specific blob. This is a Json Schema used to validate Json configurations used as input to OAuth.\nMust be a valid non-nested JSON that refers to properties from ConnectorSpecification.connectionSpecification\nusing special annotation 'path_in_connector_config'.\nThese are input values the user is entering through the UI to authenticate to the connector, that might also shared\nas inputs for syncing data via the connector.\nExamples:\nif no connector values is shared during oauth flow, oauth_user_input_from_connector_config_specification=[]\nif connector values such as 'app_id' inside the top level are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['app_id']\n }\n }\nif connector values such as 'info.app_id' nested inside another object are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['info', 'app_id']\n }\n }",
1054-
examples=[
1055-
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1056-
{
1057-
"app_id": {
1058-
"type": "string",
1059-
"path_in_connector_config": ["info", "app_id"],
1060-
}
1061-
},
1062-
],
1063-
title="OAuth user input",
1064-
)
1048+
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = Field(
1049+
None,
1050+
description="OAuth specific blob. This is a Json Schema used to validate Json configurations used as input to OAuth.\nMust be a valid non-nested JSON that refers to properties from ConnectorSpecification.connectionSpecification\nusing special annotation 'path_in_connector_config'.\nThese are input values the user is entering through the UI to authenticate to the connector, that might also shared\nas inputs for syncing data via the connector.\nExamples:\nif no connector values is shared during oauth flow, oauth_user_input_from_connector_config_specification=[]\nif connector values such as 'app_id' inside the top level are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['app_id']\n }\n }\nif connector values such as 'info.app_id' nested inside another object are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['info', 'app_id']\n }\n }",
1051+
examples=[
1052+
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1053+
{
1054+
"app_id": {
1055+
"type": "string",
1056+
"path_in_connector_config": ["info", "app_id"],
1057+
}
1058+
},
1059+
],
1060+
title="OAuth user input",
10651061
)
1066-
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = (
1067-
Field(
1068-
None,
1069-
description='The DeclarativeOAuth specific blob.\nPertains to the fields defined by the connector relating to the OAuth flow.\n\nInterpolation capabilities:\n- The variables placeholders are declared as `{{my_var}}`.\n- The nested resolution variables like `{{ {{my_nested_var}} }}` is allowed as well.\n\n- The allowed interpolation context is:\n + base64Encoder - encode to `base64`, {{ {{my_var_a}}:{{my_var_b}} | base64Encoder }}\n + base64Decorer - decode from `base64` encoded string, {{ {{my_string_variable_or_string_value}} | base64Decoder }}\n + urlEncoder - encode the input string to URL-like format, {{ https://test.host.com/endpoint | urlEncoder}}\n + urlDecorer - decode the input url-encoded string into text format, {{ urlDecoder:https%3A%2F%2Fairbyte.io | urlDecoder}}\n + codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {{ {{state_value}} | codeChallengeS256 }}\n\nExamples:\n - The TikTok Marketing DeclarativeOAuth spec:\n {\n "oauth_connector_input_specification": {\n "type": "object",\n "additionalProperties": false,\n "properties": {\n "consent_url": "https://ads.tiktok.com/marketing_api/auth?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{ {{redirect_uri_value}} | urlEncoder}}&{{state_key}}={{state_value}}",\n "access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",\n "access_token_params": {\n "{{ auth_code_key }}": "{{ auth_code_value }}",\n "{{ client_id_key }}": "{{ client_id_value }}",\n "{{ client_secret_key }}": "{{ client_secret_value }}"\n },\n "access_token_headers": {\n "Content-Type": "application/json",\n "Accept": "application/json"\n },\n "extract_output": ["data.access_token"],\n "client_id_key": "app_id",\n "client_secret_key": "secret",\n "auth_code_key": "auth_code"\n }\n }\n }',
1070-
title="DeclarativeOAuth Connector Specification",
1071-
)
1062+
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = Field(
1063+
None,
1064+
description='The DeclarativeOAuth specific blob.\nPertains to the fields defined by the connector relating to the OAuth flow.\n\nInterpolation capabilities:\n- The variables placeholders are declared as `{{my_var}}`.\n- The nested resolution variables like `{{ {{my_nested_var}} }}` is allowed as well.\n\n- The allowed interpolation context is:\n + base64Encoder - encode to `base64`, {{ {{my_var_a}}:{{my_var_b}} | base64Encoder }}\n + base64Decorer - decode from `base64` encoded string, {{ {{my_string_variable_or_string_value}} | base64Decoder }}\n + urlEncoder - encode the input string to URL-like format, {{ https://test.host.com/endpoint | urlEncoder}}\n + urlDecorer - decode the input url-encoded string into text format, {{ urlDecoder:https%3A%2F%2Fairbyte.io | urlDecoder}}\n + codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {{ {{state_value}} | codeChallengeS256 }}\n\nExamples:\n - The TikTok Marketing DeclarativeOAuth spec:\n {\n "oauth_connector_input_specification": {\n "type": "object",\n "additionalProperties": false,\n "properties": {\n "consent_url": "https://ads.tiktok.com/marketing_api/auth?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{ {{redirect_uri_value}} | urlEncoder}}&{{state_key}}={{state_value}}",\n "access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",\n "access_token_params": {\n "{{ auth_code_key }}": "{{ auth_code_value }}",\n "{{ client_id_key }}": "{{ client_id_value }}",\n "{{ client_secret_key }}": "{{ client_secret_value }}"\n },\n "access_token_headers": {\n "Content-Type": "application/json",\n "Accept": "application/json"\n },\n "extract_output": ["data.access_token"],\n "client_id_key": "app_id",\n "client_secret_key": "secret",\n "auth_code_key": "auth_code"\n }\n }\n }',
1065+
title="DeclarativeOAuth Connector Specification",
10721066
)
10731067
complete_oauth_output_specification: Optional[Dict[str, Any]] = Field(
10741068
None,
@@ -1086,9 +1080,7 @@ class Config:
10861080
complete_oauth_server_input_specification: Optional[Dict[str, Any]] = Field(
10871081
None,
10881082
description="OAuth specific blob. This is a Json Schema used to validate Json configurations persisted as Airbyte Server configurations.\nMust be a valid non-nested JSON describing additional fields configured by the Airbyte Instance or Workspace Admins to be used by the\nserver when completing an OAuth flow (typically exchanging an auth code for refresh token).\nExamples:\n complete_oauth_server_input_specification={\n client_id: {\n type: string\n },\n client_secret: {\n type: string\n }\n }",
1089-
examples=[
1090-
{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}
1091-
],
1083+
examples=[{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}],
10921084
title="OAuth input specification",
10931085
)
10941086
complete_oauth_server_output_specification: Optional[Dict[str, Any]] = Field(
@@ -1674,9 +1666,7 @@ class RecordSelector(BaseModel):
16741666
description="Responsible for filtering records to be emitted by the Source.",
16751667
title="Record Filter",
16761668
)
1677-
schema_normalization: Optional[
1678-
Union[SchemaNormalization, CustomSchemaNormalization]
1679-
] = Field(
1669+
schema_normalization: Optional[Union[SchemaNormalization, CustomSchemaNormalization]] = Field(
16801670
SchemaNormalization.None_,
16811671
description="Responsible for normalization according to the schema.",
16821672
title="Schema Normalization",
@@ -1850,16 +1840,12 @@ class Config:
18501840
description="Component used to coordinate how records are extracted across stream slices and request pages.",
18511841
title="Retriever",
18521842
)
1853-
incremental_sync: Optional[Union[CustomIncrementalSync, DatetimeBasedCursor]] = (
1854-
Field(
1855-
None,
1856-
description="Component used to fetch data incrementally based on a time field in the data.",
1857-
title="Incremental Sync",
1858-
)
1859-
)
1860-
name: Optional[str] = Field(
1861-
"", description="The stream name.", example=["Users"], title="Name"
1843+
incremental_sync: Optional[Union[CustomIncrementalSync, DatetimeBasedCursor]] = Field(
1844+
None,
1845+
description="Component used to fetch data incrementally based on a time field in the data.",
1846+
title="Incremental Sync",
18621847
)
1848+
name: Optional[str] = Field("", description="The stream name.", example=["Users"], title="Name")
18631849
primary_key: Optional[PrimaryKey] = Field(
18641850
"", description="The primary key of the stream.", title="Primary Key"
18651851
)
@@ -2131,11 +2117,7 @@ class SimpleRetriever(BaseModel):
21312117
CustomPartitionRouter,
21322118
ListPartitionRouter,
21332119
SubstreamPartitionRouter,
2134-
List[
2135-
Union[
2136-
CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter
2137-
]
2138-
],
2120+
List[Union[CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter]],
21392121
]
21402122
] = Field(
21412123
[],
@@ -2179,9 +2161,7 @@ class AsyncRetriever(BaseModel):
21792161
)
21802162
download_extractor: Optional[
21812163
Union[CustomRecordExtractor, DpathExtractor, ResponseToFileExtractor]
2182-
] = Field(
2183-
None, description="Responsible for fetching the records from provided urls."
2184-
)
2164+
] = Field(None, description="Responsible for fetching the records from provided urls.")
21852165
creation_requester: Union[CustomRequester, HttpRequester] = Field(
21862166
...,
21872167
description="Requester component that describes how to prepare HTTP requests to send to the source API to create the async server-side job.",
@@ -2215,11 +2195,7 @@ class AsyncRetriever(BaseModel):
22152195
CustomPartitionRouter,
22162196
ListPartitionRouter,
22172197
SubstreamPartitionRouter,
2218-
List[
2219-
Union[
2220-
CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter
2221-
]
2222-
],
2198+
List[Union[CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter]],
22232199
]
22242200
] = Field(
22252201
[],
@@ -2287,12 +2263,10 @@ class DynamicDeclarativeStream(BaseModel):
22872263
stream_template: DeclarativeStream = Field(
22882264
..., description="Reference to the stream template.", title="Stream Template"
22892265
)
2290-
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = (
2291-
Field(
2292-
...,
2293-
description="Component resolve and populates stream templates with components values.",
2294-
title="Components Resolver",
2295-
)
2266+
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = Field(
2267+
...,
2268+
description="Component resolve and populates stream templates with components values.",
2269+
title="Components Resolver",
22962270
)
22972271

22982272

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,11 @@ def create_check_dynamic_stream(
907907

908908
use_check_availability = model.use_check_availability
909909

910-
return CheckDynamicStream(stream_count=model.stream_count, use_check_availability=use_check_availability, parameters={})
910+
return CheckDynamicStream(
911+
stream_count=model.stream_count,
912+
use_check_availability=use_check_availability,
913+
parameters={},
914+
)
911915

912916
def create_composite_error_handler(
913917
self, model: CompositeErrorHandlerModel, config: Config, **kwargs: Any

unit_tests/sources/declarative/checks/test_check_dynamic_stream.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#
44

55
import json
6-
from copy import deepcopy
76
import logging
7+
from copy import deepcopy
88

99
import pytest
1010

@@ -132,12 +132,16 @@
132132
),
133133
],
134134
)
135-
def test_check_dynamic_stream(response_code, available_expectation, use_check_availability, expected_messages):
135+
def test_check_dynamic_stream(
136+
response_code, available_expectation, use_check_availability, expected_messages
137+
):
136138
manifest = deepcopy(_MANIFEST)
137139

138140
with HttpMocker() as http_mocker:
139141
items_request = HttpRequest(url="https://api.test.com/items")
140-
items_response = HttpResponse(body=json.dumps([{"id": 1, "name": "item_1"}, {"id": 2, "name": "item_2"}]))
142+
items_response = HttpResponse(
143+
body=json.dumps([{"id": 1, "name": "item_1"}, {"id": 2, "name": "item_2"}])
144+
)
141145
items_request_count = 1
142146
http_mocker.get(items_request, items_response)
143147

0 commit comments

Comments
 (0)