Skip to content

Commit c3ee514

Browse files
author
Oleksandr Bazarnov
committed
fixed linters issues
1 parent 38b7362 commit c3ee514

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

airbyte_cdk/manifest_migrations/manifest_migration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MigrationTrace:
3131
migration: str
3232
migrated_at: str
3333

34-
def as_dict(self) -> dict:
34+
def as_dict(self) -> Dict[str, Any]:
3535
return asdict(self)
3636

3737

airbyte_cdk/manifest_migrations/migration_handler.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,23 @@ def _handle_migration(
8282
if migration_instance.is_migrated:
8383
# set the updated manifest version, after migration has been applied
8484
self._set_manifest_version(migration_version)
85-
# set the migration trace
8685
self._set_migration_trace(migration_class, manifest_version, migration_version)
8786
else:
8887
LOGGER.info(
89-
f"Manifest migration: `{migration_instance.__name__}` is not supported for the given manifest version `{manifest_version}`.",
88+
f"Manifest migration: `{self._get_migration_name(migration_class)}` is not supported for the given manifest version `{manifest_version}`.",
9089
)
9190
except Exception as e:
9291
raise ManifestMigrationException(str(e)) from e
9392

93+
def _get_migration_name(self, migration_class: Type[ManifestMigration]) -> str:
94+
"""
95+
Get the name of the migration instance.
96+
97+
Returns:
98+
str: The name of the migration.
99+
"""
100+
return migration_class.__name__
101+
94102
def _get_manifest_version(self) -> str:
95103
"""
96104
Get the manifest version from the manifest.
@@ -101,8 +109,20 @@ def _get_manifest_version(self) -> str:
101109
return str(self._migrated_manifest.get(MANIFEST_VERSION_TAG, "0.0.0"))
102110

103111
def _version_is_valid_for_migration(
104-
self, manifest_version: str, migration_version: str
112+
self,
113+
manifest_version: str,
114+
migration_version: str,
105115
) -> bool:
116+
"""
117+
Checks if the given manifest version is less than or equal to the specified migration version.
118+
119+
Args:
120+
manifest_version (str): The version of the manifest to check.
121+
migration_version (str): The migration version to compare against.
122+
123+
Returns:
124+
bool: True if the manifest version is less than or equal to the migration version, False otherwise.
125+
"""
106126
return Version(manifest_version) <= Version(migration_version)
107127

108128
def _set_manifest_version(self, version: str) -> None:
@@ -120,7 +140,7 @@ def _set_migration_trace(
120140
migration_version: str,
121141
) -> None:
122142
"""
123-
Set the migration trace in the manifest.
143+
Set the migration trace in the manifest, under the `metadata.applied_migrations` property object.
124144
125145
:param migration_instance: The migration instance to set
126146
:param manifest_version: The manifest version before migration
@@ -135,7 +155,7 @@ def _set_migration_trace(
135155
migration_trace = MigrationTrace(
136156
from_version=manifest_version,
137157
to_version=migration_version,
138-
migration=migration_instance.__name__,
158+
migration=self._get_migration_name(migration_instance),
139159
migrated_at=datetime.now(tz=timezone.utc).isoformat(),
140160
).as_dict()
141161

airbyte_cdk/manifest_migrations/migrations_registry.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import inspect
88
import os
99
from pathlib import Path
10+
from types import ModuleType
1011
from typing import Dict, List, Type
1112

1213
import yaml
@@ -21,22 +22,22 @@
2122
REGISTRY_PATH = MIGRATIONS_PATH / "registry.yaml"
2223

2324

24-
def _find_migration_module(name: str) -> str | None:
25+
def _find_migration_module(name: str) -> str:
2526
"""
2627
Finds the migration module by name in the migrations directory.
2728
The name should match the file name of the migration module (without the .py extension).
2829
Raises ImportError if the module is not found.
2930
"""
30-
try:
31-
for migration_file in os.listdir(MIGRATIONS_PATH):
32-
migration_name = name + ".py"
33-
if migration_file == migration_name:
34-
return migration_file.replace(".py", "")
35-
except ImportError as e:
36-
raise ImportError(f"Migration module '{name}' not found in {MIGRATIONS_PATH}.") from e
3731

32+
for migration_file in os.listdir(MIGRATIONS_PATH):
33+
migration_name = name + ".py"
34+
if migration_file == migration_name:
35+
return migration_file.replace(".py", "")
3836

39-
def _get_migration_class(module) -> type:
37+
raise ImportError(f"Migration module '{name}' not found in {MIGRATIONS_PATH}.")
38+
39+
40+
def _get_migration_class(module: ModuleType) -> Type[ManifestMigration]:
4041
"""
4142
Returns the ManifestMigration subclass defined in the module.
4243
"""
@@ -53,7 +54,7 @@ def _discover_migrations() -> DiscoveredMigrations:
5354
"""
5455
with open(REGISTRY_PATH, "r") as f:
5556
registry = yaml.safe_load(f)
56-
migrations = {}
57+
migrations: DiscoveredMigrations = {}
5758
# Iterate through the registry and import the migration classes
5859
# based on the version and order specified in the registry.yaml
5960
for version_entry in registry.get("manifest_migrations", []):

0 commit comments

Comments
 (0)