Fix precommit check after moving to ruff (#927)

Lint check in main branch is failing. This fixes the lint check after we
moved to ruff in https://github.com/meta-llama/llama-stack/pull/921. We
need to move to a `ruff.toml` file as well as fixing and ignoring some
additional checks.

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>
This commit is contained in:
Yuan Tang 2025-02-02 09:46:45 -05:00 committed by GitHub
parent 4773092dd1
commit 34ab7a3b6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
217 changed files with 981 additions and 2681 deletions

View file

@ -10,9 +10,7 @@ from typing import List, Optional, Protocol
class KVStore(Protocol):
# TODO: make the value type bytes instead of str
async def set(
self, key: str, value: str, expiration: Optional[datetime] = None
) -> None: ...
async def set(self, key: str, value: str, expiration: Optional[datetime] = None) -> None: ...
async def get(self, key: str) -> Optional[str]: ...

View file

@ -54,16 +54,11 @@ class SqliteKVStoreConfig(CommonConfig):
)
@classmethod
def sample_run_config(
cls, __distro_dir__: str = "runtime", db_name: str = "kvstore.db"
):
def sample_run_config(cls, __distro_dir__: str = "runtime", db_name: str = "kvstore.db"):
return {
"type": "sqlite",
"namespace": None,
"db_path": "${env.SQLITE_STORE_DIR:~/.llama/"
+ __distro_dir__
+ "}/"
+ db_name,
"db_path": "${env.SQLITE_STORE_DIR:~/.llama/" + __distro_dir__ + "}/" + db_name,
}

View file

@ -28,11 +28,7 @@ class InmemoryKVStoreImpl(KVStore):
self._store[key] = value
async def range(self, start_key: str, end_key: str) -> List[str]:
return [
self._store[key]
for key in self._store.keys()
if key >= start_key and key < end_key
]
return [self._store[key] for key in self._store.keys() if key >= start_key and key < end_key]
async def kvstore_impl(config: KVStoreConfig) -> KVStore:

View file

@ -46,7 +46,6 @@ class PostgresKVStoreImpl(KVStore):
"""
)
except Exception as e:
log.exception("Could not connect to PostgreSQL database server")
raise RuntimeError("Could not connect to PostgreSQL database server") from e
@ -55,9 +54,7 @@ class PostgresKVStoreImpl(KVStore):
return key
return f"{self.config.namespace}:{key}"
async def set(
self, key: str, value: str, expiration: Optional[datetime] = None
) -> None:
async def set(self, key: str, value: str, expiration: Optional[datetime] = None) -> None:
key = self._namespaced_key(key)
self.cursor.execute(
f"""

View file

@ -25,9 +25,7 @@ class RedisKVStoreImpl(KVStore):
return key
return f"{self.config.namespace}:{key}"
async def set(
self, key: str, value: str, expiration: Optional[datetime] = None
) -> None:
async def set(self, key: str, value: str, expiration: Optional[datetime] = None) -> None:
key = self._namespaced_key(key)
await self.redis.set(key, value)
if expiration:
@ -66,9 +64,7 @@ class RedisKVStoreImpl(KVStore):
if matching_keys:
values = await self.redis.mget(matching_keys)
return [
value.decode("utf-8") if isinstance(value, bytes) else value
for value in values
if value is not None
value.decode("utf-8") if isinstance(value, bytes) else value for value in values if value is not None
]
return []

View file

@ -34,9 +34,7 @@ class SqliteKVStoreImpl(KVStore):
)
await db.commit()
async def set(
self, key: str, value: str, expiration: Optional[datetime] = None
) -> None:
async def set(self, key: str, value: str, expiration: Optional[datetime] = None) -> None:
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
f"INSERT OR REPLACE INTO {self.table_name} (key, value, expiration) VALUES (?, ?, ?)",
@ -46,9 +44,7 @@ class SqliteKVStoreImpl(KVStore):
async def get(self, key: str) -> Optional[str]:
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
f"SELECT value, expiration FROM {self.table_name} WHERE key = ?", (key,)
) as cursor:
async with db.execute(f"SELECT value, expiration FROM {self.table_name} WHERE key = ?", (key,)) as cursor:
row = await cursor.fetchone()
if row is None:
return None