aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gmail.com>2023-01-14 23:59:29 -0800
committerArthur Zamarin <arthurzam@gentoo.org>2023-02-02 21:59:11 +0200
commit2c03223768fb522a85b410db382d3e9f53575666 (patch)
tree1cb9eb666a86c9e447ade10e6b069f712f4d1e92
parentrefactor(config): adding typing to config hints along with immutability. (diff)
downloadpkgcore-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.py2
-rw-r--r--src/pkgcore/cache/flat_hash.py7
-rw-r--r--src/pkgcore/config/basics.py4
-rw-r--r--src/pkgcore/config/hint.py4
-rw-r--r--src/pkgcore/ebuild/domain.py2
-rw-r--r--src/pkgcore/ebuild/eclass_cache.py4
-rw-r--r--src/pkgcore/ebuild/portage_conf.py2
-rw-r--r--src/pkgcore/ebuild/profiles.py4
-rw-r--r--src/pkgcore/ebuild/repository.py5
-rw-r--r--src/pkgcore/fetch/custom.py2
-rw-r--r--src/pkgcore/pkgsets/filelist.py2
-rw-r--r--src/pkgcore/pkgsets/glsa.py4
-rw-r--r--src/pkgcore/pkgsets/installed.py4
-rw-r--r--src/pkgcore/pkgsets/system.py4
-rw-r--r--src/pkgcore/repository/multiplex.py2
-rw-r--r--src/pkgcore/sync/base.py8
-rw-r--r--src/pkgcore/sync/rsync.py2
-rw-r--r--src/pkgcore/vdb/ondisk.py2
-rw-r--r--tests/config/test_basics.py2
-rw-r--r--tests/config/test_central.py22
-rw-r--r--tests/scripts/test_pconfig.py3
-rw-r--r--tests/scripts/test_pebuild.py2
-rw-r--r--tests/scripts/test_pmaint.py2
-rw-r--r--tests/scripts/test_pquery.py2
24 files changed, 55 insertions, 42 deletions
diff --git a/src/pkgcore/binpkg/repository.py b/src/pkgcore/binpkg/repository.py
index 9a6e7870a..549d50b70 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 78c49c112..39913dd4a 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 91e16dabf..0ff78c784 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 4a052fe52..8a230204b 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 fd5b39fc3..d6ddf38d5 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 c3dea7dff..08de59487 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 7d9d131aa..ef25baab3 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 89c273915..83bcda09a 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 f63521f5a..4a06118a0 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 c1f673a3b..d5c48186b 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 d3f58b6ae..6727359b6 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 45c0213db..aa7c52683 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 1b8f6fe3d..eacf37f70 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 596f7ef6f..cdf175b63 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 02e754c14..5cede2d1f 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 f015cd2c0..2d60e6c00 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 acf1793bf..bde2fd653 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 721d03495..e871129e2 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 929c907c2..7dfc88dbf 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 f3fc1c702..5ffb8072b 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 ca8e98fe6..e11b502db 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 afa097582..6a99c4cae 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 c9af122f2..417b7a106 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 b0a41af90..72b31d242 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):