diff --git a/.github/workflows/coding-style.yml b/.github/workflows/coding-style.yml index c395b916..7c7ddb55 100644 --- a/.github/workflows/coding-style.yml +++ b/.github/workflows/coding-style.yml @@ -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" diff --git a/scanner/providers/implementations/themoviedatabase.py b/scanner/providers/implementations/themoviedatabase.py index 68844ec2..6cff79fa 100644 --- a/scanner/providers/implementations/themoviedatabase.py +++ b/scanner/providers/implementations/themoviedatabase.py @@ -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 diff --git a/scanner/pyproject.toml b/scanner/pyproject.toml index 10b2f40a..84e5d38b 100644 --- a/scanner/pyproject.toml +++ b/scanner/pyproject.toml @@ -1,4 +1,2 @@ -[tool.black] -extend-exclude = ''' -^/scanner/cache.py -''' +[tool.ruff.format] +indent-style = "tab" diff --git a/scanner/requirements.txt b/scanner/requirements.txt index 8dd09130..5a49dfae 100644 --- a/scanner/requirements.txt +++ b/scanner/requirements.txt @@ -1,5 +1,4 @@ guessit aiohttp jsons -black-with-tabs watchfiles diff --git a/scanner/scanner/cache.py b/scanner/scanner/cache.py index 706bca43..f9efbc24 100644 --- a/scanner/scanner/cache.py +++ b/scanner/scanner/cache.py @@ -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): """ @@ -18,8 +23,8 @@ def cache(ttl: timedelta, cache: Optional[Cache] = None, typed=False): result will be cached. Args: - typed: same as functools.lru_cache - ttl: how many time should the cached value be considered valid? + typed: same as functools.lru_cache + 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 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) diff --git a/scanner/scanner/monitor.py b/scanner/scanner/monitor.py index c9a5f753..7949541d 100644 --- a/scanner/scanner/monitor.py +++ b/scanner/scanner/monitor.py @@ -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) diff --git a/scanner/scanner/scanner.py b/scanner/scanner/scanner.py index 0fa1d616..54e169a7 100644 --- a/scanner/scanner/scanner.py +++ b/scanner/scanner/scanner.py @@ -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: diff --git a/shell.nix b/shell.nix index 9c0ff7c7..8b55b502 100644 --- a/shell.nix +++ b/shell.nix @@ -1,11 +1,10 @@ {pkgs ? import {}}: 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