diff options
author | 2023-01-14 23:59:29 -0800 | |
---|---|---|
committer | 2023-02-02 21:59:11 +0200 | |
commit | 2c03223768fb522a85b410db382d3e9f53575666 (patch) | |
tree | 1cb9eb666a86c9e447ade10e6b069f712f4d1e92 | |
parent | refactor(config): adding typing to config hints along with immutability. (diff) | |
download | pkgcore-2c03223768fb522a85b410db382d3e9f53575666.tar.gz pkgcore-2c03223768fb522a85b410db382d3e9f53575666.tar.bz2 pkgcore-2c03223768fb522a85b410db382d3e9f53575666.zip |
refactor(config): Remove ConfigHint/configurable positional arg support
This never made much sense in light of how args were handled,
and it complicates the heck out of typing, thus require invokers
to be explicit.
Signed-off-by: Brian Harring <ferringb@gmail.com>
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | src/pkgcore/binpkg/repository.py | 2 | ||||
-rw-r--r-- | src/pkgcore/cache/flat_hash.py | 7 | ||||
-rw-r--r-- | src/pkgcore/config/basics.py | 4 | ||||
-rw-r--r-- | src/pkgcore/config/hint.py | 4 | ||||
-rw-r--r-- | src/pkgcore/ebuild/domain.py | 2 | ||||
-rw-r--r-- | src/pkgcore/ebuild/eclass_cache.py | 4 | ||||
-rw-r--r-- | src/pkgcore/ebuild/portage_conf.py | 2 | ||||
-rw-r--r-- | src/pkgcore/ebuild/profiles.py | 4 | ||||
-rw-r--r-- | src/pkgcore/ebuild/repository.py | 5 | ||||
-rw-r--r-- | src/pkgcore/fetch/custom.py | 2 | ||||
-rw-r--r-- | src/pkgcore/pkgsets/filelist.py | 2 | ||||
-rw-r--r-- | src/pkgcore/pkgsets/glsa.py | 4 | ||||
-rw-r--r-- | src/pkgcore/pkgsets/installed.py | 4 | ||||
-rw-r--r-- | src/pkgcore/pkgsets/system.py | 4 | ||||
-rw-r--r-- | src/pkgcore/repository/multiplex.py | 2 | ||||
-rw-r--r-- | src/pkgcore/sync/base.py | 8 | ||||
-rw-r--r-- | src/pkgcore/sync/rsync.py | 2 | ||||
-rw-r--r-- | src/pkgcore/vdb/ondisk.py | 2 | ||||
-rw-r--r-- | tests/config/test_basics.py | 2 | ||||
-rw-r--r-- | tests/config/test_central.py | 22 | ||||
-rw-r--r-- | tests/scripts/test_pconfig.py | 3 | ||||
-rw-r--r-- | tests/scripts/test_pebuild.py | 2 | ||||
-rw-r--r-- | tests/scripts/test_pmaint.py | 2 | ||||
-rw-r--r-- | tests/scripts/test_pquery.py | 2 |
24 files changed, 55 insertions, 42 deletions
diff --git a/src/pkgcore/binpkg/repository.py b/src/pkgcore/binpkg/repository.py index 9a6e7870..549d50b7 100644 --- a/src/pkgcore/binpkg/repository.py +++ b/src/pkgcore/binpkg/repository.py @@ -205,7 +205,7 @@ class tree(prototype.tree): cache_name = "Packages" pkgcore_config_type = ConfigHint( - {"location": "str", "repo_id": "str"}, typename="repo" + types={"location": "str", "repo_id": "str"}, typename="repo" ) def __init__(self, location, repo_id=None, cache_version="0"): diff --git a/src/pkgcore/cache/flat_hash.py b/src/pkgcore/cache/flat_hash.py index 78c49c11..39913dd4 100644 --- a/src/pkgcore/cache/flat_hash.py +++ b/src/pkgcore/cache/flat_hash.py @@ -19,7 +19,12 @@ class database(fs_template.FsBased): # TODO: different way of passing in default auxdbkeys and location pkgcore_config_type = ConfigHint( - {"readonly": "bool", "location": "str", "label": "str", "auxdbkeys": "list"}, + types={ + "readonly": "bool", + "location": "str", + "label": "str", + "auxdbkeys": "list", + }, required=["location"], positional=["location"], typename="cache", diff --git a/src/pkgcore/config/basics.py b/src/pkgcore/config/basics.py index 91e16dab..0ff78c78 100644 --- a/src/pkgcore/config/basics.py +++ b/src/pkgcore/config/basics.py @@ -586,14 +586,14 @@ def section_alias(target, typename): identical to our target's. """ - @configurable({"target": "ref:" + typename}, typename=typename) + @configurable(types={"target": "ref:" + typename}, typename=typename) def section_alias(target): return target return AutoConfigSection({"class": section_alias, "target": target}) -@configurable({"path": "str", "parser": "callable"}, typename="configsection") +@configurable(types={"path": "str", "parser": "callable"}, typename="configsection") def parse_config_file(path, parser): try: f = open(path, "r") diff --git a/src/pkgcore/config/hint.py b/src/pkgcore/config/hint.py index 4a052fe5..8a230204 100644 --- a/src/pkgcore/config/hint.py +++ b/src/pkgcore/config/hint.py @@ -63,9 +63,9 @@ class ConfigHint: return self.__class__(**new_kwds) -def configurable(*args, **kwargs): +def configurable(**kwargs): """Decorator version of ConfigHint.""" - hint = ConfigHint(*args, **kwargs) + hint = ConfigHint(**kwargs) def decorator(original): original.pkgcore_config_type = hint diff --git a/src/pkgcore/ebuild/domain.py b/src/pkgcore/ebuild/domain.py index fd5b39fc..d6ddf38d 100644 --- a/src/pkgcore/ebuild/domain.py +++ b/src/pkgcore/ebuild/domain.py @@ -264,7 +264,7 @@ class domain(config_domain): # TODO this is missing defaults pkgcore_config_type = ConfigHint( - _types, + types=_types, typename="domain", required=["repos", "profile", "vdb"], allow_unknowns=True, diff --git a/src/pkgcore/ebuild/eclass_cache.py b/src/pkgcore/ebuild/eclass_cache.py index c3dea7df..08de5948 100644 --- a/src/pkgcore/ebuild/eclass_cache.py +++ b/src/pkgcore/ebuild/eclass_cache.py @@ -86,7 +86,7 @@ class base: class cache(base): pkgcore_config_type = ConfigHint( - {"path": "str", "location": "str"}, typename="eclass_cache" + types={"path": "str", "location": "str"}, typename="eclass_cache" ) def __init__(self, path, location=None): @@ -122,7 +122,7 @@ class StackedCaches(base): """ pkgcore_config_type = ConfigHint( - {"caches": "refs:eclass_cache", "location": "str", "eclassdir": "str"}, + types={"caches": "refs:eclass_cache", "location": "str", "eclassdir": "str"}, typename="eclass_cache", ) diff --git a/src/pkgcore/ebuild/portage_conf.py b/src/pkgcore/ebuild/portage_conf.py index 7d9d131a..ef25baab 100644 --- a/src/pkgcore/ebuild/portage_conf.py +++ b/src/pkgcore/ebuild/portage_conf.py @@ -42,7 +42,7 @@ def my_convert_hybrid(manager, val, arg_type): @configurable( - {"ebuild_repo": "ref:repo", "vdb": "ref:repo", "profile": "ref:profile"}, + types={"ebuild_repo": "ref:repo", "vdb": "ref:repo", "profile": "ref:profile"}, typename="pkgset", ) def SecurityUpgradesViaProfile(ebuild_repo, vdb, profile): diff --git a/src/pkgcore/ebuild/profiles.py b/src/pkgcore/ebuild/profiles.py index 89c27391..83bcda09 100644 --- a/src/pkgcore/ebuild/profiles.py +++ b/src/pkgcore/ebuild/profiles.py @@ -861,7 +861,7 @@ class ProfileStack: class OnDiskProfile(ProfileStack): pkgcore_config_type = ConfigHint( - {"basepath": "str", "profile": "str"}, + types={"basepath": "str", "profile": "str"}, required=("basepath", "profile"), typename="profile", ) @@ -934,7 +934,7 @@ class UserProfileNode(ProfileNode): class UserProfile(OnDiskProfile): pkgcore_config_type = ConfigHint( - {"user_path": "str", "parent_path": "str", "parent_profile": "str"}, + types={"user_path": "str", "parent_path": "str", "parent_profile": "str"}, required=("user_path", "parent_path", "parent_profile"), typename="profile", ) diff --git a/src/pkgcore/ebuild/repository.py b/src/pkgcore/ebuild/repository.py index f63521f5..4a06118a 100644 --- a/src/pkgcore/ebuild/repository.py +++ b/src/pkgcore/ebuild/repository.py @@ -25,7 +25,8 @@ from snakeoil.strings import pluralism from .. import fetch from ..config.hint import ConfigHint, configurable from ..log import logger -from ..operations import OperationError, repo as _repo_ops +from ..operations import OperationError +from ..operations import repo as _repo_ops from ..package import errors as pkg_errors from ..repository import configured, errors, prototype, util from ..repository.virtual import RestrictionRepo @@ -276,7 +277,7 @@ class UnconfiguredTree(prototype.tree): operations_kls = repo_operations pkgcore_config_type = ConfigHint( - { + types={ "location": "str", "eclass_cache": "ref:eclass_cache", "masters": "refs:repo", diff --git a/src/pkgcore/fetch/custom.py b/src/pkgcore/fetch/custom.py index c1f673a3..d5c48186 100644 --- a/src/pkgcore/fetch/custom.py +++ b/src/pkgcore/fetch/custom.py @@ -26,7 +26,7 @@ class MalformedCommand(errors.FetchError): class fetcher(base.fetcher): pkgcore_config_type = ConfigHint( - { + types={ "userpriv": "bool", "required_chksums": "list", "distdir": "str", diff --git a/src/pkgcore/pkgsets/filelist.py b/src/pkgcore/pkgsets/filelist.py index d3f58b6a..6727359b 100644 --- a/src/pkgcore/pkgsets/filelist.py +++ b/src/pkgcore/pkgsets/filelist.py @@ -17,7 +17,7 @@ from ..package.errors import InvalidDependency class FileList: - pkgcore_config_type = ConfigHint({"location": "str"}, typename="pkgset") + pkgcore_config_type = ConfigHint(types={"location": "str"}, typename="pkgset") error_on_subsets = True def __init__(self, location, gid=os_data.portage_gid, mode=0o644): diff --git a/src/pkgcore/pkgsets/glsa.py b/src/pkgcore/pkgsets/glsa.py index 45c0213d..aa7c5268 100644 --- a/src/pkgcore/pkgsets/glsa.py +++ b/src/pkgcore/pkgsets/glsa.py @@ -27,7 +27,7 @@ class GlsaDirSet(metaclass=generic_equality): (rsync tree is the usual source.) """ - pkgcore_config_type = ConfigHint({"src": "ref:repo"}, typename="pkgset") + pkgcore_config_type = ConfigHint(types={"src": "ref:repo"}, typename="pkgset") op_translate = {"ge": ">=", "gt": ">", "lt": "<", "le": "<=", "eq": "="} __attr_comparison__ = ("paths",) @@ -237,7 +237,7 @@ class SecurityUpgrades(metaclass=generic_equality): """Set of packages for available security upgrades.""" pkgcore_config_type = ConfigHint( - {"ebuild_repo": "ref:repo", "vdb": "ref:vdb"}, typename="pkgset" + types={"ebuild_repo": "ref:repo", "vdb": "ref:vdb"}, typename="pkgset" ) __attr_comparison__ = ("arch", "glsa_src", "vdb") diff --git a/src/pkgcore/pkgsets/installed.py b/src/pkgcore/pkgsets/installed.py index 1b8f6fe3..eacf37f7 100644 --- a/src/pkgcore/pkgsets/installed.py +++ b/src/pkgcore/pkgsets/installed.py @@ -24,12 +24,12 @@ class _Base: class Installed(_Base): """Set of packages holding slotted atoms of all installed packages.""" - pkgcore_config_type = ConfigHint({"vdb": "refs:repo"}, typename="pkgset") + pkgcore_config_type = ConfigHint(types={"vdb": "refs:repo"}, typename="pkgset") getter = operator.attrgetter("slotted_atom") class VersionedInstalled(_Base): """Set of packages holding versioned atoms of all installed packages.""" - pkgcore_config_type = ConfigHint({"vdb": "refs:repo"}, typename="pkgset") + pkgcore_config_type = ConfigHint(types={"vdb": "refs:repo"}, typename="pkgset") getter = operator.attrgetter("versioned_atom") diff --git a/src/pkgcore/pkgsets/system.py b/src/pkgcore/pkgsets/system.py index 596f7ef6..cdf175b6 100644 --- a/src/pkgcore/pkgsets/system.py +++ b/src/pkgcore/pkgsets/system.py @@ -10,7 +10,9 @@ from ..config.hint import ConfigHint class SystemSet: """Set of packages defined by the selected profile.""" - pkgcore_config_type = ConfigHint({"profile": "ref:profile"}, typename="pkgset") + pkgcore_config_type = ConfigHint( + types={"profile": "ref:profile"}, typename="pkgset" + ) def __init__(self, profile): self.system = frozenset(profile.system) diff --git a/src/pkgcore/repository/multiplex.py b/src/pkgcore/repository/multiplex.py index 02e754c1..5cede2d1 100644 --- a/src/pkgcore/repository/multiplex.py +++ b/src/pkgcore/repository/multiplex.py @@ -63,7 +63,7 @@ class operations(repo_interface.operations_proxy): return ret -@configurable({"repos": "refs:repo"}, typename="repo") +@configurable(types={"repos": "refs:repo"}, typename="repo") def config_tree(repos): return tree(*repos) diff --git a/src/pkgcore/sync/base.py b/src/pkgcore/sync/base.py index f015cd2c..2d60e6c0 100644 --- a/src/pkgcore/sync/base.py +++ b/src/pkgcore/sync/base.py @@ -70,7 +70,7 @@ class Syncer: disabled = False pkgcore_config_type = ConfigHint( - {"path": "str", "uri": "str", "opts": "str", "usersync": "bool"}, + types={"path": "str", "uri": "str", "opts": "str", "usersync": "bool"}, typename="syncer", ) @@ -274,7 +274,7 @@ def _load_syncers(): @configurable( - {"basedir": "str", "uri": "str", "usersync": "bool", "opts": "str"}, + types={"basedir": "str", "uri": "str", "usersync": "bool", "opts": "str"}, typename="syncer", ) def GenericSyncer(basedir, uri, **kwargs): @@ -295,12 +295,12 @@ class DisabledSyncer(Syncer): super().__init__(path, uri="") -@configurable({"basedir": "str", "usersync": "bool"}, typename="syncer") +@configurable(types={"basedir": "str", "usersync": "bool"}, typename="syncer") def DisabledSync(basedir, *args, **kwargs): return DisabledSyncer(basedir) -@configurable({"basedir": "str", "usersync": "bool"}, typename="syncer") +@configurable(types={"basedir": "str", "usersync": "bool"}, typename="syncer") def AutodetectSyncer(basedir, **kwargs): for syncer_cls in _load_syncers(): if args := syncer_cls.is_usable_on_filepath(basedir): diff --git a/src/pkgcore/sync/rsync.py b/src/pkgcore/sync/rsync.py index acf1793b..bde2fd65 100644 --- a/src/pkgcore/sync/rsync.py +++ b/src/pkgcore/sync/rsync.py @@ -53,7 +53,7 @@ class rsync_syncer(base.ExternalSyncer): return proto[0], f"rsync:{proto[1]}" pkgcore_config_type = ConfigHint( - { + types={ "basedir": "str", "uri": "str", "conn_timeout": "str", diff --git a/src/pkgcore/vdb/ondisk.py b/src/pkgcore/vdb/ondisk.py index 721d0349..e871129e 100644 --- a/src/pkgcore/vdb/ondisk.py +++ b/src/pkgcore/vdb/ondisk.py @@ -31,7 +31,7 @@ class tree(prototype.tree): operations_kls = repo_ops.operations pkgcore_config_type = ConfigHint( - { + types={ "location": "str", "cache_location": "str", "repo_id": "str", diff --git a/tests/config/test_basics.py b/tests/config/test_basics.py index 929c907c..7dfc88db 100644 --- a/tests/config/test_basics.py +++ b/tests/config/test_basics.py @@ -11,7 +11,7 @@ def passthrough(*args, **kwargs): def test_invalid_config_types(): for var in ("class", "inherit"): - @configurable({var: "str"}) + @configurable(types={var: "str"}) def testtype(): pass diff --git a/tests/config/test_central.py b/tests/config/test_central.py index f3fc1c70..5ffb8072 100644 --- a/tests/config/test_central.py +++ b/tests/config/test_central.py @@ -1,8 +1,8 @@ import pytest +from snakeoil.errors import walk_exception_chain from pkgcore.config import basics, central, errors from pkgcore.config.hint import configurable -from snakeoil.errors import walk_exception_chain # A bunch of functions used from various tests below. @@ -10,7 +10,7 @@ def repo(cache): return cache -@configurable({"content": "ref:drawer", "contents": "refs:drawer"}) +@configurable(types={"content": "ref:drawer", "contents": "refs:drawer"}) def drawer(content=None, contents=None): return content, contents @@ -391,7 +391,7 @@ def test_reinstantiate_after_raise(): # reprocess already processed section_ref args. spork = object() - @configurable({"thing": "ref:spork"}) + @configurable(types={"thing": "ref:spork"}) def myrepo(thing): assert thing is spork raise errors.ComplexInstantiationError("I suck") @@ -585,11 +585,11 @@ def test_alias(): def test_typecheck(): - @configurable({"myrepo": "ref:repo"}, typename="repo") + @configurable(types={"myrepo": "ref:repo"}, typename="repo") def reporef(myrepo=None): return myrepo - @configurable({"myrepo": "refs:repo"}, typename="repo") + @configurable(types={"myrepo": "refs:repo"}, typename="repo") def reporefs(myrepo=None): return myrepo @@ -804,11 +804,15 @@ def test_autoload_wrong_type(): def test_lazy_refs(): - @configurable({"myrepo": "lazy_ref:repo", "thing": "lazy_ref"}, typename="repo") + @configurable( + types={"myrepo": "lazy_ref:repo", "thing": "lazy_ref"}, typename="repo" + ) def reporef(myrepo=None, thing=None): return myrepo, thing - @configurable({"myrepo": "lazy_refs:repo", "thing": "lazy_refs"}, typename="repo") + @configurable( + types={"myrepo": "lazy_refs:repo", "thing": "lazy_refs"}, typename="repo" + ) def reporefs(myrepo=None, thing=None): return myrepo, thing @@ -981,7 +985,7 @@ def test_prepend_inherit(): def test_list_prepend(): - @configurable({"seq": "list"}) + @configurable(types={"seq": "list"}) def seq(seq): return seq @@ -1018,7 +1022,7 @@ def test_list_prepend(): def test_str_prepend(): - @configurable({"string": "str"}) + @configurable(types={"string": "str"}) def sect(string): return string diff --git a/tests/scripts/test_pconfig.py b/tests/scripts/test_pconfig.py index ca8e98fe..e11b502d 100644 --- a/tests/scripts/test_pconfig.py +++ b/tests/scripts/test_pconfig.py @@ -1,11 +1,12 @@ import pytest + from pkgcore.config import basics, errors from pkgcore.config.hint import configurable from pkgcore.scripts import pconfig from pkgcore.test.scripts.helpers import ArgParseMixin -@configurable({"reff": "ref:spork"}) +@configurable(types={"reff": "ref:spork"}) def spork(reff): """Test thing.""" diff --git a/tests/scripts/test_pebuild.py b/tests/scripts/test_pebuild.py index afa09758..6a99c4ca 100644 --- a/tests/scripts/test_pebuild.py +++ b/tests/scripts/test_pebuild.py @@ -7,7 +7,7 @@ from pkgcore.test.scripts.helpers import ArgParseMixin class FakeDomain: - pkgcore_config_type = ConfigHint({"repo": "ref:repo"}, typename="domain") + pkgcore_config_type = ConfigHint(types={"repo": "ref:repo"}, typename="domain") def __init__(self, repo): object.__init__(self) diff --git a/tests/scripts/test_pmaint.py b/tests/scripts/test_pmaint.py index c9af122f..417b7a10 100644 --- a/tests/scripts/test_pmaint.py +++ b/tests/scripts/test_pmaint.py @@ -56,7 +56,7 @@ def make_repo_config(repo_data, livefs=False, frozen=False, repo_id=None): class FakeDomain: pkgcore_config_type = ConfigHint( - {"repos": "refs:repo", "binpkg": "refs:repo", "vdb": "refs:repo"}, + types={"repos": "refs:repo", "binpkg": "refs:repo", "vdb": "refs:repo"}, typename="domain", ) diff --git a/tests/scripts/test_pquery.py b/tests/scripts/test_pquery.py index b0a41af9..72b31d24 100644 --- a/tests/scripts/test_pquery.py +++ b/tests/scripts/test_pquery.py @@ -9,7 +9,7 @@ from pkgcore.test.scripts.helpers import ArgParseMixin class FakeDomain: pkgcore_config_type = ConfigHint( - {"repos": "refs:repo", "vdb": "refs:repo"}, typename="domain" + types={"repos": "refs:repo", "vdb": "refs:repo"}, typename="domain" ) def __init__(self, repos, vdb): |