Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jstzwj committed Oct 13, 2024
1 parent 8ee260c commit b8834cb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
14 changes: 7 additions & 7 deletions olah/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@


class OlahRule(object):
def __init__(self) -> None:
self.repo = ""
self.type = "*"
self.allow = False
self.use_re = False
def __init__(self, repo: str = "", type: str = "*", allow: bool = False, use_re: bool = False) -> None:
self.repo = repo
self.type = type
self.allow = allow
self.use_re = use_re

@staticmethod
def from_dict(data) -> "OlahRule":
def from_dict(data: Dict[str, Any]) -> "OlahRule":
out = OlahRule()
if "repo" in data:
out.repo = data["repo"]
Expand Down Expand Up @@ -59,7 +59,7 @@ def __init__(self) -> None:
self.rules: List[OlahRule] = []

@staticmethod
def from_list(data) -> "OlahRuleList":
def from_list(data: List[Dict[str, Any]]) -> "OlahRuleList":
out = OlahRuleList()
for item in data:
out.rules.append(OlahRule.from_dict(item))
Expand Down
2 changes: 1 addition & 1 deletion olah/mirror/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self) -> None:
self.siblings = None
self.createdAt = None

def to_dict(self):
def to_dict(self) -> Dict[str, Any]:
return {
"_id": self._id,
"id": self.id,
Expand Down
4 changes: 2 additions & 2 deletions olah/mirror/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _get_description(self, commit: Commit) -> str:
readme = self._get_readme(commit)
return self._remove_card(readme)

def _get_tree_filepaths_recursive(self, tree, include_dir=False) -> List[str]:
def _get_tree_filepaths_recursive(self, tree: Tree, include_dir: bool = False) -> List[str]:
out_paths = []
for entry in tree:
if entry.type == "tree":
Expand All @@ -80,7 +80,7 @@ def _get_tree_filepaths_recursive(self, tree, include_dir=False) -> List[str]:
def _get_commit_filepaths_recursive(self, commit: Commit) -> List[str]:
return self._get_tree_filepaths_recursive(commit.tree)

def _get_path_info(self, entry: IndexObjUnion, expand: bool=False) -> Dict[str, Union[int, str]]:
def _get_path_info(self, entry: IndexObjUnion, expand: bool = False) -> Dict[str, Union[int, str]]:
lfs = False
if entry.type != "tree":
t = "file"
Expand Down
10 changes: 5 additions & 5 deletions olah/proxy/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import shutil
import tempfile
from typing import Dict, Literal, Optional
from typing import Dict, Literal, Optional, AsyncGenerator, Union
from urllib.parse import urljoin
from fastapi import FastAPI, Request

Expand All @@ -20,7 +20,7 @@
from olah.utils.repo_utils import get_org_repo
from olah.utils.file_utils import make_dirs

async def _meta_cache_generator(save_path: str):
async def _meta_cache_generator(save_path: str) -> AsyncGenerator[Union[int, Dict[str, str], bytes], None]:
cache_rq = await read_cache_request(save_path)
yield cache_rq["headers"]
yield cache_rq["content"]
Expand All @@ -33,7 +33,7 @@ async def _meta_proxy_generator(
method: str,
allow_cache: bool,
save_path: str,
):
) -> AsyncGenerator[Union[int, Dict[str, str], bytes], None]:
async with httpx.AsyncClient(follow_redirects=True) as client:
content_chunks = []
async with client.stream(
Expand Down Expand Up @@ -61,7 +61,7 @@ async def _meta_proxy_generator(
save_path, response_status_code, response_headers, bytes(content)
)

# TODO: remove param `request`

async def meta_generator(
app: FastAPI,
repo_type: Literal["models", "datasets", "spaces"],
Expand All @@ -71,7 +71,7 @@ async def meta_generator(
override_cache: bool,
method: str,
authorization: Optional[str],
):
) -> AsyncGenerator[Union[int, Dict[str, str], bytes], None]:
headers = {}
if authorization is not None:
headers["authorization"] = authorization
Expand Down
8 changes: 4 additions & 4 deletions olah/proxy/pathsinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import json
import os
from typing import Dict, List, Literal, Optional
from typing import Dict, List, Literal, Optional, Tuple
from urllib.parse import quote, urljoin
from fastapi import FastAPI, Request

Expand All @@ -20,7 +20,7 @@
from olah.utils.file_utils import make_dirs


async def _pathsinfo_cache(save_path: str):
async def _pathsinfo_cache(save_path: str) -> Tuple[int, Dict[str, str], bytes]:
cache_rq = await read_cache_request(save_path)
return cache_rq["status_code"], cache_rq["headers"], cache_rq["content"]

Expand All @@ -33,7 +33,7 @@ async def _pathsinfo_proxy(
path: str,
allow_cache: bool,
save_path: str,
):
) -> Tuple[int, Dict[str, str], bytes]:
headers = {k: v for k, v in headers.items()}
if "content-length" in headers:
headers.pop("content-length")
Expand Down Expand Up @@ -67,7 +67,7 @@ async def pathsinfo_generator(
override_cache: bool,
method: str,
authorization: Optional[str],
):
) -> AsyncGenerator[Union[int, Dict[str, str], bytes], None]:
headers = {}
if authorization is not None:
headers["authorization"] = authorization
Expand Down
8 changes: 4 additions & 4 deletions olah/proxy/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# https://opensource.org/licenses/MIT.

import os
from typing import Dict, Literal, Mapping, Optional
from typing import Dict, Literal, Mapping, Optional, AsyncGenerator, Union
from urllib.parse import urljoin
from fastapi import FastAPI, Request

Expand All @@ -19,7 +19,7 @@
from olah.utils.file_utils import make_dirs


async def _tree_cache_generator(save_path: str):
async def _tree_cache_generator(save_path: str) -> AsyncGenerator[Union[int, Dict[str, str], bytes], None]:
cache_rq = await read_cache_request(save_path)
yield cache_rq["status_code"]
yield cache_rq["headers"]
Expand All @@ -33,7 +33,7 @@ async def _tree_proxy_generator(
params: Mapping[str, str],
allow_cache: bool,
save_path: str,
):
) -> AsyncGenerator[Union[int, Dict[str, str], bytes], None]:
async with httpx.AsyncClient(follow_redirects=True) as client:
content_chunks = []
async with client.stream(
Expand Down Expand Up @@ -77,7 +77,7 @@ async def tree_generator(
override_cache: bool,
method: str,
authorization: Optional[str],
):
) -> AsyncGenerator[Union[int, Dict[str, str], bytes], None]:
headers = {}
if authorization is not None:
headers["authorization"] = authorization
Expand Down

0 comments on commit b8834cb

Please sign in to comment.