Skip to content

Commit

Permalink
poetry run ruff check --fix
Browse files Browse the repository at this point in the history
poetry run poe lint
  • Loading branch information
Rusi Popov committed Jan 22, 2025
1 parent 3d4ffe6 commit 2381916
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
from typing import Any, Iterable, List, Mapping, MutableMapping, Union

from airbyte_cdk.sources.declarative.extractors.dpath_extractor import DpathExtractor

from airbyte_cdk.sources.declarative.extractors.record_extractor import add_service_key,is_service_key,SERVICE_KEY_PREFIX
from airbyte_cdk.sources.declarative.extractors.record_extractor import (
SERVICE_KEY_PREFIX,
add_service_key,
is_service_key,
)

# The name of the service key that holds a reference to the original root response
SERVICE_KEY_ROOT = "root"
Expand Down Expand Up @@ -109,19 +112,19 @@ def _set_parent(self,body: Any, parent:Any) -> Any:
:return: a copy of the body enhanced in a subclass-specific way. None only when body is None.
"""
if isinstance(body, dict):
result = dict()
result:dict[str, Any] = dict()
if parent:
result = add_service_key(result, SERVICE_KEY_PARENT, parent)
attributes_only = dict(result)
attributes_only.update({k:v for k,v in body.items()
if v and not isinstance(v,dict) and not isinstance(v,list)})
for k,v in body.items():
result[k] = self._set_parent(v,attributes_only)
return result
elif isinstance(body, list):
result = [self._set_parent(v,parent) for v in body]
return [self._set_parent(v,parent) for v in body]
else:
result = body
return result
return body

def update_record(self, record: Any, root: Any) -> Any:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import requests

from airbyte_cdk.sources.declarative.decoders import Decoder, JsonDecoder
from airbyte_cdk.sources.declarative.extractors.record_extractor import RecordExtractor
from airbyte_cdk.sources.declarative.interpolation.interpolated_string import InterpolatedString
from airbyte_cdk.sources.types import Config
from airbyte_cdk.sources.declarative.extractors.record_extractor import RecordExtractor


@dataclass
class DpathExtractor(RecordExtractor):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SERVICE_KEY_PREFIX = "$"


def add_service_key(mapping: Mapping[str, Any], key:str, value:Any) -> Mapping[str, Any]:
def add_service_key(mapping: Mapping[str, Any], key:str, value:Any) -> dict[str, Any]:
"""
:param mapping: non-null mapping
:param key: the name of the key, not including any specific prefixes
Expand All @@ -32,12 +32,11 @@ def exclude_service_keys(struct: Any) -> Any:
:return: a copy of struct without any service fields at any level of nesting
"""
if isinstance(struct, dict):
result = {k: exclude_service_keys(v) for k, v in struct.items() if not is_service_key(k)}
return {k: exclude_service_keys(v) for k, v in struct.items() if not is_service_key(k)}
elif isinstance(struct, list):
result = [exclude_service_keys(v) for v in struct]
return [exclude_service_keys(v) for v in struct]
else:
result = struct
return result
return struct

def is_service_key(key: str) -> bool:
return key.find(SERVICE_KEY_PREFIX) == 0
Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ the value of the **dockerImageTag** parameter.
- `poetry run pytest` to run all unit tests.
- `poetry run pytest -k <suite or test name>` to run specific unit tests.
- `poetry run pytest-fast` to run the subset of PyTest tests, which are not flagged as `slow`. (It should take <5 min for fast tests only.)
- `python -m pytest -s unit_tests` if you want to pass pytest options.
- `poetry run pytest -s unit_tests` if you want to pass pytest options.

### Run Code Formatting

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
JsonDecoder,
JsonlDecoder,
)
from airbyte_cdk.sources.declarative.extractors.dpath_enhancing_extractor import DpathEnhancingExtractor, \
SERVICE_KEY_ROOT, SERVICE_KEY_PARENT
from airbyte_cdk.sources.declarative.extractors.dpath_enhancing_extractor import (
SERVICE_KEY_PARENT,
SERVICE_KEY_ROOT,
DpathEnhancingExtractor,
)
from airbyte_cdk.sources.declarative.extractors.record_extractor import (
SERVICE_KEY_PREFIX,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import requests

from airbyte_cdk.sources.declarative.decoders.json_decoder import JsonDecoder
from airbyte_cdk.sources.declarative.extractors.dpath_enhancing_extractor import (
SERVICE_KEY_PARENT,
SERVICE_KEY_ROOT,
)
from airbyte_cdk.sources.declarative.extractors.dpath_extractor import DpathExtractor
from airbyte_cdk.sources.declarative.extractors.dpath_enhancing_extractor import SERVICE_KEY_ROOT, SERVICE_KEY_PARENT
from airbyte_cdk.sources.declarative.extractors.record_extractor import (
SERVICE_KEY_PREFIX,
exclude_service_keys,
SERVICE_KEY_PREFIX
)
from airbyte_cdk.sources.declarative.extractors.record_filter import RecordFilter
from airbyte_cdk.sources.declarative.extractors.record_selector import RecordSelector
Expand Down

0 comments on commit 2381916

Please sign in to comment.