stubber.codemod.enrich¶
Enrich firmware stubs by copying docstrings and parameter information from doc-stubs or python source code. Both (.py or .pyi) files are supported.
Classes¶
A match between a target and source file to merge docstrings and typehints |
Functions¶
|
Given a target and source path, return the package name based on the path. |
|
Compare package names, return True if they are equal, ignoring an _ or u-prefix and case |
Given a target and source path, return a list of tuples of (target, source, package name) that are candidates for merging. |
|
|
Enrich firmware stubs using the doc-stubs in another folder. |
|
Generate a list of merge candidates for the source and target folders. |
|
Enrich a folder containing firmware stubs using the doc-stubs in another folder. |
|
Guess the port name from the folder contents. |
Module Contents¶
- class stubber.codemod.enrich.MergeMatch¶
A match between a target and source file to merge docstrings and typehints
- target: pathlib.Path¶
- source: pathlib.Path¶
- stubber.codemod.enrich.package_from_path(target: pathlib.Path, source: pathlib.Path | None = None) str¶
Given a target and source path, return the package name based on the path.
- Parameters:
target (pathlib.Path)
source (Optional[pathlib.Path])
- Return type:
- stubber.codemod.enrich.upackage_equal(src: str, target: str) Tuple[bool, int]¶
Compare package names, return True if they are equal, ignoring an _ or u-prefix and case
- stubber.codemod.enrich.source_target_candidates(source: pathlib.Path, target: pathlib.Path, ext: str | None = None) collections.abc.Generator[MergeMatch, None, None]¶
Given a target and source path, return a list of tuples of (target, source, package name) that are candidates for merging. Goal is to match the target and source files based on the package name, to avoid mismatched merges of docstrings and typehints
Returns a generator of tuples of (target, source, target_package, source_package, is_partial_match)
- Parameters:
source (pathlib.Path)
target (pathlib.Path)
ext (Optional[str])
- Return type:
collections.abc.Generator[MergeMatch, None, None]
- stubber.codemod.enrich.enrich_file(source_path: pathlib.Path, target_path: pathlib.Path, diff: bool = False, write_back: bool = False, copy_params: bool = False, copy_docstr: bool = False, copy_returns: bool = False) collections.abc.Generator[str, None, None]¶
Enrich firmware stubs using the doc-stubs in another folder. Both (.py or .pyi) files are supported. Both source an target files must exist, and are assumed to match. Any matching of source and target files should be done before calling this function.
- Parameters:
source_path (pathlib.Path) – the path to the firmware stub-file to enrich
docstub_path – the path to the file containing the doc-stubs
diff (bool) – if True, return the diff between the original and the enriched source file
write_back (bool) – if True, write the enriched source file back to the source_path
target_path (pathlib.Path)
copy_params (bool)
copy_docstr (bool)
copy_returns (bool)
- Return type:
collections.abc.Generator[str, None, None]
Returns: - None or a string containing the diff between the original and the enriched source file
- stubber.codemod.enrich.merge_candidates(source_folder: pathlib.Path, target_folder: pathlib.Path) List[MergeMatch]¶
Generate a list of merge candidates for the source and target folders. Each target is matched with exactly one source file.
- Parameters:
source_folder (pathlib.Path)
target_folder (pathlib.Path)
- Return type:
List[MergeMatch]
- stubber.codemod.enrich.enrich_folder(source_folder: pathlib.Path, target_folder: pathlib.Path, show_diff: bool = False, write_back: bool = False, require_docstub: bool = False, copy_params: bool = False, ext: str | None = None, copy_docstr: bool = False, copy_returns: bool = False) int¶
Enrich a folder containing firmware stubs using the doc-stubs in another folder.
Returns the number of files enriched.
- Parameters:
source_folder (pathlib.Path)
target_folder (pathlib.Path)
show_diff (bool)
write_back (bool)
require_docstub (bool)
copy_params (bool)
ext (Optional[str])
copy_docstr (bool)
copy_returns (bool)
- Return type:
- stubber.codemod.enrich.guess_port_from_path(folder: pathlib.Path) str¶
Guess the port name from the folder contents. ( could also be done based on the path name)
- Parameters:
folder (pathlib.Path)
- Return type: