Skip to content

Commit

Permalink
file-based: move toggle to root
Browse files Browse the repository at this point in the history
  • Loading branch information
aldogonzalez8 committed Jan 8, 2025
1 parent 1fd48aa commit edf6816
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 59 deletions.
24 changes: 9 additions & 15 deletions airbyte_cdk/sources/file_based/config/abstract_file_based_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
from airbyte_cdk.sources.utils import schema_helpers


class DeliveryOptions(BaseModel):
preserve_subdirectories_directories: bool = Field(
True,
description="Flag indicating we should preserve subdirectories directories",
)


class DeliverRecords(BaseModel):
class Config(OneOfOptionConfig):
title = "Replicate Records"
Expand All @@ -37,10 +30,11 @@ class Config(OneOfOptionConfig):
discriminator = "delivery_type"

delivery_type: Literal["use_file_transfer"] = Field("use_file_transfer", const=True)
delivery_options: Optional[DeliveryOptions] = Field(
title="Delivery Options",
type="object",
order=2,

preserve_subdirectories_directories: bool = Field(
title="Preserve Subdirectories Directories",
description="Flag indicating we should preserve subdirectories directories",
default=True,
)


Expand Down Expand Up @@ -77,10 +71,10 @@ class AbstractFileBasedSpec(BaseModel):
airbyte_hidden=True,
)

delivery_options: Optional[DeliveryOptions] = Field(
title="Delivery Options",
type="object",
order=8,
preserve_subdirectories_directories: bool = Field(
title="Preserve Subdirectories Directories",
description="Flag indicating we should preserve subdirectories directories",
default=True,
)

@classmethod
Expand Down
7 changes: 3 additions & 4 deletions airbyte_cdk/sources/file_based/file_based_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,8 @@ def _use_file_transfer(parsed_config: AbstractFileBasedSpec) -> bool:
def _preserve_subdirectories_directories(parsed_config: AbstractFileBasedSpec) -> bool:
# fall back to preserve subdirectories if config is not present or incomplete
if (
hasattr(parsed_config, "delivery_options")
and parsed_config.delivery_options is not None
and hasattr(parsed_config.delivery_options, "preserve_subdirectories_directories")
hasattr(parsed_config, "preserve_subdirectories_directories")
and parsed_config.preserve_subdirectories_directories is not None
):
return parsed_config.delivery_options.preserve_subdirectories_directories
return parsed_config.preserve_subdirectories_directories
return True
7 changes: 3 additions & 4 deletions airbyte_cdk/sources/file_based/file_based_stream_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,10 @@ def preserve_subdirectories_directories(self) -> bool:
# fall back to preserve subdirectories if config is not present or incomplete
if (
self.config
and hasattr(self.config, "delivery_options")
and self.config.delivery_options is not None
and hasattr(self.config.delivery_options, "preserve_subdirectories_directories")
and hasattr(self.config, "preserve_subdirectories_directories")
and self.config.preserve_subdirectories_directories is not None
):
return self.config.delivery_options.preserve_subdirectories_directories
return self.config.preserve_subdirectories_directories
return True

@abstractmethod
Expand Down
46 changes: 10 additions & 36 deletions unit_tests/sources/file_based/scenarios/csv_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,56 +517,30 @@
"title": "Copy Raw Files",
"type": "object",
"properties": {
"delivery_options": {
"allOf": [
{
"properties": {
"preserve_subdirectories_directories": {
"default": True,
"description": "Flag indicating we should preserve subdirectories directories",
"title": "Preserve Subdirectories Directories",
"type": "boolean",
}
},
"title": "DeliveryOptions",
"type": "object",
}
],
"order": 2,
"title": "Delivery Options",
"type": "object",
},
"delivery_type": {
"title": "Delivery Type",
"default": "use_file_transfer",
"const": "use_file_transfer",
"enum": ["use_file_transfer"],
"type": "string",
},
},
"description": "Copy raw files without parsing their contents. Bits are copied into the destination exactly as they appeared in the source. Recommended for use with unstructured text data, non-text and compressed files.",
"required": ["delivery_type"],
},
],
},
"delivery_options": {
"allOf": [
{
"properties": {
"preserve_subdirectories_directories": {
"default": True,
"description": "Flag indicating we should preserve subdirectories directories",
"title": "Preserve Subdirectories Directories",
"type": "boolean",
}
},
},
"title": "DeliveryOptions",
"type": "object",
}
"description": "Copy raw files without parsing their contents. Bits are copied into the destination exactly as they appeared in the source. Recommended for use with unstructured text data, non-text and compressed files.",
"required": ["delivery_type"],
},
],
"order": 8,
"title": "Delivery Options",
"type": "object",
},
"preserve_subdirectories_directories": {
"default": True,
"description": "Flag indicating we should preserve subdirectories directories",
"title": "Preserve Subdirectories Directories",
"type": "boolean",
},
},
"required": ["streams"],
Expand Down

0 comments on commit edf6816

Please sign in to comment.