mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-08 10:44:20 -04:00
Migrate to ruff
This commit is contained in:
parent
898e7b272e
commit
2db6255fae
7
.github/workflows/coding-style.yml
vendored
7
.github/workflows/coding-style.yml
vendored
@ -47,10 +47,9 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Run black
|
||||
run: |
|
||||
pip3 install black-with-tabs
|
||||
black . --check
|
||||
- uses: chartboost/ruff-action@v1
|
||||
with:
|
||||
args: format --check
|
||||
|
||||
transcoder:
|
||||
name: "Lint transcoder"
|
||||
|
@ -18,7 +18,6 @@ from ..types.studio import Studio
|
||||
from ..types.genre import Genre
|
||||
from ..types.metadataid import MetadataID
|
||||
from ..types.show import Show, ShowTranslation, Status as ShowStatus
|
||||
from ..types.season import Season
|
||||
from ..types.collection import Collection, CollectionTranslation
|
||||
|
||||
|
||||
|
@ -1,4 +1,2 @@
|
||||
[tool.black]
|
||||
extend-exclude = '''
|
||||
^/scanner/cache.py
|
||||
'''
|
||||
[tool.ruff.format]
|
||||
indent-style = "tab"
|
||||
|
@ -1,5 +1,4 @@
|
||||
guessit
|
||||
aiohttp
|
||||
jsons
|
||||
black-with-tabs
|
||||
watchfiles
|
||||
|
@ -4,12 +4,17 @@ from functools import wraps
|
||||
from typing import Any, Optional, Tuple, Final, Literal
|
||||
from enum import Enum
|
||||
|
||||
|
||||
# Waiting for https://github.com/python/typing/issues/689 for better sentinels
|
||||
class Sentinel(Enum):
|
||||
NoneSentinel = 0
|
||||
|
||||
|
||||
none: Final = Sentinel.NoneSentinel
|
||||
type Cache = dict[Any, Tuple[asyncio.Event | Literal[none], datetime | Literal[none], Any]]
|
||||
type Cache = dict[
|
||||
Any, Tuple[asyncio.Event | Literal[none], datetime | Literal[none], Any]
|
||||
]
|
||||
|
||||
|
||||
def cache(ttl: timedelta, cache: Optional[Cache] = None, typed=False):
|
||||
"""
|
||||
@ -41,11 +46,7 @@ def cache(ttl: timedelta, cache: Optional[Cache] = None, typed=False):
|
||||
return await wrapper(*args, **kwargs)
|
||||
return ret[2]
|
||||
# Return the cached result if it exits and is not expired
|
||||
if (
|
||||
ret[2] != none
|
||||
and ret[1] != none
|
||||
and datetime.now() - ret[1] < ttl
|
||||
):
|
||||
if ret[2] != none and ret[1] != none and datetime.now() - ret[1] < ttl:
|
||||
return ret[2]
|
||||
|
||||
return await exec_as_cache(cache, key, lambda: f(*args, **kwargs))
|
||||
@ -54,6 +55,7 @@ def cache(ttl: timedelta, cache: Optional[Cache] = None, typed=False):
|
||||
|
||||
return wrap
|
||||
|
||||
|
||||
async def exec_as_cache(cache: Cache, key, f):
|
||||
event = asyncio.Event()
|
||||
cache[key] = (event, none, none)
|
||||
|
@ -6,7 +6,7 @@ from .scanner import Scanner
|
||||
|
||||
async def monitor(path: str, scanner: Scanner):
|
||||
async for changes in awatch(path):
|
||||
for (event, file) in changes:
|
||||
for event, file in changes:
|
||||
try:
|
||||
if event == Change.added:
|
||||
await scanner.identify(file)
|
||||
|
@ -82,7 +82,7 @@ class Scanner:
|
||||
|
||||
raw = guessit(path, {"episode_prefer_number": True, "excludes": "language"})
|
||||
|
||||
if not "mimetype" in raw or not raw["mimetype"].startswith("video"):
|
||||
if "mimetype" not in raw or not raw["mimetype"].startswith("video"):
|
||||
return
|
||||
# Remove seasons in "One Piece (1999) 152.mkv" for example
|
||||
if raw.get("season") == raw.get("year") and "season" in raw:
|
||||
|
@ -1,11 +1,10 @@
|
||||
{pkgs ? import <nixpkgs> {}}: let
|
||||
python = pkgs.python312.withPackages (ps:
|
||||
python = pkgs.python311.withPackages (ps:
|
||||
with ps; [
|
||||
guessit
|
||||
aiohttp
|
||||
jsons
|
||||
watchfiles
|
||||
black
|
||||
]);
|
||||
dotnet = with pkgs.dotnetCorePackages;
|
||||
combinePackages [
|
||||
@ -20,8 +19,9 @@ in
|
||||
nodePackages.eas-cli
|
||||
nodePackages.expo-cli
|
||||
dotnet
|
||||
# csharpier
|
||||
# python
|
||||
csharpier
|
||||
python
|
||||
ruff
|
||||
go
|
||||
wgo
|
||||
mediainfo
|
||||
|
Loading…
x
Reference in New Issue
Block a user