Skip to content

Commit

Permalink
linting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bcdurak committed Oct 8, 2024
1 parent cabcd77 commit 0ff1b5f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 40 deletions.
14 changes: 7 additions & 7 deletions src/mlstacks/analytics/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import logging
import os
from types import TracebackType
from typing import Any, Dict, List, Optional, Type, cast
from typing import Any, Optional, cast
from uuid import uuid4

import click
Expand All @@ -41,7 +41,7 @@
CONFIG_FILENAME = "config.yaml"


def on_error(error: Exception, batch: List[Dict[str, Any]]) -> None:
def on_error(error: Exception, batch: list[dict[str, Any]]) -> None:
"""Custom error handler for Segment analytics.
Args:
Expand Down Expand Up @@ -88,7 +88,7 @@ def __enter__(self) -> "MLStacksAnalyticsContext":

def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_type: Optional[type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
) -> bool:
Expand All @@ -109,7 +109,7 @@ def __exit__(
def track(
self,
event: AnalyticsEventsEnum,
properties: Optional[Dict[Any, Any]] = None,
properties: Optional[dict[Any, Any]] = None,
) -> Any:
"""Tracks event in Segment.
Expand Down Expand Up @@ -168,7 +168,7 @@ def set_analytics_user_id(user_id: str) -> None:

def track_event(
event: AnalyticsEventsEnum,
metadata: Optional[Dict[str, Any]] = None,
metadata: Optional[dict[str, Any]] = None,
) -> bool:
"""Track segment event if user opted-in.
Expand All @@ -195,7 +195,7 @@ class EventHandler:
def __init__(
self,
event: AnalyticsEventsEnum,
metadata: Optional[Dict[str, Any]] = None,
metadata: Optional[dict[str, Any]] = None,
):
"""Initialization of the context manager.
Expand All @@ -204,7 +204,7 @@ def __init__(
metadata: The metadata of the event.
"""
self.event: AnalyticsEventsEnum = event
self.metadata: Dict[str, Any] = metadata or {}
self.metadata: dict[str, Any] = metadata or {}

def __enter__(self) -> "EventHandler":
"""Enter function of the event handler.
Expand Down
4 changes: 1 addition & 3 deletions src/mlstacks/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# permissions and limitations under the License.
"""MLStacks constants."""

from typing import Dict, List

MLSTACKS_PACKAGE_NAME = "mlstacks"
MLSTACKS_INITIALIZATION_FILE_FLAG = "IGNORE_ME"
MLSTACKS_STACK_COMPONENT_FLAGS = [
Expand Down Expand Up @@ -41,7 +39,7 @@
"model_deployer": ["seldon"],
"step_operator": ["sagemaker", "vertex"],
}
ALLOWED_COMPONENT_TYPES: Dict[str, Dict[str, List[str]]] = {
ALLOWED_COMPONENT_TYPES: dict[str, dict[str, list[str]]] = {
"aws": {
"artifact_store": ["s3"],
"container_registry": ["aws"],
Expand Down
6 changes: 3 additions & 3 deletions src/mlstacks/models/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# permissions and limitations under the License.
"""Component model."""

from typing import Dict, Optional
from typing import Optional

from pydantic import BaseModel, field_validator, model_validator

Expand Down Expand Up @@ -43,8 +43,8 @@ class ComponentMetadata(BaseModel):
environment_variables: The environment variables for the component.
"""

config: Optional[Dict[str, str]] = None
environment_variables: Optional[Dict[str, str]] = None
config: Optional[dict[str, str]] = None
environment_variables: Optional[dict[str, str]] = None


class Component(BaseModel):
Expand Down
6 changes: 3 additions & 3 deletions src/mlstacks/models/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# permissions and limitations under the License.
"""Stack model."""

from typing import Dict, List, Optional
from typing import Optional

from pydantic import BaseModel, field_validator

Expand Down Expand Up @@ -46,11 +46,11 @@ class Stack(BaseModel):
name: str
provider: ProviderEnum
default_region: Optional[str] = None
default_tags: Optional[Dict[str, str]] = None
default_tags: Optional[dict[str, str]] = None
deployment_method: Optional[DeploymentMethodEnum] = (
DeploymentMethodEnum.KUBERNETES
)
components: List[Component] = []
components: list[Component] = []

@field_validator("name")
@classmethod
Expand Down
6 changes: 3 additions & 3 deletions src/mlstacks/utils/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""CLI utilities for mlstacks."""

from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, List, NoReturn, Optional, Union
from typing import TYPE_CHECKING, Any, NoReturn, Optional, Union

import click
from rich import box, table
Expand Down Expand Up @@ -138,7 +138,7 @@ def print_markdown_with_pager(text: str) -> None:


def print_table(
obj: List[Dict[str, Any]],
obj: list[dict[str, Any]],
title: Optional[str] = None,
caption: Optional[str] = None,
**columns: table.Column,
Expand Down Expand Up @@ -189,7 +189,7 @@ def print_table(


def pretty_print_output_vals(
output_vals: Dict[str, str],
output_vals: dict[str, str],
) -> None:
"""Prints dictionary values as a rich table.
Expand Down
32 changes: 16 additions & 16 deletions src/mlstacks/utils/terraform_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import shutil
import subprocess
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple, cast
from typing import Any, Optional, cast

import pkg_resources
import python_terraform
Expand Down Expand Up @@ -147,8 +147,8 @@ def _compose_enable_key(component: Component) -> str:


def parse_and_extract_component_variables(
components: List[Component],
) -> Dict[str, str]:
components: list[Component],
) -> dict[str, str]:
"""Parse component variables.
Args:
Expand Down Expand Up @@ -189,7 +189,7 @@ def parse_and_extract_component_variables(
return component_variables


def parse_and_extract_tf_vars(stack: Stack) -> Dict[str, Any]:
def parse_and_extract_tf_vars(stack: Stack) -> dict[str, Any]:
"""Parse Terraform variables.
Args:
Expand Down Expand Up @@ -228,8 +228,8 @@ def tf_definitions_present(

def include_files(
directory: str, # noqa: ARG001
filenames: List[str],
) -> List[str]:
filenames: list[str],
) -> list[str]:
"""Include files in Terraform definitions.
Args:
Expand Down Expand Up @@ -358,7 +358,7 @@ def populate_tf_definitions(
def get_recipe_metadata(
provider: ProviderEnum,
base_config_dir: str = CONFIG_DIR,
) -> Dict[str, Any]:
) -> dict[str, Any]:
"""Loads modular recipe metadata for a specific provider.
Args:
Expand Down Expand Up @@ -458,7 +458,7 @@ def _tf_client_init(
region: str,
debug: bool = False,
remote_state_bucket: Optional[str] = None,
) -> Tuple[Any, Any, Any]:
) -> tuple[Any, Any, Any]:
"""Initialize Terraform client.
Args:
Expand Down Expand Up @@ -506,9 +506,9 @@ def _tf_client_init(

def _tf_client_apply(
client: python_terraform.Terraform,
tf_vars: Dict[str, Any],
tf_vars: dict[str, Any],
debug: bool,
) -> Tuple[Any, Any, Any]:
) -> tuple[Any, Any, Any]:
"""Apply Terraform changes.
Args:
Expand Down Expand Up @@ -548,9 +548,9 @@ def _tf_client_apply(

def _tf_client_destroy(
client: python_terraform.Terraform,
tf_vars: Dict[str, Any],
tf_vars: dict[str, Any],
debug: bool,
) -> Tuple[Any, Any, Any]:
) -> tuple[Any, Any, Any]:
"""Destroy Terraform changes.
Args:
Expand Down Expand Up @@ -580,7 +580,7 @@ def _tf_client_output(
runner: TerraformRunner,
state_path: str,
output_key: Optional[str] = None,
) -> Dict[str, str]:
) -> dict[str, str]:
"""Get Terraform outputs.
Args:
Expand Down Expand Up @@ -658,7 +658,7 @@ def populate_remote_state_tf_definitions(
def write_remote_state_tf_variables(
bucket_name: str,
stack: Stack,
) -> Dict[str, str]:
) -> dict[str, str]:
"""Writes remote state variables to a json file.
Args:
Expand Down Expand Up @@ -968,7 +968,7 @@ def get_remote_state_bucket(stack_path: str) -> str:
def get_stack_outputs(
stack_path: str,
output_key: Optional[str] = None,
) -> Dict[str, str]:
) -> dict[str, str]:
"""Get stack outputs.
Args:
Expand Down Expand Up @@ -1023,7 +1023,7 @@ def verify_infracost_installed() -> bool:
return False


def _get_infracost_vars(variables: Dict[str, Any]) -> Dict[str, str]:
def _get_infracost_vars(variables: dict[str, Any]) -> dict[str, str]:
"""Get Infracost variables.
Args:
Expand Down
4 changes: 2 additions & 2 deletions src/mlstacks/utils/yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""Utility functions for loading YAML files into Python objects."""

from pathlib import Path
from typing import Any, Dict, Union
from typing import Any, Union

import yaml

Expand All @@ -25,7 +25,7 @@
from mlstacks.models.stack import Stack


def load_yaml_as_dict(path: Union[Path, str]) -> Dict[str, Any]:
def load_yaml_as_dict(path: Union[Path, str]) -> dict[str, Any]:
"""Loads a yaml file as a dictionary.
Args:
Expand Down
4 changes: 1 addition & 3 deletions src/mlstacks/utils/zenml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
# permissions and limitations under the License.
"""Utilities for mlstacks-ZenML interaction."""

from typing import List

from mlstacks.constants import ALLOWED_FLAVORS
from mlstacks.models.component import Component
from mlstacks.models.stack import Stack


def has_valid_flavor_combinations(
stack: Stack,
components: List[Component],
components: list[Component],
) -> bool:
"""Returns true if flavors have a valid combination.
Expand Down

0 comments on commit 0ff1b5f

Please sign in to comment.