jiti.cli.merge.source¶
Internal API
Documented for transparency — the supported public surface is the top-level jiti package. Internals can change in any release.
jiti.cli.merge.source
¶
Splice a generated section into its source file.
The transform is text-preserving: it replaces the @jiti stub's exact line span with the
generated implementation (helpers + public function), keeps the user's signature line, and
brings along the impls' imports — minus self-imports of the module being merged into.
ruff is deferred to _ruff_batch so a multi-target merge formats every touched file in one
pass. Stripping @jiti also drops the runtime contract; post-merge code is plain Python.
Classes¶
Functions¶
merge_into_source
¶
merge_into_source(
source: str, qualname: str, own_module: str, section_body: str, file_imports: str
) -> str
Return source with the @jiti stub qualname replaced by its generated implementation.
section_body is the generated unit (private helpers + public function, no markers);
file_imports is the companion's hoisted import block; own_module is the module being
merged into, whose self-imports are dropped (the symbols already live in the file). The
public function is spliced at the @jiti site (and re-indented if it's a class method);
any module-level helpers in the section body (constants, private functions, etc.) are
injected at module level near the imports — keeping them out of the class body where
they'd cause syntax errors when stacked under decorators like @staticmethod.
Non-@jiti decorators stacked above @jiti (e.g. @staticmethod, @functools.cache)
are preserved on the merged def — only the @jiti decorator line itself is dropped.
Source code in src/jiti/cli/merge/source.py
write_source
¶
Atomically replace path. Ruff is deferred to _ruff_batch at the end of run_merge,
so a multi-target merge runs ruff check and ruff format exactly once across all files.
Source code in src/jiti/cli/merge/source.py
apply_section
¶
Inline the section into source, drop the impl section. Returns source_path for ruff.
Source code in src/jiti/cli/merge/source.py
resolve_wrapper
¶
Walk module.qualname and unwrap to the underlying _JitiCallable, if any.
Plain @jiti defs surface the JitiCallable directly via attribute access; stacked
descriptors (@staticmethod @jiti, @property @jiti, etc.) surface their wrapper —
_unwrap_to_jiti_callable peels through __wrapped__ / __func__ / fget to find
the JitiCallable underneath. Same unwrap used by jiti.required_for.