Skip to content

Commit 830ad57

Browse files
committed
lint
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
1 parent 378af3e commit 830ad57

File tree

17 files changed

+109
-286
lines changed

17 files changed

+109
-286
lines changed

examples/connectors/snowflake_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from flyteplugins.connectors.snowflake import Snowflake, SnowflakeConfig
2+
13
import flyte
24
from flyte.io import DataFrame
3-
from flyteplugins.connectors.snowflake import Snowflake, SnowflakeConfig
45

56
"""
67
Example of using Snowflake connector.

examples/image/custom_builder/src/my_builder/my_builder.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ def get_checkers(self) -> Optional[typing.List[typing.Type[ImageChecker]]]:
2020
"""Return the image checker."""
2121
return [MyImageChecker]
2222

23-
async def build_image(self, image: Image, dry_run: bool = False, wait: bool = True,) -> str:
23+
async def build_image(
24+
self,
25+
image: Image,
26+
dry_run: bool = False,
27+
wait: bool = True,
28+
) -> str:
2429
print("Building image locally...")
2530
return image.uri

plugins/connectors/src/flyteplugins/connectors/snowflake/connector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ def _execute_query():
172172
schema=schema,
173173
warehouse=warehouse,
174174
query_id=query_id,
175-
has_output=task_template.interface.outputs is not None and len(task_template.interface.outputs.variables) > 0,
175+
has_output=task_template.interface.outputs is not None
176+
and len(task_template.interface.outputs.variables) > 0,
176177
connection_kwargs=connection_kwargs,
177178
)
178179

plugins/wandb/src/flyteplugins/wandb/__init__.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ async def my_task():
134134
import os
135135
from typing import Optional
136136

137-
import wandb
138-
139137
import flyte
140138
from flyte.io import Dir
141139

140+
import wandb
141+
142142
from ._context import (
143143
get_wandb_context,
144144
get_wandb_sweep_context,
@@ -317,9 +317,7 @@ def download_wandb_run_dir(
317317
f"Error: {e}"
318318
) from e
319319
except Exception as e:
320-
raise RuntimeError(
321-
f"Unexpected error fetching wandb run '{run_path}': {e}"
322-
) from e
320+
raise RuntimeError(f"Unexpected error fetching wandb run '{run_path}': {e}") from e
323321

324322
try:
325323
for file in api_run.files():
@@ -334,13 +332,9 @@ def download_wandb_run_dir(
334332
with open(os.path.join(path, "summary.json"), "w") as f:
335333
json.dump(summary_data, f, indent=2, default=str)
336334
except (IOError, OSError) as e:
337-
raise RuntimeError(
338-
f"Failed to write summary.json for run '{run_id}': {e}"
339-
) from e
335+
raise RuntimeError(f"Failed to write summary.json for run '{run_id}': {e}") from e
340336
except Exception as e:
341-
raise RuntimeError(
342-
f"Failed to export summary data for run '{run_id}': {e}"
343-
) from e
337+
raise RuntimeError(f"Failed to export summary data for run '{run_id}': {e}") from e
344338

345339
# Export metrics history to JSON
346340
if include_history:
@@ -350,13 +344,9 @@ def download_wandb_run_dir(
350344
with open(os.path.join(path, "metrics_history.json"), "w") as f:
351345
json.dump(history, f, indent=2, default=str)
352346
except (IOError, OSError) as e:
353-
raise RuntimeError(
354-
f"Failed to write metrics_history.json for run '{run_id}': {e}"
355-
) from e
347+
raise RuntimeError(f"Failed to write metrics_history.json for run '{run_id}': {e}") from e
356348
except Exception as e:
357-
raise RuntimeError(
358-
f"Failed to export history data for run '{run_id}': {e}"
359-
) from e
349+
raise RuntimeError(f"Failed to export history data for run '{run_id}': {e}") from e
360350

361351
return path
362352

@@ -403,9 +393,7 @@ def download_wandb_sweep_dirs(
403393
project = wandb_ctx.project if wandb_ctx else None
404394

405395
if not entity or not project:
406-
raise RuntimeError(
407-
"Cannot query sweep without entity and project. Set them via wandb_config()."
408-
)
396+
raise RuntimeError("Cannot query sweep without entity and project. Set them via wandb_config().")
409397

410398
# Query sweep runs via wandb API
411399
try:
@@ -425,9 +413,7 @@ def download_wandb_sweep_dirs(
425413
f"Error: {e}"
426414
) from e
427415
except Exception as e:
428-
raise RuntimeError(
429-
f"Unexpected error fetching wandb sweep '{entity}/{project}/{sweep_id}': {e}"
430-
) from e
416+
raise RuntimeError(f"Unexpected error fetching wandb sweep '{entity}/{project}/{sweep_id}': {e}") from e
431417

432418
# Download each run's data
433419
downloaded_paths = []
@@ -436,9 +422,7 @@ def download_wandb_sweep_dirs(
436422
for run_id in run_ids:
437423
path = f"{base_path or '/tmp/wandb_runs'}/{run_id}"
438424
try:
439-
download_wandb_run_dir(
440-
run_id=run_id, path=path, include_history=include_history
441-
)
425+
download_wandb_run_dir(run_id=run_id, path=path, include_history=include_history)
442426
downloaded_paths.append(path)
443427
except Exception as e:
444428
# Log failure but continue with other runs

plugins/wandb/src/flyteplugins/wandb/_context.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,7 @@ def get_wandb_sweep_context() -> Optional[_WandBSweepConfig]:
333333
if ctx is None or not ctx.custom_context:
334334
return None
335335

336-
has_wandb_sweep_keys = any(
337-
k.startswith("wandb_sweep_") for k in ctx.custom_context.keys()
338-
)
336+
has_wandb_sweep_keys = any(k.startswith("wandb_sweep_") for k in ctx.custom_context.keys())
339337
if not has_wandb_sweep_keys:
340338
return None
341339

plugins/wandb/src/flyteplugins/wandb/_decorator.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from inspect import iscoroutinefunction
66
from typing import Any, Callable, Optional, TypeVar, cast
77

8-
import wandb
9-
108
import flyte
119
from flyte._task import AsyncFunctionTaskTemplate
1210

11+
import wandb
12+
1313
from ._context import RunMode, get_wandb_context, get_wandb_sweep_context
1414
from ._link import Wandb, WandbSweep
1515

@@ -124,9 +124,7 @@ def _wandb_run(
124124
if not is_primary:
125125
shared_config["x_update_finish_state"] = False
126126

127-
init_kwargs["settings"] = wandb.Settings(
128-
**{**existing_settings, **shared_config}
129-
)
127+
init_kwargs["settings"] = wandb.Settings(**{**existing_settings, **shared_config})
130128

131129
# Initialize wandb
132130
run = wandb.init(**init_kwargs)
@@ -141,9 +139,7 @@ def _wandb_run(
141139
yield run
142140
finally:
143141
# Determine if this is a primary run
144-
is_primary_run = run_mode == "new" or (
145-
run_mode == "auto" and saved_run_id is None
146-
)
142+
is_primary_run = run_mode == "new" or (run_mode == "auto" and saved_run_id is None)
147143

148144
if run:
149145
# Different cleanup logic for local vs remote mode
@@ -293,9 +289,7 @@ def sync_wrapper(*args, **wrapper_kwargs):
293289

294290

295291
@contextmanager
296-
def _create_sweep(
297-
project: Optional[str] = None, entity: Optional[str] = None, **decorator_kwargs
298-
):
292+
def _create_sweep(project: Optional[str] = None, entity: Optional[str] = None, **decorator_kwargs):
299293
"""Context manager for wandb sweep creation."""
300294
ctx = flyte.ctx()
301295

@@ -317,14 +311,8 @@ def _create_sweep(
317311
wandb_config = get_wandb_context()
318312

319313
# Priority: decorator kwargs > sweep config > wandb config
320-
project = (
321-
project
322-
or sweep_config.project
323-
or (wandb_config.project if wandb_config else None)
324-
)
325-
entity = (
326-
entity or sweep_config.entity or (wandb_config.entity if wandb_config else None)
327-
)
314+
project = project or sweep_config.project or (wandb_config.project if wandb_config else None)
315+
entity = entity or sweep_config.entity or (wandb_config.entity if wandb_config else None)
328316
prior_runs = sweep_config.prior_runs or []
329317

330318
# Get sweep config dict
@@ -401,19 +389,15 @@ def decorator(func: F) -> F:
401389
original_execute = func.execute
402390

403391
async def wrapped_execute(*args, **exec_kwargs):
404-
with _create_sweep(
405-
project=project, entity=entity, **kwargs
406-
) as sweep_id:
392+
with _create_sweep(project=project, entity=entity, **kwargs) as sweep_id:
407393
result = await original_execute(*args, **exec_kwargs)
408394

409395
# After sweep finishes, optionally download logs
410396
should_download = download_logs
411397
if should_download is None:
412398
# Check context config
413399
sweep_config = get_wandb_sweep_context()
414-
should_download = (
415-
sweep_config.download_logs if sweep_config else False
416-
)
400+
should_download = sweep_config.download_logs if sweep_config else False
417401

418402
if should_download and sweep_id:
419403
from . import download_wandb_sweep_logs

plugins/wandb/tests/test_context.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,8 @@ def test_wandb_sweep_config_to_dict(self):
410410
result = config.to_dict()
411411

412412
assert result["wandb_sweep_method"] == "random"
413-
assert result["wandb_sweep_metric"] == json.dumps(
414-
{"name": "loss", "goal": "minimize"}
415-
)
416-
assert result["wandb_sweep_parameters"] == json.dumps(
417-
{"lr": {"min": 0.001, "max": 0.1}}
418-
)
413+
assert result["wandb_sweep_metric"] == json.dumps({"name": "loss", "goal": "minimize"})
414+
assert result["wandb_sweep_parameters"] == json.dumps({"lr": {"min": 0.001, "max": 0.1}})
419415

420416
def test_wandb_sweep_config_from_dict(self):
421417
"""Test creating WandBSweepConfig from dict."""

0 commit comments

Comments
 (0)