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