lib.util: Add kebab_to_pascal() and pascal_to_kebab()

PathFilter.create() currently instantiates individual filters in a match -
case over the filter URI's protocol. The plan is to instantiate filters
without match / case based on a protocol naming scheme only, so we better
introduce one at this point. Adopt jw-python's kebab_to_pascal() and
pascal_to_kebab() functions as a foundation for a future naming convention.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-11-11 09:09:02 +01:00
commit 372356a8df
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 29 additions and 2 deletions

View file

@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, Any, override
from jw.pkg.lib.FileContext import FileContext
from jw.pkg.lib.Package import Package
from jw.pkg.lib.PathFilter import PathFilter
from jw.pkg.lib.pf.Pkg import Pkg
if TYPE_CHECKING:
@ -65,6 +66,13 @@ for definition in ('',
f = Pkg(file_context = fc, spec = 'pkg:url=~example\\.com')
assert repr(f) == 'filter:pkg:url=~example\\.com'
# -- PathFilter.create() resolves the name kebab-to-pascal --
f3 = PathFilter.create(spec = 'pkg:url=~example\\.com', file_context = fc)
assert isinstance(f3, Pkg)
assert f3.match_pkg(pkg)
assert not f3.match_pkg(pkg_other)
class _FakeDistro:
def __init__(self, pkgs: list[tuple[str, str | None, list[str]]]) -> None:

View file

@ -4,12 +4,19 @@ import stat
import tempfile
from jw.pkg.lib.ec.Local import Local
from jw.pkg.lib.util import copy
from jw.pkg.lib.util import copy, kebab_to_pascal, pascal_to_kebab
def uri(path: str) -> str:
return 'local://localhost' + path
async def run_tests() -> None:
# -- kebab <-> pascal: the name conversion behind the dynamic
# loading of filters and, later, file contexts
assert kebab_to_pascal('pkg') == 'Pkg'
assert kebab_to_pascal('pkg-secrets') == 'PkgSecrets'
assert pascal_to_kebab('Pkg') == 'pkg'
assert pascal_to_kebab('PkgSecrets') == 'pkg-secrets'
with tempfile.TemporaryDirectory() as tmp:
# -- Source tree
#