kebab_to_pascal() and pascal_to_kebab() are needed in jw-pkg, for the
resolution of filter names and, later, the dynamic loading of file
contexts. jw-python depends on jw-pkg, so jw-pkg's util.py is their
canonical home.
This commit imports them from jw.pkg.lib.util and re-exports them, so the
existing importers keep working.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.2
Signed-off-by: Jan Lindemann <jan@janware.com>
Merge pull request "Sync the tree with current mypy and isort"
Upstream-repo: ssh://git@code.janware.com/janware/jw-python
Source-branch: jan/fix/20261113-sync-the-tree-with-current-mypy-and-isort
Target-branch: master
Reviewed-on: #4
The current isort formats parenthesized import lists with a trailing comma
and wraps long imports differently than when the files were last formatted,
so make format rewrites them on every run even though nothing is wrong with
the code.
Apply make format to the two drifted import statements so the tree matches
the formatter's output and make format becomes a no-op:
- src/python/jw/util/log.py: trailing comma in the jw.pkg.lib.log import
list
- src/python/jwutils/db/schema/CompositeForeignKey.py: wrap the
CompositeForeignKey import in parentheses
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.2
Signed-off-by: Jan Lindemann <jan@janware.com>
mypy 2.4.0 infers the attribute from the None assignment in __init__() and
then flags the right operand of the and check in __parse__() as unreachable
code, failing make check.
The attribute is only ever assigned None, so annotate it as Any and keep
the runtime behaviour unchanged.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.2
Signed-off-by: Jan Lindemann <jan@janware.com>
The parse_opts test is a plain script that constructs an Options from
sys.argv and crashed on the first get() call, because the by_index
condition in Options.get() is inverted and raises KeyError for an integer
index. It has several shortcomings, though:
- "make test" doesn't execute it, only make -C test/parse_opts run, so CI
doesn't run it
- It doesn't adhere to standard janware directory layout
- It's very basic
Replace the script with a pytest module under
test/unit/python/jw/util/Options, following the layout of the sibling
unit test directories: a Makefile including py-test.mk and a test.py
discovered by pytest. The module covers parsing of option strings, repeated
keys, JSON values, flags, get() with defaults and the by_index parameter,
__contains__, __iter__, keys(), str() and update().
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
The by_index branch of Options.get() raises KeyError for every integer
index, because the first isinstance guard is inverted: it fires for exactly
the keys the branch is supposed to handle, so the range check and the
lookup in the list of parsed keys below it are dead code. A non-integer key
with by_index set slips past the guard and falls through to the regular key
lookup instead. A previous make-check fallout commit flipped the original
type(key) != int test into a positive isinstance test, and a later mypy fix
then added redundant isinstance guards to the unreachable branches,
cementing the broken flow.
Invert the guard back to not isinstance(key, int), so that a non-integer
key raises KeyError, an in-range integer index returns the key stored at
that position in the option string, and an out-of-range index returns the
default or raises KeyError. Drop the redundant isinstance guards from the
now-reachable branches.
TODO: The bug actually made "make -C test/parse_opts run" fail, but since
jw-python's nightly CI doesn't run that, this has gone unnoticed. The test
now passes, but should be replaced with a better test (executed by "make
test", and pytest-based).
Signed-off-by: Jan Lindemann <jan@janware.com>
The test tree needs to be aligned with type checking, too, because jw-pkg
is going to required it for test, too. The load_yaml and StringTree tests
receive their fixtures as bare Callable and Generator without type
arguments, and the StringTree tests pass the st fixture without an
annotation. The cast script suppresses errors with un-coded type ignore
comments, and the parse_opts script declares its loop variable as
"str | int", so indexing the Options object with it is rejected.
Introduce _YamlFile, _TempDir, and _St aliases for the fixture types and
give the st parameters an annotation. Code the type ignore comments with
the argument mismatch they suppress, and split the parse_opts loop variable
into i for the index loops and k for the key loops.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit fixes tightening type check fallout.
add_subcommands() with a string pattern collects every class of the calling
module whose name matches the pattern. inspect.getmembers() yields plain
objects, so the unannotated collection list is inferred as list[object],
which is not compatible with the declared list[type[Cmd]] parameter type,
and make check fails on it.
Annotate the collection list as list[type[Cmd]] and narrow it to subclasses
of Cmd via issubclass(). This makes the implementation match the declared
signature and stops classes lacking the Cmd interface from being registered
as subcommands, where they would break later when instantiated and treated
as Cmd in __add_cmd_to_parser().
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
Add a store_dict() function to write the contents of a mapping to
a file as JSON, using the same formatting as dump_dict().
Signed-off-by: Jan Lindemann <jan@janware.com>
For a reviewable diff, .gitignore is updated in two commits. The first sorts,
the second is the result of "make gitignore".
This commit is step 2.
Signed-off-by: Jan Lindemann <jan@janware.com>
For a reviewable diff, .gitignore is updated in two commits. The first sorts,
the second is the result of "make gitignore".
This commit is step 1.
Signed-off-by: Jan Lindemann <jan@janware.com>
For in-tree tests, the jw package is split across several projects, and
each directory containing a py-ns-dir.mk contributes its subtree. So far,
it was up to that directory how the contribution is handled. With current
changes in jw-pkg, py-ns-dir.mk handles the contribution method centrally
by default, and the __init__.py currently under version control should be
removed. jw-python contains a custom __init__.py there, so protect it from
whatever py-ns-dir.mk is up to.
Signed-off-by: Jan Lindemann <jan@janware.com>
The optional marker is a leading dash in the include spec, but in
a YAML block list the leading dash is the list syntax and is
consumed by the YAML parser before load_yaml() sees the spec. An
include written as a plain list item "- file" is therefore
required, not optional, and a missing file raises, even though the
dash reads like the optional marker.
Note in the module docstring that in a block list the item itself
must carry the marker, as in "- -file.yaml" or the quoted form
"- "-file.yaml"".
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
An optional include with a target path that points to a missing
file leaves a trace in the output: _load_yaml() still calls
_merge_at_path() with the empty document, which creates the target
key as an empty mapping. A root-level optional include of the same
file contributes nothing, so the outcome depends on whether the
spec names a target path.
Skip included documents that are empty: an empty document
contributes nothing, at the root as well as at a target path, and
creates no key. Update the module docstring accordingly and add
tests covering a missing optional include with a target path.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
The jw.include file spec is resolved as a single literal file name,
so a set of files under one directory has to be listed one by one.
Let the file part of a spec use glob characters (*, ?, [...]).
_normalize_include_specs() expands every match into its own
IncludeSpec entry, so matches are loaded and deep-merged in lexical
order: at the root, later files win; at a target path, the existing
content wins as with a single include. A non-optional glob that
matches no files raises ValueError; the leading - prefix keeps a
glob optional. Document the globbing in the module docstring,
including the YAML quoting requirement for specs that start with a
glob character, and add tests covering the glob syntax, lexical
order, the no-match and optional cases, target-path merging,
absolute paths, and self-inclusion.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
The module has no docstring, so the include/link/inplace-link
extensions and their path rules are only discoverable by reading the
code. _parse_link() claims a named link 'uses a single pipe' even
though pipes may appear in the target path after the first one, and
_expand_links() does not say that a jw.link node with sibling keys is
not a link at all (the key is kept as-is), which is the behavior a
typo in a link node silently produces.
Add a module docstring describing the three extensions, the relative
path rules, and the known limitations (dotted keys cannot be
addressed, path navigation cannot traverse link nodes). Correct the
_parse_link() pipe rule, note the sibling-key behavior and the error
types in _expand_links(), and fix the 'stays at the current level'
wording, since a single dot resolves within the dict that contains
the link.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
The __main__ debug printer crashes with a bare IndexError when no
file argument is given, and json.dumps() crashes on YAML values that
have no JSON representation, such as dates.
Check the argument count and print a usage message, and pass
default = str to json.dumps() so that non-JSON values are rendered
as strings instead of aborting the dump.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
The memoisation cache in _expand_links_recursive() stores the expanded
value of a link node. A link node that is first reached via another
link, and later visited by the normal tree walk, is expanded only
once; the cached result object is then returned as-is for the second
location. Both places in the output tree end up holding the same
dict, so mutating one of them silently mutates the other.
Deepcopy the value on every cache read so that each place in the
output tree holds an independent object. Add a regression test that
mutates one cached location and checks the others stay untouched.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
open() without an encoding argument decodes the file with the
platform's locale-dependent default, so the same YAML file can be
decoded differently (or fail) on hosts with different locale
settings. YAML files are expected to be UTF-8, so say so
explicitly.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>