From acee95a0031f50e5812f99c50253b365248053dc Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Mon, 17 Apr 2023 02:32:28 +0200 Subject: [PATCH] dictscheme: rename from dataclass as it's confusing with builtin dataclasses --- config/scheme.py | 22 +++++++++++----------- config/state.py | 4 ++-- config/test_config.py | 2 +- devices/device.py | 6 +++--- devices/deviceinfo.py | 4 ++-- dataclass.py => dictscheme.py | 10 +++++----- distro/repo_config.py | 8 ++++---- flavours/flavour.py | 8 ++++---- packages/srcinfo_cache.py | 4 ++-- 9 files changed, 34 insertions(+), 34 deletions(-) rename dataclass.py => dictscheme.py (98%) diff --git a/config/scheme.py b/config/scheme.py index 9409661..a5846ba 100644 --- a/config/scheme.py +++ b/config/scheme.py @@ -3,11 +3,11 @@ from __future__ import annotations from munch import Munch from typing import Any, Optional, Mapping, Union -from dataclass import DataClass +from dictscheme import DictScheme from constants import Arch -class SparseProfile(DataClass): +class SparseProfile(DictScheme): parent: Optional[str] device: Optional[str] flavour: Optional[str] @@ -34,11 +34,11 @@ class Profile(SparseProfile): size_extra_mb: Union[str, int] -class WrapperSection(DataClass): +class WrapperSection(DictScheme): type: str # NOTE: rename to 'wrapper_type' if this causes problems -class BuildSection(DataClass): +class BuildSection(DictScheme): ccache: bool clean_mode: bool crosscompile: bool @@ -46,18 +46,18 @@ class BuildSection(DataClass): threads: int -class PkgbuildsSection(DataClass): +class PkgbuildsSection(DictScheme): git_repo: str git_branch: str -class PacmanSection(DataClass): +class PacmanSection(DictScheme): parallel_downloads: int check_space: bool repo_branch: str -class PathsSection(DataClass): +class PathsSection(DictScheme): cache_dir: str chroots: str pacman: str @@ -69,7 +69,7 @@ class PathsSection(DataClass): rust: str -class ProfilesSection(DataClass): +class ProfilesSection(DictScheme): current: str default: SparseProfile @@ -94,7 +94,7 @@ class ProfilesSection(DataClass): return f'{type(self)}{dict.__repr__(self.toDict())}' -class Config(DataClass): +class Config(DictScheme): wrapper: WrapperSection build: BuildSection pkgbuilds: PkgbuildsSection @@ -130,7 +130,7 @@ class Config(DataClass): return Config(_vals, validate=validate) -class RuntimeConfiguration(DataClass): +class RuntimeConfiguration(DictScheme): verbose: bool no_wrap: bool error_shell: bool @@ -142,7 +142,7 @@ class RuntimeConfiguration(DataClass): colors: Optional[bool] -class ConfigLoadState(DataClass): +class ConfigLoadState(DictScheme): load_finished: bool exception: Optional[Exception] diff --git a/config/state.py b/config/state.py index af4c743..2d1ba42 100644 --- a/config/state.py +++ b/config/state.py @@ -7,7 +7,7 @@ from typing import Mapping, Optional from constants import DEFAULT_PACKAGE_BRANCH -from .scheme import Config, ConfigLoadState, DataClass, Profile, RuntimeConfiguration +from .scheme import Config, ConfigLoadState, DictScheme, Profile, RuntimeConfiguration from .profile import PROFILE_DEFAULTS, PROFILE_DEFAULTS_DICT, resolve_profile CONFIG_DIR = appdirs.user_config_dir('kupfer') @@ -95,7 +95,7 @@ def merge_configs(conf_new: Mapping[str, dict], conf_base={}, warn_missing_defau continue logging.debug(f'Parsing config section "{outer_name}"') # check if outer_conf is a dict - if not (isinstance(outer_conf, (dict, DataClass))): + if not (isinstance(outer_conf, (dict, DictScheme))): parsed[outer_name] = outer_conf else: # init section diff --git a/config/test_config.py b/config/test_config.py index 6854cc8..b97ac1b 100644 --- a/config/test_config.py +++ b/config/test_config.py @@ -157,7 +157,7 @@ def test_config_save_modified(configstate_emptyfile: ConfigStateHolder): def get_config_scheme(data: dict[str, Any], validate=True, allow_incomplete=False) -> Config: """ helper func to ignore a false type error. - for some reason, mypy argues about DataClass.fromDict() instead of Config.fromDict() here + for some reason, mypy argues about DictScheme.fromDict() instead of Config.fromDict() here """ return Config.fromDict(data, validate=validate, allow_incomplete=allow_incomplete) # type: ignore[call-arg] diff --git a/devices/device.py b/devices/device.py index 9780a86..b53adbb 100644 --- a/devices/device.py +++ b/devices/device.py @@ -5,7 +5,7 @@ from typing import Optional from config.state import config from constants import Arch, ARCHES -from dataclass import DataClass +from dictscheme import DictScheme from distro.distro import get_kupfer_local from distro.package import LocalPackage from packages.pkgbuild import Pkgbuild, _pkgbuilds_cache, discover_pkgbuilds, get_pkgbuild_by_path, init_pkgbuilds @@ -22,7 +22,7 @@ DEVICE_DEPRECATIONS = { } -class DeviceSummary(DataClass): +class DeviceSummary(DictScheme): name: str description: str arch: str @@ -43,7 +43,7 @@ class DeviceSummary(DataClass): return separator.join([f"{color_str(name, bold=True, use_colors=colors)}: {value}" for name, value in fields.items()]) -class Device(DataClass): +class Device(DictScheme): name: str arch: Arch package: Pkgbuild diff --git a/devices/deviceinfo.py b/devices/deviceinfo.py index c8df9cf..b9acf3a 100644 --- a/devices/deviceinfo.py +++ b/devices/deviceinfo.py @@ -9,14 +9,14 @@ from typing import Any, Mapping, Optional from config.state import config from constants import Arch -from dataclass import DataClass +from dictscheme import DictScheme PMOS_ARCHES_OVERRIDES: dict[str, Arch] = { "armv7": 'armv7h', } -class DeviceInfo(DataClass): +class DeviceInfo(DictScheme): arch: Arch name: str manufacturer: str diff --git a/dataclass.py b/dictscheme.py similarity index 98% rename from dataclass.py rename to dictscheme.py index 6bd19df..25578bb 100644 --- a/dataclass.py +++ b/dictscheme.py @@ -45,7 +45,7 @@ def resolve_dict_hints(hints: Any) -> Generator[tuple[Any, ...], None, None]: continue -class DataClass(Munch): +class DictScheme(Munch): _type_hints: ClassVar[dict[str, Any]] _strip_hidden: ClassVar[bool] = False @@ -118,7 +118,7 @@ class DataClass(Munch): if not (optional and value is None): assert issubclass(target_class, Munch) # despite the above assert, mypy doesn't seem to understand target_class is a Munch here - kwargs = {'validate': validate} if issubclass(target_class, DataClass) else {} + kwargs = {'validate': validate} if issubclass(target_class, DictScheme) else {} value = target_class(value, **kwargs) # type:ignore[attr-defined] else: # print(f"nothing to do: '{key}' was already {target_class}) @@ -217,7 +217,7 @@ class DataClass(Munch): if not v: result[k] = {} continue - if isinstance(v, DataClass): + if isinstance(v, DictScheme): # pass None in sparse and strip_hidden result[k] = v.toDict(strip_hidden=strip_hidden, sparse=sparse) continue @@ -228,13 +228,13 @@ class DataClass(Munch): _subhints = {} _hints = resolve_type_hint(hints[k], [dict]) hints_flat = list(flatten_hints(_hints)) - subclass = DataClass + subclass = DictScheme for hint in hints_flat: if get_origin(hint) == dict: _valtype = get_args(hint)[1] _subhints = {n: _valtype for n in v.keys()} break - if isinstance(hint, type) and issubclass(hint, DataClass): + if isinstance(hint, type) and issubclass(hint, DictScheme): subclass = hint _subhints = hint._type_hints break diff --git a/distro/repo_config.py b/distro/repo_config.py index 34c55e6..e263bcf 100644 --- a/distro/repo_config.py +++ b/distro/repo_config.py @@ -10,7 +10,7 @@ from typing import ClassVar, Optional, Mapping, Union from config.state import config from constants import Arch, BASE_DISTROS, KUPFER_HTTPS, REPOS_CONFIG_FILE, REPOSITORIES -from dataclass import DataClass, toml_inline_dicts, TomlPreserveInlineDictEncoder +from dictscheme import DictScheme, toml_inline_dicts, TomlPreserveInlineDictEncoder from utils import sha256sum REPOS_KEY = 'repos' @@ -22,7 +22,7 @@ BASEDISTROS_KEY = 'base_distros' _current_config: Optional[ReposConfigFile] -class AbstrRepoConfig(DataClass): +class AbstrRepoConfig(DictScheme): options: Optional[dict[str, str]] _strip_hidden: ClassVar[bool] = True _sparse: ClassVar[bool] = True @@ -37,12 +37,12 @@ class RepoConfig(AbstrRepoConfig): local_only: Optional[bool] -class BaseDistro(DataClass): +class BaseDistro(DictScheme): remote_url: Optional[str] repos: dict[str, BaseDistroRepo] -class ReposConfigFile(DataClass): +class ReposConfigFile(DictScheme): remote_url: Optional[str] repos: dict[str, RepoConfig] base_distros: dict[Arch, BaseDistro] diff --git a/flavours/flavour.py b/flavours/flavour.py index c9a41a1..4272eca 100644 --- a/flavours/flavour.py +++ b/flavours/flavour.py @@ -8,12 +8,12 @@ from typing import Optional from config.state import config from constants import FLAVOUR_DESCRIPTION_PREFIX, FLAVOUR_INFO_FILE -from dataclass import DataClass +from dictscheme import DictScheme from packages.pkgbuild import discover_pkgbuilds, get_pkgbuild_by_name, init_pkgbuilds, Pkgbuild from utils import color_str -class FlavourInfo(DataClass): +class FlavourInfo(DictScheme): rootfs_size: int # rootfs size in GB description: Optional[str] @@ -21,7 +21,7 @@ class FlavourInfo(DataClass): return f'rootfs_size: {self.rootfs_size}' -class Flavour(DataClass): +class Flavour(DictScheme): name: str pkgbuild: Pkgbuild description: str @@ -53,7 +53,7 @@ class Flavour(DataClass): def get_lines(k, v, key_prefix=''): results = [] full_k = f'{key_prefix}.{k}' if key_prefix else k - if not isinstance(v, (dict, DataClass)): + if not isinstance(v, (dict, DictScheme)): results = [f'{color_str(full_k, bold=True)}: {v}'] else: for _k, _v in v.items(): diff --git a/packages/srcinfo_cache.py b/packages/srcinfo_cache.py index 112591f..5cb2373 100644 --- a/packages/srcinfo_cache.py +++ b/packages/srcinfo_cache.py @@ -9,14 +9,14 @@ from typing import Any, ClassVar, Optional from config.state import config from constants import MAKEPKG_CMD, SRCINFO_FILE, SRCINFO_METADATA_FILE, SRCINFO_INITIALISED_FILE -from dataclass import DataClass +from dictscheme import DictScheme from exec.cmd import run_cmd from utils import sha256sum SRCINFO_CHECKSUM_FILES = ['PKGBUILD', SRCINFO_FILE] -class JsonFile(DataClass): +class JsonFile(DictScheme): _filename: ClassVar[str] _relative_path: str