Skip to content

Commit

Permalink
build: format codebase imports using ruff linter (meta-llama#1028)
Browse files Browse the repository at this point in the history
# What does this PR do?

- Configured ruff linter to automatically fix import sorting issues.
- Set --exit-non-zero-on-fix to ensure non-zero exit code when fixes are
applied.
- Enabled the 'I' selection to focus on import-related linting rules.
- Ran the linter, and formatted all codebase imports accordingly.
- Removed the black dep from the "dev" group since we use ruff

Signed-off-by: Sébastien Han <[email protected]>

[//]: # (If resolving an issue, uncomment and update the line below)
[//]: # (Closes #[issue-number])

## Test Plan
[Describe the tests you ran to verify your changes with result
summaries. *Provide clear instructions so the plan can be easily
re-executed.*]

[//]: # (## Documentation)
[//]: # (- [ ] Added a Changelog entry if the change is significant)

Signed-off-by: Sébastien Han <[email protected]>
  • Loading branch information
leseb authored and franciscojavierarceo committed Feb 14, 2025
1 parent 6407fbf commit c582059
Show file tree
Hide file tree
Showing 140 changed files with 138 additions and 242 deletions.
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.4
hooks:
# Run the linter with import sorting.
- id: ruff
args: [
--fix,
--exit-non-zero-on-fix
--exit-non-zero-on-fix,
--select, I,
]
- id: ruff-format

Expand Down
4 changes: 2 additions & 2 deletions llama_stack/apis/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
Literal,
Optional,
Protocol,
runtime_checkable,
Union,
runtime_checkable,
)

from llama_models.schema_utils import json_schema_type, register_schema, webmethod
from pydantic import BaseModel, ConfigDict, Field

from llama_stack.apis.common.content_types import ContentDelta, InterleavedContent, URL
from llama_stack.apis.common.content_types import URL, ContentDelta, InterleavedContent
from llama_stack.apis.inference import (
CompletionMessage,
ResponseFormat,
Expand Down
1 change: 0 additions & 1 deletion llama_stack/apis/agents/event_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from llama_stack.apis.agents import AgentTurnResponseEventType, StepType
from llama_stack.apis.common.content_types import ToolCallParseStatus
from llama_stack.apis.inference import ToolResponseMessage

from llama_stack.providers.utils.inference.prompt_adapter import (
interleaved_content_as_str,
)
Expand Down
1 change: 0 additions & 1 deletion llama_stack/apis/common/content_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import Annotated, List, Literal, Optional, Union

from llama_models.llama3.api.datatypes import ToolCall

from llama_models.schema_utils import json_schema_type, register_schema
from pydantic import BaseModel, Field, model_validator

Expand Down
1 change: 0 additions & 1 deletion llama_stack/apis/common/deployment_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import Any, Dict, Optional

from llama_models.schema_utils import json_schema_type

from pydantic import BaseModel

from llama_stack.apis.common.content_types import URL
Expand Down
2 changes: 1 addition & 1 deletion llama_stack/apis/scoring_functions/scoring_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
Literal,
Optional,
Protocol,
runtime_checkable,
Union,
runtime_checkable,
)

from llama_models.schema_utils import json_schema_type, register_schema, webmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
# the root directory of this source tree.

from enum import Enum

from typing import Any, Dict, List, Optional, Protocol, Union

from llama_models.schema_utils import json_schema_type, webmethod

from pydantic import BaseModel

from llama_stack.apis.inference import Message
Expand Down
2 changes: 1 addition & 1 deletion llama_stack/apis/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.

from .tools import * # noqa: F401 F403
from .rag_tool import * # noqa: F401 F403
from .tools import * # noqa: F401 F403
2 changes: 1 addition & 1 deletion llama_stack/apis/tools/rag_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pydantic import BaseModel, Field
from typing_extensions import Annotated, Protocol, runtime_checkable

from llama_stack.apis.common.content_types import InterleavedContent, URL
from llama_stack.apis.common.content_types import URL, InterleavedContent
from llama_stack.providers.utils.telemetry.trace_protocol import trace_protocol


Expand Down
2 changes: 1 addition & 1 deletion llama_stack/apis/tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pydantic import BaseModel, Field
from typing_extensions import Protocol, runtime_checkable

from llama_stack.apis.common.content_types import InterleavedContent, URL
from llama_stack.apis.common.content_types import URL, InterleavedContent
from llama_stack.apis.resource import Resource, ResourceType
from llama_stack.providers.utils.telemetry.trace_protocol import trace_protocol

Expand Down
2 changes: 0 additions & 2 deletions llama_stack/cli/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
from typing import Dict, List, Optional

import httpx

from llama_models.datatypes import Model
from llama_models.sku_list import LlamaDownloadInfo
from pydantic import BaseModel, ConfigDict

from rich.console import Console
from rich.progress import (
BarColumn,
Expand Down
1 change: 0 additions & 1 deletion llama_stack/cli/model/describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import json

from llama_models.sku_list import resolve_model

from termcolor import colored

from llama_stack.cli.subcommand import Subcommand
Expand Down
1 change: 0 additions & 1 deletion llama_stack/cli/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from llama_stack.cli.model.list import ModelList
from llama_stack.cli.model.prompt_format import ModelPromptFormat
from llama_stack.cli.model.verify_download import ModelVerifyDownload

from llama_stack.cli.subcommand import Subcommand


Expand Down
2 changes: 1 addition & 1 deletion llama_stack/cli/model/prompt_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import textwrap
from io import StringIO

from llama_models.datatypes import CoreModelId, is_multimodal, model_family, ModelFamily
from llama_models.datatypes import CoreModelId, ModelFamily, is_multimodal, model_family

from llama_stack.cli.subcommand import Subcommand

Expand Down
1 change: 0 additions & 1 deletion llama_stack/cli/model/safety_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from llama_models.datatypes import CheckpointQuantizationFormat
from llama_models.llama3.api.datatypes import SamplingParams
from llama_models.sku_list import LlamaDownloadInfo

from pydantic import BaseModel, ConfigDict, Field


Expand Down
5 changes: 2 additions & 3 deletions llama_stack/cli/stack/_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
from termcolor import cprint

from llama_stack.cli.table import print_table

from llama_stack.distribution.build import (
SERVER_DEPENDENCIES,
ImageType,
build_image,
get_provider_dependencies,
ImageType,
SERVER_DEPENDENCIES,
)
from llama_stack.distribution.datatypes import (
BuildConfig,
Expand Down
1 change: 1 addition & 0 deletions llama_stack/cli/tests/test_stack_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pytest
import yaml

from llama_stack.distribution.configure import (
LLAMA_STACK_RUN_CONFIG_VERSION,
parse_and_maybe_upgrade_config,
Expand Down
4 changes: 0 additions & 4 deletions llama_stack/distribution/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@
import logging
import sys
from enum import Enum

from pathlib import Path
from typing import Dict, List

from pydantic import BaseModel
from termcolor import cprint

from llama_stack.distribution.datatypes import BuildConfig, Provider

from llama_stack.distribution.distribution import get_provider_registry

from llama_stack.distribution.utils.config_dirs import BUILDS_BASE_DIR

from llama_stack.distribution.utils.exec import run_command, run_with_pty
from llama_stack.providers.datatypes import Api

Expand Down
4 changes: 1 addition & 3 deletions llama_stack/distribution/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
# the root directory of this source tree.

import inspect

import json
from collections.abc import AsyncIterator
from enum import Enum
from typing import Any, get_args, get_origin, Type, Union
from typing import Any, Type, Union, get_args, get_origin

import httpx
from pydantic import BaseModel, parse_obj_as
from termcolor import cprint

from llama_stack.apis.version import LLAMA_STACK_API_VERSION

from llama_stack.providers.datatypes import RemoteProviderConfig

_CLIENT_CLASSES = {}
Expand Down
4 changes: 1 addition & 3 deletions llama_stack/distribution/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
# the root directory of this source tree.
import logging
import textwrap

from typing import Any, Dict

from llama_stack.distribution.datatypes import (
DistributionSpec,
LLAMA_STACK_RUN_CONFIG_VERSION,
DistributionSpec,
Provider,
StackRunConfig,
)
Expand All @@ -20,7 +19,6 @@
)
from llama_stack.distribution.utils.dynamic import instantiate_class_type
from llama_stack.distribution.utils.prompt_for_config import prompt_for_config

from llama_stack.providers.datatypes import Api, ProviderSpec

logger = logging.getLogger(__name__)
Expand Down
24 changes: 12 additions & 12 deletions llama_stack/distribution/library_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@
from concurrent.futures import ThreadPoolExecutor
from enum import Enum
from pathlib import Path
from typing import Any, get_args, get_origin, Optional, TypeVar
from typing import Any, Optional, TypeVar, get_args, get_origin

import httpx
import yaml
from llama_stack_client import (
NOT_GIVEN,
APIResponse,
AsyncAPIResponse,
AsyncLlamaStackClient,
AsyncStream,
LlamaStackClient,
)
from pydantic import BaseModel, TypeAdapter
from rich.console import Console
from termcolor import cprint

from llama_stack.distribution.build import print_pip_install_help
from llama_stack.distribution.configure import parse_and_maybe_upgrade_config
Expand All @@ -35,17 +46,6 @@
setup_logger,
start_trace,
)
from llama_stack_client import (
APIResponse,
AsyncAPIResponse,
AsyncLlamaStackClient,
AsyncStream,
LlamaStackClient,
NOT_GIVEN,
)
from pydantic import BaseModel, TypeAdapter
from rich.console import Console
from termcolor import cprint

T = TypeVar("T")

Expand Down
1 change: 0 additions & 1 deletion llama_stack/distribution/routers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import Any, Dict

from llama_stack.distribution.datatypes import RoutedProtocol

from llama_stack.distribution.store import DistributionRegistry
from llama_stack.providers.datatypes import Api, RoutingTable

Expand Down
2 changes: 1 addition & 1 deletion llama_stack/distribution/routers/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from typing import Any, AsyncGenerator, Dict, List, Optional

from llama_stack.apis.common.content_types import InterleavedContent, URL
from llama_stack.apis.common.content_types import URL, InterleavedContent
from llama_stack.apis.datasetio import DatasetIO, PaginatedRowsResult
from llama_stack.apis.eval import (
AppEvalTaskConfig,
Expand Down
3 changes: 0 additions & 3 deletions llama_stack/distribution/server/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
from pydantic import BaseModel

from llama_stack.apis.tools import RAGToolRuntime, SpecialToolGroup

from llama_stack.apis.version import LLAMA_STACK_API_VERSION

from llama_stack.distribution.resolver import api_protocol_map

from llama_stack.providers.datatypes import Api


Expand Down
5 changes: 3 additions & 2 deletions llama_stack/distribution/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import argparse
import asyncio
import functools
import logging
import inspect
import json
import logging
import os
import signal
import sys
Expand All @@ -21,7 +21,8 @@
from typing import Any, List, Union

import yaml
from fastapi import Body, FastAPI, HTTPException, Path as FastapiPath, Request
from fastapi import Body, FastAPI, HTTPException, Request
from fastapi import Path as FastapiPath
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse, StreamingResponse
from pydantic import BaseModel, ValidationError
Expand Down
2 changes: 1 addition & 1 deletion llama_stack/distribution/store/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import pytest
import pytest_asyncio

from llama_stack.apis.inference import Model
from llama_stack.apis.vector_dbs import VectorDB

from llama_stack.distribution.store.registry import (
CachedDiskDistributionRegistry,
DiskDistributionRegistry,
Expand Down
1 change: 0 additions & 1 deletion llama_stack/distribution/ui/modules/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# the root directory of this source tree.

import os

from typing import Optional

from llama_stack_client import LlamaStackClient
Expand Down
1 change: 0 additions & 1 deletion llama_stack/distribution/ui/page/distribution/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from page.distribution.scoring_functions import scoring_functions
from page.distribution.shields import shields
from page.distribution.vector_dbs import vector_dbs

from streamlit_option_menu import option_menu


Expand Down
1 change: 0 additions & 1 deletion llama_stack/distribution/ui/page/evaluations/app_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import pandas as pd
import streamlit as st

from modules.api import llama_stack_api
from modules.utils import process_dataset

Expand Down
2 changes: 0 additions & 2 deletions llama_stack/distribution/ui/page/evaluations/native_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import json

import pandas as pd

import streamlit as st

from modules.api import llama_stack_api


Expand Down
1 change: 0 additions & 1 deletion llama_stack/distribution/ui/page/playground/rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from llama_stack_client.lib.agents.event_logger import EventLogger
from llama_stack_client.types.agent_create_params import AgentConfig
from llama_stack_client.types.memory_insert_params import Document

from modules.api import llama_stack_api
from modules.utils import data_url_from_file

Expand Down
1 change: 0 additions & 1 deletion llama_stack/distribution/utils/config_dirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
from pathlib import Path


LLAMA_STACK_CONFIG_DIR = Path(os.getenv("LLAMA_STACK_CONFIG_DIR", os.path.expanduser("~/.llama/")))

DISTRIBS_BASE_DIR = LLAMA_STACK_CONFIG_DIR / "distributions"
Expand Down
4 changes: 1 addition & 3 deletions llama_stack/distribution/utils/prompt_for_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import json
import logging
from enum import Enum

from typing import Any, get_args, get_origin, List, Literal, Optional, Type, Union
from typing import Any, List, Literal, Optional, Type, Union, get_args, get_origin

from pydantic import BaseModel
from pydantic.fields import FieldInfo
from pydantic_core import PydanticUndefinedType

from typing_extensions import Annotated

log = logging.getLogger(__name__)
Expand Down
Loading

0 comments on commit c582059

Please sign in to comment.