mirror of
https://github.com/caelestia-dots/cli.git
synced 2026-06-07 15:59:28 -05:00
refactor: enforce stricter type hints (#91)
LSP was screaming at me so I decided to just address it to get it off my screen. + Fixed the type hints := Modified and added type hints for certain functions and variables in most of the files in the utils/ folder (and some in the subcommands/ folder) for clarity and so pyright's type checker wouldn't cry. :+ To resolve certain type issues, I had to add a bit more tiny additional code such as, additional checks if a variable is None, a tiny class in utils/material/generator.py to resolve the constructor usage mismatch between what the DynamicScheme accepts and what the code actually passes, and etc. - Renamed certain functions and variables for clarity and also for some to not collide with pre-existing definitions from well-known library imports. + PIL has reorganized their code a bit, so the code is made to reflect their new definitions. = Reorganized the single import statement for "colourfulness" in utils/wallpaper.py to be close to the top. (I think that's it) Side Effects?: Everything should work the same as no logic change was done whatsover (unless we consider the added if statements for type checking as a logic change). I've tested it, everything seems to be in urdir.
This commit is contained in:
@@ -4,41 +4,42 @@ import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
config_dir = Path(os.getenv("XDG_CONFIG_HOME", Path.home() / ".config"))
|
||||
data_dir = Path(os.getenv("XDG_DATA_HOME", Path.home() / ".local/share"))
|
||||
state_dir = Path(os.getenv("XDG_STATE_HOME", Path.home() / ".local/state"))
|
||||
cache_dir = Path(os.getenv("XDG_CACHE_HOME", Path.home() / ".cache"))
|
||||
pictures_dir = Path(os.getenv("XDG_PICTURES_DIR", Path.home() / "Pictures"))
|
||||
videos_dir = Path(os.getenv("XDG_VIDEOS_DIR", Path.home() / "Videos"))
|
||||
config_dir: Path = Path(os.getenv("XDG_CONFIG_HOME", Path.home() / ".config"))
|
||||
data_dir: Path = Path(os.getenv("XDG_DATA_HOME", Path.home() / ".local/share"))
|
||||
state_dir: Path = Path(os.getenv("XDG_STATE_HOME", Path.home() / ".local/state"))
|
||||
cache_dir: Path = Path(os.getenv("XDG_CACHE_HOME", Path.home() / ".cache"))
|
||||
pictures_dir: Path = Path(os.getenv("XDG_PICTURES_DIR", Path.home() / "Pictures"))
|
||||
videos_dir: Path = Path(os.getenv("XDG_VIDEOS_DIR", Path.home() / "Videos"))
|
||||
|
||||
c_config_dir = config_dir / "caelestia"
|
||||
c_data_dir = data_dir / "caelestia"
|
||||
c_state_dir = state_dir / "caelestia"
|
||||
c_cache_dir = cache_dir / "caelestia"
|
||||
c_config_dir: Path = config_dir / "caelestia"
|
||||
c_data_dir: Path = data_dir / "caelestia"
|
||||
c_state_dir: Path = state_dir / "caelestia"
|
||||
c_cache_dir: Path = cache_dir / "caelestia"
|
||||
|
||||
user_config_path = c_config_dir / "cli.json"
|
||||
cli_data_dir = Path(__file__).parent.parent / "data"
|
||||
templates_dir = cli_data_dir / "templates"
|
||||
user_templates_dir = c_config_dir / "templates"
|
||||
theme_dir = c_state_dir / "theme"
|
||||
user_config_path: Path = c_config_dir / "cli.json"
|
||||
cli_data_dir: Path = Path(__file__).parent.parent / "data"
|
||||
templates_dir: Path = cli_data_dir / "templates"
|
||||
user_templates_dir: Path = c_config_dir / "templates"
|
||||
theme_dir: Path = c_state_dir / "theme"
|
||||
|
||||
scheme_path = c_state_dir / "scheme.json"
|
||||
scheme_data_dir = cli_data_dir / "schemes"
|
||||
scheme_cache_dir = c_cache_dir / "schemes"
|
||||
scheme_path: Path = c_state_dir / "scheme.json"
|
||||
scheme_data_dir: Path = cli_data_dir / "schemes"
|
||||
scheme_cache_dir: Path = c_cache_dir / "schemes"
|
||||
|
||||
wallpapers_dir = os.getenv("CAELESTIA_WALLPAPERS_DIR", pictures_dir / "Wallpapers")
|
||||
wallpaper_path_path = c_state_dir / "wallpaper/path.txt"
|
||||
wallpaper_link_path = c_state_dir / "wallpaper/current"
|
||||
wallpaper_thumbnail_path = c_state_dir / "wallpaper/thumbnail.jpg"
|
||||
wallpapers_cache_dir = c_cache_dir / "wallpapers"
|
||||
wallpapers_dir: Path = Path(os.getenv("CAELESTIA_WALLPAPERS_DIR", pictures_dir / "Wallpapers"))
|
||||
wallpaper_path_path: Path = c_state_dir / "wallpaper/path.txt"
|
||||
wallpaper_link_path: Path = c_state_dir / "wallpaper/current"
|
||||
wallpaper_thumbnail_path: Path = c_state_dir / "wallpaper/thumbnail.jpg"
|
||||
wallpapers_cache_dir: Path = c_cache_dir / "wallpapers"
|
||||
|
||||
screenshots_dir = os.getenv("CAELESTIA_SCREENSHOTS_DIR", pictures_dir / "Screenshots")
|
||||
screenshots_cache_dir = c_cache_dir / "screenshots"
|
||||
screenshots_dir: Path = Path(os.getenv("CAELESTIA_SCREENSHOTS_DIR", pictures_dir / "Screenshots"))
|
||||
screenshots_cache_dir: Path = c_cache_dir / "screenshots"
|
||||
|
||||
recordings_dir = os.getenv("CAELESTIA_RECORDINGS_DIR", videos_dir / "Recordings")
|
||||
recording_path = c_state_dir / "record/recording.mp4"
|
||||
recording_notif_path = c_state_dir / "record/notifid.txt"
|
||||
recordings_dir: Path = Path(os.getenv("CAELESTIA_RECORDINGS_DIR", videos_dir / "Recordings"))
|
||||
recording_path: Path = c_state_dir / "record/recording.mp4"
|
||||
recording_notif_path: Path = c_state_dir / "record/notifid.txt"
|
||||
|
||||
|
||||
def compute_hash(path: Path | str) -> str:
|
||||
@@ -51,7 +52,7 @@ def compute_hash(path: Path | str) -> str:
|
||||
return sha.hexdigest()
|
||||
|
||||
|
||||
def atomic_dump(path: Path, content: dict[str, any]) -> None:
|
||||
def atomic_dump(path: Path, content: dict[str, Any]) -> None:
|
||||
with tempfile.NamedTemporaryFile("w") as f:
|
||||
json.dump(content, f)
|
||||
f.flush()
|
||||
|
||||
Reference in New Issue
Block a user