Commit graph

380 commits

Author SHA1 Message Date
d4fd741c19
misc.load_class(): Use jw.pkg.lib.LoadTypes
Make load_class() use jw.pkg.lib.LoadTypes, because it provides the
possibility to nicely log which modules and classes it picks.

TODO: Don't use importlib at all in module misc.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
26f3893579
test: Fix MyPy errors
Fix multiple errors in test dug up by MyPy.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
af185c60f9
Config: Derive from Mapping and add @override
Derive Config from collections.abc.Mapping to formally declare it as
a read-only mapping interface. Implement the three abstract methods:

  - __getitem__(): delegates to get(), raises KeyError if missing
  - __iter__(): iterates over config keys (delegated to __conf)
  - __len__(): returns number of top-level keys

Add @override to __getitem__(), __iter__(), and __len__(). The get()
method does not get @override — Mapping.get() uses generic overloads
with Any-typed parameters that are incompatible with Config.get()’s
specific str-typed signature. While Config.get() is Liskov-safe
(contravariant args, covariant return), mypy flags the mismatch on
the def line. A targeted "# type: ignore[override]" suppresses only
this one false positive without disabling override checking for the
rest of the module.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
ffbb070076
Config: Modernize types to PEP 604 union syntax
Replace Optional[X] with X | None and typing.Dict with builtin dict
throughout the module. Add "from __future__ import annotations" to
enable deferred evaluation, removing all quoted forward references.

Add missing return type annotations to __setitem__(), parent, root,
set(), get(), value(), and name. Remove Optional and Dict from the
typing import since cast() is the only runtime typing helper needed.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
9ed8c1cb18
Config: Annotate __load() signature and paths_buf
The __load() method has no type annotations for any of its three
parameters, making it inconsistent with __init__ and harder for type
checkers to verify correctness. Add type annotations to all __load()
parameters and the paths_buf local variable.

The paths_buf variable needs an explicit list[str] annotation because
mypy cannot infer the type of an empty list literal when passed as
a mutable buffer argument to serdes.read().

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
1f3e38e685
Config: Add diagnostic to paths_buf assert
The bare assert (len(paths_buf)) relies on truthiness which, while
correct, is misleading — readers might expect "assert len(paths_buf)
> 0" instead. Replace with an explicit comparison and add a diagnostic
message showing the actual length for easier debugging.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
8a7bcfba8e
Config: Fix branch() return type annotation
The branch() method returns either None or a Config but has no
return type annotation — just a "# type: ignore" comment with a
FIXME. Add the proper Optional[Config] annotation (written as
Config | None in modern syntax) and remove the workaround.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
544d80949f
Config: Define _REFUSE_MODE_MASK constant
Extract the magic 0o0027 default for refuse_mode_mask into a module-
level constant with a docstring. This makes the default parameter
self-documenting and prevents duplication if the value ever changes.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
c7b4a6e118
Config: Replace __is_abs() with os.path.isabs()
The __is_abs() helper duplicates os.path.isabs() logic. Replace it
with the standard library function, guarding for None/empty strings
to match the original helper safety behavior.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
f9f10f9b9e
Config: Fix search_dirs env var parsing into dirs
When search_dirs comes from an environment variable, the __load()
method iterates over each character of the colon-separated string
instead of treating it as a list of directory paths. This produces
nonsensical glob paths like "h/", "o/", "m/", etc.

Fix by splitting the env var value into a list before assigning it
to the search_dirs variable.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
df5202f4dc
stree: Reorder StringTree class members
Reorder the StringTree class members to follow the project coding
style:

1. Nested public/helper types (Error, Match) at the top.
2. Instance attribute annotations so mypy can track them before
   __adopt_children runs in __init__.
3. Private methods (__adopt_children, __set, __dump, __find) grouped
   together, with _dict_to_tree moved from module scope into the
   class as a @staticmethod.
4. Dunder methods (__repr__ through __len__) between private and public.
5. Public API preceded by # -- Public API comment, with __init__
   moved from the top into this section.
6. _dict_to_tree recursive call updated to StringTree._dict_to_tree()
   to avoid the bare-name lookup that mypy rejects on a @staticmethod.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.80.2
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
b4f053c892
stree: Switch StringTree from Mapping to MutableMapping
StringTree declares itself as a Mapping but implements __setitem__
which returns StringTree — neither correct for Mapping nor for
MutableMapping. This commit changes the base class to MutableMapping
and fixes the signatures to match the ABC contract: __setitem__ now
returns None, and __delitem__ is implemented by delegating to the
underlying OrderedDict.

The __setitem__ return value change is an API break for callers that
rely on its StringTree return. Those callers should use add() instead.
This is acceptable because the previous type signature was silently
incorrect — it violated the Mapping abstract base class contract.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.80.2
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
4d49b508bc
stree: Type annotate StringTree and serdes
The StringTree class and its companion serdes module have minimal
type annotations — only method signatures and a few instance
attributes were typed. This commit adds proper type annotations to
every parameter, return type, and local variable across both files.

cleanup_string() gains overloaded signatures so callers passing str
get str back, avoiding the need to widen the return type everywhere.
The matcher return type in __find is narrowed from Any to
Callable[[str, str], bool]. Casts are used sparingly where the
runtime guarantees a narrower type than the checker can infer (e.g.
self.value() always returns str when called without path, despite the
return annotation being str | None).

Variable annotations in StringTree.__set, get, __find, child_list, and
dump cover local bindings. serdes gains full parameter and return type
coverage plus annotations for all local variables in _cleanup_line,
parse, _read_lines_from_one_path, and _read_lines.

The get() default parameter remains Any because overriding
Mapping.get with a concrete type breaks the Liskov substitution
principle — Mapping.get is generic over the default type.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.80.2
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
0e6276e30e
stree.StringTree: Refactoring and fixes
This commit refactors the order of functions a little from used to
using.

It also fixes a bug: .find() could omit matching entries, fixes
intricate case distinction, and doesn't ignore re.PatternError
anylonger.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
499694e1f9
stree.StringTree: Add unit tests
Add pytest-style unit tests for the StringTree class.

This commit also adds the needed infrastructure: Dependency on
python3-pytest, the unit test directory structure and conftest.py in
.gitignore.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.80.2
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
01942ac5bf
stree.StringTree: Exception -> StringTree.Error
Raise a specialized StringTree.Error rather than a bare Exception to
allow callers to distinguish where it came from.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
2a6814d125
stree.StringTree: Derive from Mapping
This commit derives StringTree from Mapping, allowing it to be used
as a drop-in-replacement for dictionaries returned from load_yaml().

Note that this is a breaking change, because it changes the return
value of __getitem__() from str to StringTree. Either this or get()
have to give, because the base class uses __getitem__() to implement
get(), and returning different types from these, as it's currently
the case would break caller expectations.

To mitigate the pain of the breakage, __str__() now returns .content
or "", and can be used to easily convert []'s return value to a
string.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
b26e709082
stree.StringTree.read(): Add classmethod
Add StringTree.read() which is a frontend for serdes.read(), saving
one import from the caller's perspective.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
aec0b0a3f5
stree.StringTree: Add type hinting
Add some type hinting to the StringTree class in the hope to make
some call semanticas clearer.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
b4041018d2
stree.StringTree.__set(): path_ -> path
Some methods take a "path_" argument, which is not nice for callers.
Rename it to "path" and fix the fallout in the method bodies.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
e3c64f2efb
jw.util: Add @override
Add @override qualifiers to overridden methods.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
ae1445a08c
jw.util.log: Import from jw.pkg.lib.log
Remove jw-python's implementation of the log module entirely, making
it a facade of jw-pkg's implementation. This removes reduncancy and
duplicate state.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
d15177a9a8
log: Add log()
In a push to harmonize jw.pkg and jw.util logging APIs, add the
aliases

  log() for slog()
  log_m() for slog_m()

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:11 +00:00
8681317e8c
jw.util.Cmds, .Cmd, .App: Use jw.pkg.lib.App + .Cmd
This commit does a couple of things in one go:

- Move the implementations from jw.util.Cmds and jw.util.Cmd back to
  jwutils where they came from to remain backwards compatible for
  code still using jwutils.

- No code uses jw.util.Cmds and jw.util.Cmd yet, so remove them.

- Add new jw.util.App and jw.util.Cmd classes instead, which are
  re-exported modules from jw.pkg.lib. These implementations are very
  similar, but not identical to jwutils.Cmds and jwutils.App.

Originally, Cmds and Cmd had been copied from jw-python to jw-pkg App
and Cmd, respectively, because an App class proved indispensible in
jw-pkg.  The two classes have subsequently evolved in jw-pkg, and
re-using them here ends the fork and removes the redundancy.

This makes jw-python expose the same App / Cmd pair as jw.pkg does
for as long as Cmds is still in use. In the future, it might be a
good idea to remove Cmds, Cmd and App from jw-python entirely.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:11 +00:00
2871dda16e
jw: Add "util" to __all__
Add "util" to __all__, to allow imports of jw.util.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:11 +00:00
b928a071ef
Release 1.0.0-50@suse-tumbleweed/x86_64
Some checks failed
CI / Packaging test (push) Has been cancelled
CI / Packaging - OpenSUSE Tumbleweed (push) Has been cancelled
CI / Packaging - Kali Linux (push) Has been cancelled
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-14 23:29:46 +00:00
262b1a5e02
Release 1.0.0-50@kali-rolling/amd64
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-14 23:09:45 +00:00
c3687c96be
Start version: 1.0.0-50
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-14 23:08:54 +00:00
d781cbfdd2
jwutils: Add missing types
Add types missing from the jwutils compatibility shim, because
software using it complains:

  from .Cmd import Cmd as Cmd
  from jw.util.ldap import Config as Config

This will probably not be the last time this happens.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-06-14 11:36:34 +02:00
b727f54d38
Release 1.0.0-49@suse-tumbleweed/x86_64
All checks were successful
CI / Packaging - Kali Linux (push) Successful in 4m26s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 5m9s
CI / Packaging test (push) Successful in 0s
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-12 06:40:58 +00:00
a9b87f683c
Release 1.0.0-49@kali-rolling/amd64
All checks were successful
CI / Packaging - Kali Linux (push) Successful in 4m25s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 5m10s
CI / Packaging test (push) Successful in 0s
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-12 03:36:34 +00:00
90690521a1
Start version: 1.0.0-49
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-12 03:35:45 +00:00
e9845b5a1f
Makefile: Include py-topdir.mk
Include py-topdir.mk, which entails loads of fallout from make check.
Fix it.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-06-12 04:55:47 +02:00
7212850b22
Release 1.0.0-48@suse-tumbleweed/x86_64
All checks were successful
CI / Packaging - Kali Linux (push) Successful in 4m10s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m43s
CI / Packaging test (push) Successful in 0s
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-11 23:38:37 +00:00
c50f08e16d
Release 1.0.0-48@kali-rolling/amd64
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-11 23:11:17 +00:00
a50d3719b2
Start version: 1.0.0-48
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-11 23:10:27 +00:00
a2684dd601
jwutils: Move to jwutils -> jw.util
Move all implementation source code from the jwutils module to
jw.util. For compatibility with existing Python modules, keep a thin,
autogenerated compatibility shim under jwutils.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-06-11 23:10:25 +00:00
bc7652fdf9
Release 1.0.0-47@suse-tumbleweed/x86_64
All checks were successful
CI / Packaging - Kali Linux (push) Successful in 3m50s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m37s
CI / Packaging test (push) Successful in 0s
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 04:46:10 +00:00
d1f901147d
Release 1.0.0-47@kali-rolling/amd64
All checks were successful
CI / Packaging - Kali Linux (push) Successful in 3m51s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m24s
CI / Packaging test (push) Successful in 0s
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 03:45:55 +00:00
021f8de5f5
Start version: 1.0.0-47
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 03:45:55 +00:00
59576eb461
Release 1.0.0-46@kali-rolling/amd64
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 03:45:55 +00:00
ea76e59d57
Start version: 1.0.0-46
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 03:45:55 +00:00
e5e4e3d51d
Release 1.0.0-45@kali-rolling/amd64
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 03:45:55 +00:00
2e93adc4f7
Start version: 1.0.0-45
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 03:45:55 +00:00
a04b33d966
Release 1.0.0-44@kali-rolling/amd64
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 03:45:55 +00:00
e601faf526
Start version: 1.0.0-44
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 03:45:55 +00:00
71bd17fd42
Release 1.0.0-43@kali-rolling/amd64
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 03:45:55 +00:00
3f8aa523f7
Start version: 1.0.0-43
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 03:45:55 +00:00
5b1f7b82df
Release 1.0.0-42@kali-rolling/amd64
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 03:45:55 +00:00
0b2657894f
Start version: 1.0.0-42
Signed-off-by: janware DevOps <devops@janware.com>
2026-06-10 03:45:55 +00:00