Skip to content

Commit 5fd7e86

Browse files
style: apply ruff formatting to qa module
Co-Authored-By: Aaron <AJ> Steers <[email protected]>
1 parent 695b3a3 commit 5fd7e86

File tree

9 files changed

+122
-47
lines changed

9 files changed

+122
-47
lines changed

airbyte_cdk/qa/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class MyCustomCheck(Check):
5959
name = "My custom check"
6060
description = "Description of what my check verifies"
6161
category = CheckCategory.TESTING
62-
62+
6363
def _run(self, connector: Connector) -> CheckResult:
6464
if some_condition:
6565
return self.pass_(connector, "Check passed message")

airbyte_cdk/qa/checks/documentation/documentation.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class CheckDocumentationExists(DocumentationCheck):
1616
"""Check that connectors have documentation."""
1717

1818
name = "Connectors must have documentation"
19-
description = "Connectors must have documentation to ensure that users can understand how to use them."
19+
description = (
20+
"Connectors must have documentation to ensure that users can understand how to use them."
21+
)
2022

2123
def _run(self, connector: Connector) -> CheckResult:
2224
"""Run the check.
@@ -29,9 +31,11 @@ def _run(self, connector: Connector) -> CheckResult:
2931
"""
3032
docs_dir = Path("/home/ubuntu/repos/airbyte/docs/integrations")
3133
connector_type_dir = docs_dir / (connector.connector_type + "s")
32-
33-
doc_file = connector_type_dir / (connector.technical_name.replace("source-", "").replace("destination-", "") + ".md")
34-
34+
35+
doc_file = connector_type_dir / (
36+
connector.technical_name.replace("source-", "").replace("destination-", "") + ".md"
37+
)
38+
3539
if not doc_file.exists():
3640
return self.create_check_result(
3741
connector=connector,

airbyte_cdk/qa/checks/metadata.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,19 @@ def _run(self, connector: Connector) -> CheckResult:
3333
CheckResult: The result of the check
3434
"""
3535
if not connector.metadata_file_path.exists():
36-
return self.fail(connector=connector, message=f"Metadata file {consts.METADATA_FILE_NAME} does not exist")
37-
36+
return self.fail(
37+
connector=connector,
38+
message=f"Metadata file {consts.METADATA_FILE_NAME} does not exist",
39+
)
40+
3841
try:
3942
with open(connector.metadata_file_path, "r") as f:
4043
yaml.safe_load(f)
4144
except yaml.YAMLError as e:
42-
return self.fail(connector=connector, message=f"Metadata file is invalid YAML: {str(e)}")
43-
44-
45+
return self.fail(
46+
connector=connector, message=f"Metadata file is invalid YAML: {str(e)}"
47+
)
48+
4549
return self.pass_(
4650
connector=connector,
4751
message="Metadata file exists and is valid YAML.",
@@ -100,7 +104,11 @@ def _run(self, connector: Connector) -> CheckResult:
100104
message="Could not infer the language tag from the connector directory",
101105
)
102106

103-
current_language_tags = [t for t in (connector.metadata.get("tags", []) if connector.metadata else []) if t.startswith("language:")]
107+
current_language_tags = [
108+
t
109+
for t in (connector.metadata.get("tags", []) if connector.metadata else [])
110+
if t.startswith("language:")
111+
]
104112
if not current_language_tags:
105113
return self.fail(
106114
connector=connector,
@@ -146,15 +154,21 @@ def get_expected_cdk_tag(self, connector: Connector) -> str:
146154
Returns:
147155
str: The expected CDK tag
148156
"""
149-
manifest_file = connector.code_directory / connector.technical_name.replace("-", "_") / "manifest.yaml"
157+
manifest_file = (
158+
connector.code_directory / connector.technical_name.replace("-", "_") / "manifest.yaml"
159+
)
150160
pyproject_file = connector.code_directory / consts.PYPROJECT_FILE_NAME
151161
setup_py_file = connector.code_directory / "setup.py"
152162
if manifest_file.exists():
153163
return self.CDKTag.LOW_CODE
154164
if pyproject_file.exists():
155165
pyproject = toml.load((connector.code_directory / consts.PYPROJECT_FILE_NAME))
156166
cdk_deps = pyproject["tool"]["poetry"]["dependencies"].get("airbyte-cdk", None)
157-
if cdk_deps and isinstance(cdk_deps, dict) and "file-based" in cdk_deps.get("extras", []):
167+
if (
168+
cdk_deps
169+
and isinstance(cdk_deps, dict)
170+
and "file-based" in cdk_deps.get("extras", [])
171+
):
158172
return self.CDKTag.FILE
159173
if setup_py_file.exists():
160174
if "airbyte-cdk[file-based]" in (connector.code_directory / "setup.py").read_text():
@@ -170,7 +184,11 @@ def _run(self, connector: Connector) -> CheckResult:
170184
Returns:
171185
CheckResult: The result of the check
172186
"""
173-
current_cdk_tags = [t for t in (connector.metadata.get("tags", []) if connector.metadata else []) if t.startswith("cdk:")]
187+
current_cdk_tags = [
188+
t
189+
for t in (connector.metadata.get("tags", []) if connector.metadata else [])
190+
if t.startswith("cdk:")
191+
]
174192
expected_cdk_tag = self.get_expected_cdk_tag(connector)
175193
if not current_cdk_tags:
176194
return self.fail(
@@ -217,7 +235,9 @@ def _run(self, connector: Connector) -> CheckResult:
217235
message="Can't verify breaking changes deadline: connector version is not defined.",
218236
)
219237

220-
breaking_changes = (connector.metadata.get("releases", {}) if connector.metadata else {}).get("breakingChanges")
238+
breaking_changes = (
239+
connector.metadata.get("releases", {}) if connector.metadata else {}
240+
).get("breakingChanges")
221241

222242
if not breaking_changes:
223243
return self.pass_(
@@ -250,7 +270,10 @@ def _run(self, connector: Connector) -> CheckResult:
250270
message=f"The upgrade deadline for the breaking changes in {current_version} is less than {self.minimum_days_until_deadline} days from today. Please extend the deadline",
251271
)
252272

253-
return self.pass_(connector=connector, message="The upgrade deadline is set to at least a week in the future")
273+
return self.pass_(
274+
connector=connector,
275+
message="The upgrade deadline is set to at least a week in the future",
276+
)
254277

255278

256279
class CheckConnectorMaxSecondsBetweenMessagesValue(MetadataCheck):
@@ -270,7 +293,9 @@ def _run(self, connector: Connector) -> CheckResult:
270293
Returns:
271294
CheckResult: The result of the check
272295
"""
273-
max_seconds_between_messages = connector.metadata.get("maxSecondsBetweenMessages") if connector.metadata else None
296+
max_seconds_between_messages = (
297+
connector.metadata.get("maxSecondsBetweenMessages") if connector.metadata else None
298+
)
274299
if not max_seconds_between_messages:
275300
return self.fail(
276301
connector=connector,

airbyte_cdk/qa/checks/packaging.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def _run(self, connector: Connector) -> CheckResult:
4343
message=f"{consts.PYPROJECT_FILE_NAME} file is missing",
4444
)
4545
if not (connector.code_directory / consts.POETRY_LOCK_FILE_NAME).exists():
46-
return self.fail(connector=connector, message=f"{consts.POETRY_LOCK_FILE_NAME} file is missing")
46+
return self.fail(
47+
connector=connector, message=f"{consts.POETRY_LOCK_FILE_NAME} file is missing"
48+
)
4749
if (connector.code_directory / "setup.py").exists():
4850
return self.fail(
4951
connector=connector,
@@ -82,7 +84,9 @@ def _run(self, connector: Connector) -> CheckResult:
8284
passed=False,
8385
message=f"PyPi publishing is not declared. Please set it in the {consts.METADATA_FILE_NAME} file",
8486
)
85-
return self.create_check_result(connector=connector, passed=True, message="PyPi publishing is declared")
87+
return self.create_check_result(
88+
connector=connector, passed=True, message="PyPi publishing is declared"
89+
)
8690

8791

8892
class CheckManifestOnlyConnectorBaseImage(PackagingCheck):
@@ -110,7 +114,11 @@ def _run(self, connector: Connector) -> CheckResult:
110114
passed=False,
111115
message=f"A manifest-only connector must use `source-declarative-manifest` base image. Replace the base image in {consts.METADATA_FILE_NAME} file",
112116
)
113-
return self.create_check_result(connector=connector, passed=True, message="Connector uses source-declarative-manifest base image")
117+
return self.create_check_result(
118+
connector=connector,
119+
passed=True,
120+
message="Connector uses source-declarative-manifest base image",
121+
)
114122

115123

116124
class CheckConnectorLicense(PackagingCheck):
@@ -323,7 +331,7 @@ def _run(self, connector: Connector) -> CheckResult:
323331
passed=False,
324332
message=f"dockerImageTag is missing in {consts.METADATA_FILE_NAME}",
325333
)
326-
334+
327335
try:
328336
semver.Version.parse(str(connector.metadata["dockerImageTag"]))
329337
except ValueError:
@@ -332,7 +340,7 @@ def _run(self, connector: Connector) -> CheckResult:
332340
passed=False,
333341
message=f"Connector version {connector.metadata['dockerImageTag']} does not follow semantic versioning",
334342
)
335-
343+
336344
return self.create_check_result(
337345
connector=connector,
338346
passed=True,

airbyte_cdk/qa/checks/security.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,20 @@ def _read_all_files_in_directory(
7171
Tuple[Path, str]: The file path and line content
7272
"""
7373
ignored_directories = ignored_directories if ignored_directories is not None else set()
74-
ignored_filename_patterns = ignored_filename_patterns if ignored_filename_patterns is not None else set()
74+
ignored_filename_patterns = (
75+
ignored_filename_patterns if ignored_filename_patterns is not None else set()
76+
)
7577

7678
for path in directory.rglob("*"):
77-
ignore_directory = any([ignored_directory in path.parts for ignored_directory in ignored_directories])
78-
ignore_filename = any([path.match(ignored_filename_pattern) for ignored_filename_pattern in ignored_filename_patterns])
79+
ignore_directory = any(
80+
[ignored_directory in path.parts for ignored_directory in ignored_directories]
81+
)
82+
ignore_filename = any(
83+
[
84+
path.match(ignored_filename_pattern)
85+
for ignored_filename_pattern in ignored_filename_patterns
86+
]
87+
)
7988
ignore = ignore_directory or ignore_filename
8089
if path.is_file() and not ignore:
8190
try:
@@ -148,9 +157,7 @@ def _run(self, connector: Connector) -> CheckResult:
148157
class CheckConnectorUsesPythonBaseImage(SecurityCheck):
149158
"""Check that Python connectors use the Python connector base image."""
150159

151-
name = (
152-
f"Python connectors must not use a Dockerfile and must declare their base image in {consts.METADATA_FILE_NAME} file"
153-
)
160+
name = f"Python connectors must not use a Dockerfile and must declare their base image in {consts.METADATA_FILE_NAME} file"
154161
description = f"Connectors must use our Python connector base image, declared through the `connectorBuildOptions.baseImage` in their `{consts.METADATA_FILE_NAME}`.\nThis is to ensure that all connectors use a base image which is maintained and has security updates."
155162
applies_to_connector_languages = [
156163
ConnectorLanguage.PYTHON,
@@ -175,7 +182,9 @@ def _run(self, connector: Connector) -> CheckResult:
175182
message=f"Dockerfile file exists. Please remove it and declare the base image in {consts.METADATA_FILE_NAME} file with the `connectorBuildOptions.baseImage` key",
176183
)
177184

178-
base_image = (connector.metadata.get("connectorBuildOptions", {}) if connector.metadata else {}).get("baseImage")
185+
base_image = (
186+
connector.metadata.get("connectorBuildOptions", {}) if connector.metadata else {}
187+
).get("baseImage")
179188
if not base_image:
180189
return self.create_check_result(
181190
connector=connector,

airbyte_cdk/qa/checks/testing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class CheckConnectorHasAcceptanceTests(TestingCheck):
1414
"""Check that connectors have acceptance tests."""
1515

1616
name = "Connectors must have acceptance tests"
17-
description = "Connectors must have acceptance tests to ensure that they meet the Airbyte specification."
17+
description = (
18+
"Connectors must have acceptance tests to ensure that they meet the Airbyte specification."
19+
)
1820

1921
def _run(self, connector: Connector) -> CheckResult:
2022
"""Run the check.

airbyte_cdk/qa/connector.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ def code_directory(self) -> Path:
9898
"""
9999
if self._connector_directory:
100100
return self._connector_directory
101-
101+
102102
cwd = Path.cwd()
103103
if cwd.name == self.technical_name:
104104
return cwd
105-
105+
106106
for parent in cwd.parents:
107107
if parent.name == self.technical_name:
108108
return parent
109-
109+
110110
return cwd
111111

112112
@property
@@ -142,9 +142,15 @@ def language(self) -> Optional[ConnectorLanguage]:
142142
Returns:
143143
ConnectorLanguage: The programming language of the connector
144144
"""
145-
if Path(self.code_directory / "setup.py").exists() or Path(self.code_directory / "pyproject.toml").exists():
145+
if (
146+
Path(self.code_directory / "setup.py").exists()
147+
or Path(self.code_directory / "pyproject.toml").exists()
148+
):
146149
return ConnectorLanguage.PYTHON
147-
if Path(self.code_directory / "src" / "main" / "java").exists() or Path(self.code_directory / "src" / "main" / "kotlin").exists():
150+
if (
151+
Path(self.code_directory / "src" / "main" / "java").exists()
152+
or Path(self.code_directory / "src" / "main" / "kotlin").exists()
153+
):
148154
return ConnectorLanguage.JAVA
149155
if self.manifest_path.exists():
150156
return ConnectorLanguage.LOW_CODE
@@ -247,7 +253,7 @@ def is_released(self) -> bool:
247253
"""
248254
if self._is_released is not None:
249255
return self._is_released
250-
256+
251257
self._is_released = True
252258
return True
253259

airbyte_cdk/qa/models.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from __future__ import annotations
32

43
import json
@@ -196,12 +195,18 @@ def run(self, connector: Connector) -> CheckResult:
196195
connector,
197196
f"Check does not apply to {connector.connector_type} connectors",
198197
)
199-
if self.applies_to_connector_support_levels and connector.support_level not in self.applies_to_connector_support_levels:
198+
if (
199+
self.applies_to_connector_support_levels
200+
and connector.support_level not in self.applies_to_connector_support_levels
201+
):
200202
return self.skip(
201203
connector,
202204
f"Check does not apply to {connector.support_level} connectors",
203205
)
204-
if self.applies_to_connector_cloud_usage and connector.cloud_usage not in self.applies_to_connector_cloud_usage:
206+
if (
207+
self.applies_to_connector_cloud_usage
208+
and connector.cloud_usage not in self.applies_to_connector_cloud_usage
209+
):
205210
return self.skip(
206211
connector,
207212
f"Check does not apply to {connector.cloud_usage} connectors",
@@ -239,7 +244,9 @@ def pass_(self, connector: Connector, message: str) -> CheckResult:
239244
Returns:
240245
CheckResult: A passing check result
241246
"""
242-
return CheckResult(connector=connector, check=self, status=CheckStatus.PASSED, message=message)
247+
return CheckResult(
248+
connector=connector, check=self, status=CheckStatus.PASSED, message=message
249+
)
243250

244251
def fail(self, connector: Connector, message: str) -> CheckResult:
245252
"""Create a failing check result.
@@ -251,7 +258,9 @@ def fail(self, connector: Connector, message: str) -> CheckResult:
251258
Returns:
252259
CheckResult: A failing check result
253260
"""
254-
return CheckResult(connector=connector, check=self, status=CheckStatus.FAILED, message=message)
261+
return CheckResult(
262+
connector=connector, check=self, status=CheckStatus.FAILED, message=message
263+
)
255264

256265
def skip(self, connector: Connector, reason: str) -> CheckResult:
257266
"""Create a skipped check result.
@@ -263,7 +272,9 @@ def skip(self, connector: Connector, reason: str) -> CheckResult:
263272
Returns:
264273
CheckResult: A skipped check result
265274
"""
266-
return CheckResult(connector=connector, check=self, status=CheckStatus.SKIPPED, message=reason)
275+
return CheckResult(
276+
connector=connector, check=self, status=CheckStatus.SKIPPED, message=reason
277+
)
267278

268279
def create_check_result(self, connector: Connector, passed: bool, message: str) -> CheckResult:
269280
"""Create a check result based on whether the check passed or failed.
@@ -326,23 +337,31 @@ def to_json(self) -> str:
326337
"message": check_result.message,
327338
}
328339
if check_result.status == CheckStatus.PASSED:
329-
connectors_report[connector.technical_name]["passed_checks"].append(check_name_and_message)
340+
connectors_report[connector.technical_name]["passed_checks"].append(
341+
check_name_and_message
342+
)
330343
connectors_report[connector.technical_name]["successful_checks_count"] += 1
331344
connectors_report[connector.technical_name]["total_checks_count"] += 1
332345

333346
elif check_result.status == CheckStatus.FAILED:
334-
connectors_report[connector.technical_name]["failed_checks"].append(check_name_and_message)
347+
connectors_report[connector.technical_name]["failed_checks"].append(
348+
check_name_and_message
349+
)
335350
connectors_report[connector.technical_name]["failed_checks_count"] += 1
336351
connectors_report[connector.technical_name]["total_checks_count"] += 1
337352

338353
elif check_result.status == CheckStatus.SKIPPED:
339-
connectors_report[connector.technical_name]["skipped_checks"].append(check_name_and_message)
354+
connectors_report[connector.technical_name]["skipped_checks"].append(
355+
check_name_and_message
356+
)
340357
connectors_report[connector.technical_name]["skipped_checks_count"] += 1
341358
else:
342359
raise ValueError(f"Invalid check status {check_result.status}")
343360
for connector_technical_name in connectors_report.keys():
344361
connectors_report[connector_technical_name]["badge_color"] = (
345-
"red" if connectors_report[connector_technical_name]["failed_checks_count"] > 0 else "green"
362+
"red"
363+
if connectors_report[connector_technical_name]["failed_checks_count"] > 0
364+
else "green"
346365
)
347366
badge_name = self.badge_name.replace(" ", "_")
348367
badge_text = f"{connectors_report[connector_technical_name]['successful_checks_count']}/{connectors_report[connector_technical_name]['total_checks_count']}".replace(

0 commit comments

Comments
 (0)