Skip to content

Commit 5f3e661

Browse files
committed
ruff and isort
1 parent ce8ba08 commit 5f3e661

File tree

10 files changed

+224
-109
lines changed

10 files changed

+224
-109
lines changed

src/gaiaflow/cli/commands/minikube.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212

1313
def load_imports():
1414
from gaiaflow.constants import BaseAction
15-
from gaiaflow.managers.minikube_manager import (ExtendedAction,
16-
MinikubeManager)
17-
from gaiaflow.managers.utils import (create_gaiaflow_context_path,
18-
gaiaflow_path_exists_in_state,
19-
parse_key_value_pairs)
15+
from gaiaflow.managers.minikube_manager import ExtendedAction, MinikubeManager
16+
from gaiaflow.managers.utils import (
17+
create_gaiaflow_context_path,
18+
gaiaflow_path_exists_in_state,
19+
parse_key_value_pairs,
20+
)
2021

2122
return SimpleNamespace(
2223
BaseAction=BaseAction,
@@ -101,12 +102,14 @@ def restart(
101102
)
102103

103104

104-
@app.command(help="Containerize your package into a docker image inside the "
105-
"minikube cluster.")
105+
@app.command(
106+
help="Containerize your package into a docker image inside the minikube cluster."
107+
)
106108
def dockerize(
107109
project_path: Path = typer.Option(..., "--path", "-p", help="Path to your project"),
108-
image_name: str = typer.Option(DEFAULT_IMAGE_NAME, "--image-name", "-i",
109-
help=("Name of your image.")),
110+
image_name: str = typer.Option(
111+
DEFAULT_IMAGE_NAME, "--image-name", "-i", help=("Name of your image.")
112+
),
110113
):
111114
imports = load_imports()
112115
gaiaflow_path, user_project_path = imports.create_gaiaflow_context_path(
@@ -121,7 +124,7 @@ def dockerize(
121124
user_project_path=user_project_path,
122125
action=imports.ExtendedAction.DOCKERIZE,
123126
local=False,
124-
image_name=image_name
127+
image_name=image_name,
125128
)
126129

127130

src/gaiaflow/cli/commands/mlops.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
import fsspec
66
import typer
77

8-
from gaiaflow.constants import Service, DEFAULT_IMAGE_NAME
8+
from gaiaflow.constants import DEFAULT_IMAGE_NAME, Service
99

1010
app = typer.Typer()
1111
fs = fsspec.filesystem("file")
1212

1313

1414
def load_imports():
1515
from gaiaflow.constants import BaseAction, ExtendedAction
16-
from gaiaflow.managers.mlops_manager import MlopsManager
1716
from gaiaflow.managers.minikube_manager import MinikubeManager
18-
from gaiaflow.managers.utils import (create_gaiaflow_context_path,
19-
gaiaflow_path_exists_in_state,
20-
save_project_state)
17+
from gaiaflow.managers.mlops_manager import MlopsManager
18+
from gaiaflow.managers.utils import (
19+
create_gaiaflow_context_path,
20+
gaiaflow_path_exists_in_state,
21+
save_project_state,
22+
)
2123

2224
return SimpleNamespace(
2325
BaseAction=BaseAction,
@@ -56,11 +58,17 @@ def start(
5658
False, "--docker-build", "-b", help="Force Docker image build"
5759
),
5860
user_env_name: str = typer.Option(
59-
None, "--env", "-e", help="Provide conda/mamba environment name for "
60-
"Jupyter Lab to run. If not set, it will use the name from your environment.yml file."
61+
None,
62+
"--env",
63+
"-e",
64+
help="Provide conda/mamba environment name for "
65+
"Jupyter Lab to run. If not set, it will use the name from your environment.yml file.",
6166
),
6267
env_tool: "str" = typer.Option(
63-
"mamba", "--env-tool", "-t", help="Which tool to use for running your Jupyter lab. Options: mamba, conda",
68+
"mamba",
69+
"--env-tool",
70+
"-t",
71+
help="Which tool to use for running your Jupyter lab. Options: mamba, conda",
6472
),
6573
):
6674
imports = load_imports()
@@ -242,12 +250,12 @@ def cleanup(
242250
)
243251

244252

245-
246253
@app.command(help="Containerize your package into a docker image locally.")
247254
def dockerize(
248255
project_path: Path = typer.Option(..., "--path", "-p", help="Path to your project"),
249-
image_name: str = typer.Option(DEFAULT_IMAGE_NAME, "--image-name", "-i",
250-
help=("Name of your image.")),
256+
image_name: str = typer.Option(
257+
DEFAULT_IMAGE_NAME, "--image-name", "-i", help=("Name of your image.")
258+
),
251259
):
252260
imports = load_imports()
253261
gaiaflow_path, user_project_path = imports.create_gaiaflow_context_path(
@@ -268,15 +276,18 @@ def dockerize(
268276
user_project_path=user_project_path,
269277
action=imports.ExtendedAction.DOCKERIZE,
270278
local=True,
271-
image_name=image_name
279+
image_name=image_name,
272280
)
273281

274-
@app.command(help="Update the dependencies for the Airflow tasks. This command "
275-
"synchronizes the running container environments with the project's"
276-
"`environment.yml`. Make sure you have updated "
277-
"`environment.yml` before running"
278-
"this, as the container environments are updated based on "
279-
"its contents.")
282+
283+
@app.command(
284+
help="Update the dependencies for the Airflow tasks. This command "
285+
"synchronizes the running container environments with the project's"
286+
"`environment.yml`. Make sure you have updated "
287+
"`environment.yml` before running"
288+
"this, as the container environments are updated based on "
289+
"its contents."
290+
)
280291
def update_deps(
281292
project_path: Path = typer.Option(..., "--path", "-p", help="Path to your project"),
282293
):

src/gaiaflow/core/create_task.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from enum import Enum
22

3-
from .operators import (DevTaskOperator, DockerTaskOperator,
4-
ProdLocalTaskOperator, ProdTaskOperator)
3+
from .operators import (
4+
DevTaskOperator,
5+
DockerTaskOperator,
6+
ProdLocalTaskOperator,
7+
ProdTaskOperator,
8+
)
59

610

711
class GaiaflowMode(Enum):

src/gaiaflow/core/operators.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import platform
33
from datetime import datetime
44

5-
from airflow.providers.cncf.kubernetes.operators.pod import \
6-
KubernetesPodOperator
5+
from airflow.providers.cncf.kubernetes.operators.pod import KubernetesPodOperator
76
from airflow.providers.docker.operators.docker import DockerOperator
87
from airflow.providers.standard.operators.python import ExternalPythonOperator
9-
from kubernetes.client import V1ResourceRequirements
108

11-
from gaiaflow.constants import (DEFAULT_MINIO_AWS_ACCESS_KEY_ID,
12-
DEFAULT_MINIO_AWS_SECRET_ACCESS_KEY,
13-
RESOURCE_PROFILES)
9+
from gaiaflow.constants import (
10+
DEFAULT_MINIO_AWS_ACCESS_KEY_ID,
11+
DEFAULT_MINIO_AWS_SECRET_ACCESS_KEY,
12+
RESOURCE_PROFILES,
13+
)
1414

1515
from .utils import build_env_from_secrets, inject_params_as_env_vars
1616

@@ -128,8 +128,12 @@ def create_task(self):
128128

129129
args, kwargs = self.resolve_args_kwargs()
130130
kwargs["params"] = dict(self.params)
131-
op_kwargs = {"func_path": self.func_path, "args": args, "kwargs":
132-
kwargs, "current_dir": current_dir}
131+
op_kwargs = {
132+
"func_path": self.func_path,
133+
"args": args,
134+
"kwargs": kwargs,
135+
"current_dir": current_dir,
136+
}
133137

134138
def run_wrapper(**op_kwargs):
135139
import sys
@@ -206,17 +210,17 @@ def create_task(self):
206210
if profile is None:
207211
raise ValueError(f"Unknown resource profile: {profile_name}")
208212

209-
resources = V1ResourceRequirements(
210-
requests={
211-
"cpu": profile["request_cpu"],
212-
"memory": profile["request_memory"],
213-
},
214-
limits={
215-
"cpu": profile["limit_cpu"],
216-
"memory": profile["limit_memory"],
217-
# "gpu": profile.get["limit_gpu"],
218-
},
219-
)
213+
# resources = V1ResourceRequirements(
214+
# requests={
215+
# "cpu": profile["request_cpu"],
216+
# "memory": profile["request_memory"],
217+
# },
218+
# limits={
219+
# "cpu": profile["limit_cpu"],
220+
# "memory": profile["limit_memory"],
221+
# # "gpu": profile.get["limit_gpu"],
222+
# },
223+
# )
220224

221225
return KubernetesPodOperator(
222226
task_id=self.task_id,

src/gaiaflow/core/runner.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pickle
1010
from typing import Any
1111

12+
1213
def run(
1314
func_path: str | None = None,
1415
args: list | None = None,
@@ -39,30 +40,34 @@ def _extract_params_from_env(prefix="PARAMS_") -> dict[str, str]:
3940
if k.startswith(prefix)
4041
}
4142

42-
def _resolve_inputs(func_path: str, args: list[Any], kwargs: dict[Any],
43-
mode: str):
43+
44+
def _resolve_inputs(func_path: str, args: list[Any], kwargs: dict[Any], mode: str):
4445
if mode == "dev":
4546
return func_path, args or [], kwargs or {}
46-
else: # all other modes (dev_docker, prod_local and prod)
47+
else: # all other modes (dev_docker, prod_local and prod)
4748
func_path = os.environ.get("FUNC_PATH", func_path)
4849
args = json.loads(os.environ.get("FUNC_ARGS", "[]"))
4950
kwargs = json.loads(os.environ.get("FUNC_KWARGS", "{}"))
5051
kwargs["params"] = _extract_params_from_env()
5152
return func_path, args, kwargs
5253

54+
5355
def _import_function(func_path: str):
5456
import importlib
57+
5558
module_path, func_name = func_path.rsplit(":", 1)
5659
module = importlib.import_module(module_path)
5760
return getattr(module, func_name)
5861

62+
5963
def _write_result(result, mode):
6064
if mode == "prod" or mode == "prod_local":
6165
_write_xcom_result(result)
6266
if mode == "dev_docker":
6367
with open("/tmp/script.out", "wb+") as tmp:
6468
pickle.dump(result, tmp)
6569

70+
6671
def _write_xcom_result(result: Any) -> None:
6772
try:
6873
xcom_dir = "/airflow/xcom"

src/gaiaflow/core/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ def docker_network_gateway() -> str | None:
2828
if "Gateway" in line:
2929
match = re.search(r'"Gateway"\s*:\s*"([^"]+)"', line)
3030
if match:
31-
print(f"Docker network Gateway for Minikube is - "
32-
f"{match.group(1)}")
31+
print(f"Docker network Gateway for Minikube is - {match.group(1)}")
3332
return match.group(1)
3433
print("Is your minikube cluster running? Please run and try again.")
3534
return None
@@ -41,5 +40,6 @@ def docker_network_gateway() -> str | None:
4140
print("Docker command not found. Is Docker installed and in your PATH?")
4241
return None
4342

43+
4444
if __name__ == "__main__":
45-
docker_network_gateway()
45+
docker_network_gateway()

0 commit comments

Comments
 (0)