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>
The annotation 'dict[str, Any] | Any' on the cached base value
collapses to plain Any, since Any absorbs any union member. Write
the simplified form.
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 'noqa: E402' on the re import suppresses 'module level import not
at top of file', but the import is at the top of the file, so the
suppression is dead. Drop it.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
_INCLUDE_PATH_RE allows the pipe character in the target-path part of
a jw.include spec such as 'target.path|file.yaml'. The greedy match
then consumes further pipes, so a file name that itself contains a
pipe is misparsed: the target swallows part of the file name and the
remainder becomes the (nonexistent) file to open. Dots are needed in
the target part for nested paths, but a pipe can never be part of a
target path.
Drop the pipe from the character class so that the first pipe always
separates the target path from the file name. Add a regression test
with a pipe in the file name.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
A link value that is not a string (for example a number parsed from
YAML) is passed to the regular expression in _parse_link(), which
crashes with a bare TypeError from the regex engine that does not
mention the offending value or the link kind.
Make _resolve_link() validate the spec type up front and raise
TypeError naming the link kind and the value. Add tests for both
jw.link and jw.inplace-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>
When a link's target path cannot be resolved, the raw KeyError from
_resolve_path() propagates to the caller (or a raw TypeError when a
path segment hits a list), without saying which link or which
document location caused the failure. The parse-and-resolve
sequence is also duplicated in the jw.link and jw.inplace-link
branches of _expand_links_recursive().
Extract the sequence into _resolve_link() and wrap navigation
failures in ValueError naming the link kind, the spec, and the
location in the document. Document that path navigation operates on
the unexpanded tree, so intermediate segments must not be link nodes
themselves. Update the tests that pinned KeyError and add coverage
for the list-navigation case and the error message content.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
A jw.inplace-link node deep-merges its sibling keys into the resolved
target. When the target resolves to a non-dict value, the merge is
skipped and the sibling keys are silently discarded, losing document
data without any warning.
Raise ValueError when the resolved target is not a mapping and the
node carries sibling keys, and add regression tests for scalar and
list targets.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
When jw.include specifies a target path, _merge_at_path() walks the
existing document to that path. If an intermediate key holds a
non-dict value, that value is silently replaced by an empty dict; if
the leaf key holds a non-dict value, it is silently replaced by the
included mapping. Both cases discard local document data without
warning, and the leaf case even inverts the documented precedence in
which local content wins over included content (which holds for the
dict-versus-dict case).
Make _merge_at_path() raise ValueError when an existing value on or
at the target path is not a mapping, and add regression tests for
both the intermediate and the leaf case.
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 compiled regular expressions _LINK_NAME_RE and _INCLUDE_PATH_RE
are defined inline between the functions that use them, which scatters
module-level state through the file. Move both of them to the top of
the module, next to the IncludeSpec and Includes type aliases, and
group them under a Constants section header so that all module-level
definitions appear before the first function.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
Object's .name property is not backed by an overridable _name() method,
fix that. Default to the name assembled from the _name_parts() method,
much like it was before, only without braces.
.log_name is for logging, and using the _name_parts() assembly is good
for that, but .name is potentially meant to be machine readable. To be
used and decided by deriving classes.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add methods for retrieving configuration values to TreeNode. The main
benefit being that config values are looked up recursively from leaf to
root.
Signed-off-by: Jan Lindemann <jan@janware.com>
Enrich the Object class with property parent, which allows it to
participate in an object tree hierarchy.
Signed-off-by: Jan Lindemann <jan@janware.com>
The Object is going to get narrowed variants, so move it into a
submodule of its own. Keep jw.util.Object as a compatibility shim for
now.
Signed-off-by: Jan Lindemann <jan@janware.com>
Object.__init__() takes no arguments and does not call
super().__init__(), so it is a dead end for cooperative __init__ chains.
Make __init__() accept **kwargs and forward them to super().__init__()
to fix that.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
When jw.include merges content at a target path, the local content in
the main document should take precedence over the included content
(siblings win, and the main file is the ultimate source of truth).
Fix _merge_at_path so that root's existing content at the target path
wins over the value being merged in.
Also update the test_include_override_existing test to reflect the
correct semantics: local content overrides included content.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add two functions, add_hide_log_patterns() and
clear_hide_log_patterns(). Their intended purpose is to keep secrets
from leaking into logging. add_hide_log_patterns() takes compiled
regular expressions, strings or arrays thereof that are added to the
global pattern list. It defaults to ["secret", "password", "token"],
case-insensitive. clear_hide_log_patterns() clears the list, so the
caller must start from scratch building one.
This keeps sensitive keys visible for debugging while suppressing
their child values from log output.
In addition to these two functions, debug logging was removed in some
places where the effort of keeping would have outweighed the gain.
Signed-off-by: Jan Lindemann <jan@janware.com>
frame_parameters() returns a dictionary of name -> value pairs with
the parameters of the current call frames.
They can be limited by specifying exclude_names and exclude_values
which do the obvious thing.
Signed-off-by: Jan Lindemann <jan@janware.com>
Make Auth.Kind inherit from Flag rather than Enum, and introduce
Kind.Both, allowing an entity to be both Group and User.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
Add proper type annotations to fix mypy warn_return_any errors.
The following files were modified to add cast() calls or return
type annotations where functions returned Any values:
- algo/ShuntingYard.py: Add cast for operator() return value
- auth/Auth.py: Add cast for load() return value, fix imports
- cast.py: Fix cast_str_to_int return type, fix _strip type
- db/TableIoHandler.py: Remove redundant cast, fix store() return
- db/query/Queries.py: Add cast for _run() and __getitem__ returns
- db/query/Query.py: Add cast for db property return
- db/query/QueryResult.py: Add cast for db and query property returns
- db/schema/Schema.py: Add return type to __tables property, cast columns
- db/schema/Table.py: Add cast for model_module_search_paths return
- ev/app/EventRouter.py: Add cast for peer_conf.get() return
- ev/base/Object.py: Add cast for get_conf_section and str_or_none returns
- ev/base/SimpleObject.py: Add cast for create() return, fix imports
- load_yaml.py: Add cast for _expand_links_recursive return
- misc.py: Fix object_builtin_name return type, add param annotations
- stree/StringTree.py: Fix get() return type with default_value variable
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
Add mypy directives disallow_any_generics, warn_redundant_casts, and
warn_unused_ignores. Fix all resulting type annotation errors:
- load_yaml.py: Add type arguments to dict, tuple, set annotations; fix
resolving dict/set types for link keys; handle str|int path types.
- misc.py: Add Mapping[str, Any] and Iterable[Any] type arguments; fix
multiline export comment to avoid bad pattern flag.
- multi_key_dict.py: Add type argument to dict[tuple, Any].
- StringTree.py: Move Any import out of TYPE_CHECKING; fix MutableMapping
type args.
- serdes.py: Add type argument to re.Match.
- Config.py: Change Config from Mapping to Mapping[str, str]; remove
unused cast.
- ev/base/Object.py, SimpleObject.py, EventLogger.py, PollerOneShot.py:
Add Mapping[str, Any] type args.
- ev/app/EventRouter.py: Add dict[str, Any] type args in inner functions.
- auth/*: Remove now-unnecessary # type: ignore[return-value] comments.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
Fix fallout of mypy --warn-unreachable --error-code=exchaustive-match.
The warn_unreachable and exhaustive-match mypy directives exposed several
classes of issues: unreachable statements after exhaustive matches,
unreachable isinstance checks on already-narrowed types, dead code after
raise statements, and missing None in type unions where the code
checked for it at runtime.
Fix the following files:
- Config.py: Broaden glob_paths parameter type to accept str, matching
the isinstance check in the function body.
- ldap.py: Remove dead code (unreachable if-block with False condition
and unreachable continue after raise).
- DataType.py: Use case _ fallback in py_type() match for exhaustive-
match compliance, remove redundant isinstance check and assertion
that were unreachable given type annotations.
- Event.py: Add | None to Dest type alias where the code checks for
None at runtime.
- EventHub.py: Add | None to peer_confs variable type annotation where
the code checks for None at runtime.
- StringTree.py: Fix is_quoted() to accept only str (not StringTree),
fix __set() path parameter type to str | None, remove dead code after
exhaustive isinstance checks, remove unnecessary assert.
- auth/ldap/Auth.py: Remove unreachable continue statement after raise.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
Fix fallout of mypy --enable-error-code=ignore-without-code check.
The multi_key_dict class had several type issues: the keys() and values()
methods could implicitly return None when a key type was specified but not
found, pyright flagged the conditional items() redefinition, and six test
call sites carried bare "# type: ignore" comments.
Add from __future__ import annotations, a _keys_from_dict() helper, and
proper parameter/return type annotations to keys(), values(), and items().
Consolidate the conditional Python 2/3 items() into a single function with
runtime dispatch. Remove all six bare type-ignores from multi_key_dict.py
and annotate the remaining pre-existing ones in other files with specific
error codes required by ignore-without-code.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>