Commit graph jw-python/src/python/jw
Author SHA1 Message Date
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
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
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