commit: d5cfbc500ea1d0390a290267ed2628fed6a20b13
Author: Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Sat Nov 22 23:55:57 2025 +0000
Commit: Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Sat Nov 22 23:55:57 2025 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=d5cfbc50
feat: drop lazy-object-proxy dep
Snakeoil DelayedInstantion is a superset of that in regards
to lieing to the python environment (making it a full thunk-
hiding it's even there). Snakeoil isn't as fast on the
implementation, but that's irrelevant for things like lazy-loading
subcmds which was the usage.
Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
pyproject.toml | 4 +---
src/snakeoil/cli/arghparse.py | 16 ++++++----------
2 files changed, 7 insertions(+), 13 deletions(-)
diff --git a/pyproject.toml b/pyproject.toml
index a6df15d..113252b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -26,9 +26,7 @@ classifiers = [
]
dynamic = ["version"]
-dependencies = [
- "lazy-object-proxy",
-]
+dependencies = []
[project.optional-dependencies]
test = [
diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index e0bd1b3..a964cbf 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -10,6 +10,7 @@ import pkgutil
import subprocess
import sys
import traceback
+import types
import typing
from argparse import (
_UNRECOGNIZED_ARGS_ATTR,
@@ -30,13 +31,11 @@ from itertools import chain
from operator import attrgetter
from textwrap import dedent
-import lazy_object_proxy
-
from snakeoil.formatters import PlainTextFormatter
from .. import klass
from ..mappings import ImmutableDict
-from ..obj import popattr
+from ..obj import DelayedInstantiation, popattr
from ..sequences import split_elements, split_negations
from ..strings import pluralism
from ..version import get_version
@@ -570,19 +569,16 @@ class _SubParser(argparse._SubParsersAction):
return parser
- def _lazy_parser(self, module, subcmd):
- """Lazily-import the subcommand parser for a given module."""
- return getattr(importlib.import_module(module), subcmd)
-
- def add_command(self, subcmd):
+ def add_command(self, subcmd: str) -> None:
"""Register a given subcommand to be imported on demand.
Note that this assumes a specific module naming and layout scheme for
commands.
"""
prog = self._prog_prefix
module = f"{prog}.scripts.{prog}_{subcmd}"
- func = partial(self._lazy_parser, module, subcmd)
- self._name_parser_map[subcmd] = lazy_object_proxy.Proxy(func)
+ self._name_parser_map[subcmd] = DelayedInstantiation(
+ self.__class__, lambda: getattr(importlib.import_module(module),
subcmd)
+ )
def __call__(self, parser, namespace, values, option_string=None):
"""override stdlib argparse to revert subparser namespace changes