diff --git a/dataclass.py b/dataclass.py index 53d44fc..bed0473 100644 --- a/dataclass.py +++ b/dataclass.py @@ -59,7 +59,13 @@ class DataClass(Munch): self.update(d | kwargs, validate=validate) @classmethod - def transform(cls, values: Mapping[str, Any], validate: bool = True, allow_extra: bool = False, type_hints: Optional[dict[str, Any]] = None) -> Any: + def transform( + cls, + values: Mapping[str, Any], + validate: bool = True, + allow_extra: bool = False, + type_hints: Optional[dict[str, Any]] = None, + ) -> Any: results = {} values = dict(values) print(f"\ntransform function:\n{values}, {type_hints=}") @@ -89,7 +95,8 @@ class DataClass(Munch): key_type, value_type = dict_hints[0] if not isinstance(value, Mapping): if validate: - raise Exception(f"Got non-mapping {value!r} for expected dict type: {key_type} => {value_type}. Allowed classes: {_classes}") + raise Exception( + f"Got non-mapping {value!r} for expected dict type: {key_type} => {value_type}. Allowed classes: {_classes}") print(f"Got non-mapping {value!r} for expected dict type: {key_type} => {value_type}. Allowed classes: {_classes}") results[key] = value continue @@ -264,7 +271,7 @@ class DataClass(Munch): self, strip_hidden: Optional[bool] = None, sparse: Optional[bool] = None, - **yaml_args + **yaml_args, ) -> str: import yaml yaml_args = {'sort_keys': False} | yaml_args @@ -274,10 +281,10 @@ class DataClass(Munch): ) def toToml( - self, - strip_hidden: Optional[bool] = None, - sparse: Optional[bool] = None, - encoder: Optional[TomlEncoder] = TomlPreserveInlineDictEncoder() + self, + strip_hidden: Optional[bool] = None, + sparse: Optional[bool] = None, + encoder: Optional[TomlEncoder] = TomlPreserveInlineDictEncoder(), ) -> str: return toml.dumps( self.toDict(strip_hidden=strip_hidden, sparse=sparse), diff --git a/distro/distro.py b/distro/distro.py index 5f820b6..06f43aa 100644 --- a/distro/distro.py +++ b/distro/distro.py @@ -1,7 +1,7 @@ from enum import IntFlag from typing import Generic, Mapping, Optional, TypeVar -from constants import Arch, ARCHES, BASE_DISTROS, REPOSITORIES, KUPFER_BRANCH_MARKER, KUPFER_HTTPS, CHROOT_PATHS +from constants import Arch, ARCHES, REPOSITORIES, KUPFER_BRANCH_MARKER, KUPFER_HTTPS, CHROOT_PATHS from generator import generate_pacman_conf_body from config.state import config @@ -211,4 +211,3 @@ def get_kupfer_local(arch: Optional[Arch] = None, in_chroot: bool = True, scan: d = get_kupfer_distro(arch, location=DistroLocation.CHROOT if in_chroot else DistroLocation.LOCAL, scan=scan) assert isinstance(d, LocalDistro) return d - diff --git a/distro/repo_config.py b/distro/repo_config.py index 96116b5..ed2cc58 100644 --- a/distro/repo_config.py +++ b/distro/repo_config.py @@ -6,14 +6,13 @@ import toml import yaml from copy import deepcopy -from typing import Any, ClassVar, Optional, Mapping +from typing import ClassVar, Optional, Mapping from config.state import config from constants import Arch, BASE_DISTROS, KUPFER_HTTPS, REPOS_CONFIG_FILE, REPOSITORIES -from dataclass import DataClass, Munch, toml_inline_dicts, TomlEncoder, TomlPreserveInlineDictEncoder +from dataclass import DataClass, toml_inline_dicts, TomlPreserveInlineDictEncoder from utils import sha256sum - REPOS_KEY = 'repos' REMOTEURL_KEY = 'remote_url' LOCALONLY_KEY = 'local_only' @@ -56,10 +55,7 @@ class ReposConfigFile(DataClass): super().__init__(d=d, **kwargs) for repo_cls, defaults, repos, remote_url in [ (RepoConfig, REPO_DEFAULTS, self.get(REPOS_KEY, {}), d.get(REMOTEURL_KEY, None)), - *[ - (BaseDistroRepo, BASE_DISTRO_DEFAULTS, _distro.repos, _distro.get(REMOTEURL_KEY, None)) - for _distro in self.base_distros.values() - ], + *[(BaseDistroRepo, BASE_DISTRO_DEFAULTS, _distro.repos, _distro.get(REMOTEURL_KEY, None)) for _distro in self.base_distros.values()], ]: if repos is None: continue @@ -84,7 +80,7 @@ class ReposConfigFile(DataClass): def toToml(self, strip_hidden=None, sparse=None, encoder=TomlPreserveInlineDictEncoder()): d = self.toDict(strip_hidden=strip_hidden, sparse=sparse) - for key in [REPOS_KEY, ]: + for key in [REPOS_KEY]: if key not in d or not isinstance(d[key], Mapping): continue inline = {name: {k: toml_inline_dicts(v) for k, v in value.items()} for name, value in d[key].items()} @@ -92,33 +88,13 @@ class ReposConfigFile(DataClass): d[key] = inline return toml.dumps(d, encoder=encoder) - def toToml_old(self, **kwargs): - """Dumps specific TOML format, kwargs are ignored.""" - def toml_line(k, v): - assert isinstance(k, str) - if isinstance(v, dict): - assert isinstance(v, Munch) - return f'{k} = ' + v.toYAML(default_flow_style=True).strip('\n') - #return toml.dumps({k: (v if not isinstance(v, dict) else toml.}, encoder=toml.encoder.TomlPreserveInlineDictEncoder).strip('\n') - - res = '' - for k in self.keys(): - if k == REPOS_KEY: - continue - res - - for k, v in self.repos.items(): - res += f"[repos.{k}]\n" - for subk, subv in v.items(): - res += toml_line(subk, subv) + '\n' - res += '\n' - return res - REPO_DEFAULTS = { LOCALONLY_KEY: None, REMOTEURL_KEY: None, - OPTIONS_KEY: {'SigLevel': 'Never'} + OPTIONS_KEY: { + 'SigLevel': 'Never' + }, } BASE_DISTRO_DEFAULTS = { @@ -131,15 +107,16 @@ REPOS_CONFIG_DEFAULT = ReposConfigFile({ '_checksum': None, REMOTEURL_KEY: KUPFER_HTTPS, REPOS_KEY: { - 'local': REPO_DEFAULTS | {LOCALONLY_KEY: True}, + 'local': REPO_DEFAULTS | { + LOCALONLY_KEY: True + }, **{r: deepcopy(REPO_DEFAULTS) for r in REPOSITORIES}, }, - BASEDISTROS_KEY: { - arch: { - 'repos': {k: {'remote_url': v} for k, v in arch_def['repos'].items()}, - } - for arch, arch_def in BASE_DISTROS.items() - }, + BASEDISTROS_KEY: {arch: { + 'repos': {k: { + 'remote_url': v + } for k, v in arch_def['repos'].items()}, + } for arch, arch_def in BASE_DISTROS.items()}, }) _current_config = None diff --git a/packages/cli.py b/packages/cli.py index 343179b..e5ff9a1 100644 --- a/packages/cli.py +++ b/packages/cli.py @@ -187,6 +187,7 @@ def cmd_init( for arch in ARCHES: init_prebuilts(arch) + @cmd_packages.command(name='build') @click.option('--force', is_flag=True, default=False, help='Rebuild even if package is already built') @click.option('--arch', default=None, required=False, type=click.Choice(ARCHES), help="The CPU architecture to build for")