A Python source-code decomposition core for context graphs: parses .py modules (docstrings, imports, and the symbol tree of functions/classes/methods with their calls) into provenance-carrying graph nodes and edges that co-reside with the markdown source-type. First source = the ecosystem's own code; generalizes to any Python corpus.
Project description
cjm-python-decompose-core
A Python source-code decomposition core for context graphs: parses .py modules (docstrings, imports, and the symbol tree of functions/classes/methods with their calls) into provenance-carrying graph nodes and edges that co-reside with the markdown source-type. First source = the ecosystem's own code; generalizes to any Python corpus.
Modules
cjm_python_decompose_core.__init__cjm_python_decompose_core.emit— Project a module BACK out of the graph (graph -> .py) — the canonical emit leg.cjm_python_decompose_core.extract— Bind parsed Python onto dev-graph-schema code nodes (the dev-domain binding).cjm_python_decompose_core.ingest— Flatten a decomposed Python corpus into graph elements (the queue-free half).cjm_python_decompose_core.parse— Schema-free Python parsing (stdlibast).tests.test_extract_ingest— Extract (parse -> schema nodes) + ingest (corpus -> graph elements) binding.tests.test_imports_emit— Imports-as-projection: deriving a module's canonical import block from bindings.tests.test_method_attribution— First-param capture + monkey-patch-assignment detection (the cross-cell method idioms).tests.test_parse— Schema-free Python parsing: docstrings, imports, the symbol tree, and calls.tests.test_regions_emit— Verbatim region decomposition + canonical emit (the authoring / round-trip substrate).tests_manual.imports_projection— Imports-as-projection faithfulness sweep over the real arc libs (corpus harness).
API
cjm_python_decompose_core.emit
emit_module_from_nodesfunction — Reassemble a module's canonical.pysource from its graph nodes (the round-trip).module_used_bindingsfunction — Union of every contained symbol's import bindings + the module-level ones (+ anynodes_for_modulefunction — Filter queried region nodes down to one module (bymodule_idproperty).regions_from_nodesfunction — Collect a module's top-level regions from its nodes, ordered byorder_index.render_bindingfunction — Render one import-binding descriptor back to its canonical import statement.render_import_blockfunction — Derive a module's canonical import block from its used import bindings.synth_importfunction — A syntheticfrom <import_name> import <local_name>binding (USES-derived).
cjm_python_decompose_core.extract
DecomposedModuleclass — One module bound to schema nodes: the module + its symbols + local edges.decompose_filefunction — Read a.pyfile and decompose it (hash over the raw file bytes).decompose_packagefunction — Decompose every.pyunder a package dir (the lib's own importable source).decompose_pathsfunction — Decompose an explicit set of files; unparseable files are skipped (recorded by the caller).decompose_textfunction — Parse + bind in one step from in-memory source text.import_name_forfunction — The dotted import name a module is reachable by (drops a trailing__init__).iter_py_filesfunction — Yield.pyfile paths underroot, skipping__pycache__/build/etc.module_path_forfunction — The repo-relative POSIX path used as the module's identity input.
cjm_python_decompose_core.ingest
build_call_mapfunction — Map UNAMBIGUOUS bare symbol names to their node ids (the CALLS target table).build_import_mapfunction — Map every module's dotted import name to its node id (the IMPORTS target table).corpus_graph_elementsfunction — Collect a decomposed corpus into the node + edge wire-dict listsextend_graphexpects.resolve_importfunction — Resolve a (possibly relative) import to an absolute dotted module name.
cjm_python_decompose_core.parse
ParsedModuleclass — The structural decomposition of one Python module.ParsedSymbolclass — One definition within a module (function/class/method), with its nesting.SourceRegionclass — One ordered top-level region of a module, held verbatim (symbol or text).emit_regionsfunction — Reassemble ordered regions into canonical.pysource — the graph owns formatting.iter_symbolsfunction — Flatten the symbol tree depth-first (parent before its children).monkeypatch_assignmentsfunction — Top-level monkey-patch assignments:Class.method = func(the incremental-class idiom).parse_modulefunction — Parse Python source into module docstring + imports + the symbol tree.parse_regionsfunction — Decompose a module into ordered verbatim top-level regions (the round-trip substrate).
tests.test_extract_ingest
test_corpus_imports_and_calls_resolve_intra_corpusfunctiontest_decompose_text_builds_module_and_symbolsfunctiontest_external_imports_not_mintedfunctiontest_import_map_and_call_mapfunctiontest_ingest_is_idempotent_in_idsfunctiontest_local_edges_about_repo_and_defines_nestingfunctiontest_module_path_and_import_namefunctiontest_resolve_import_relative_and_absolutefunction
tests.test_imports_emit
test_coexisting_submodule_imports_both_survive_round_tripfunction — import urllib.request + import urllib.error both bindurlliband both aretest_derived_block_is_faithful_and_prunes_dead_importsfunctiontest_docstring_lines_starting_with_from_survive_derivefunctiontest_emit_module_default_is_verbatim_not_derivedfunctiontest_emit_module_derive_imports_prunes_dead_and_keeps_bodiesfunctiontest_parameter_default_reference_is_not_prunedfunctiontest_rebinding_imports_still_supersedefunction — Aliased / from-imports rebinding a name follow Python last-binding-wins —test_render_binding_formsfunctiontest_render_import_block_orders_dedups_and_groupsfunctiontest_render_import_block_wraps_long_from_lines_in_aligned_parensfunctiontest_same_module_imported_twice_dedupesfunction — A literally duplicated plain import collapses to one statement.
tests.test_method_attribution
test_first_param_and_annotation_capturedfunctiontest_first_param_forward_ref_annotationfunctiontest_first_param_unannotated_and_classes_have_nonefunctiontest_monkeypatch_assignments_detectedfunctiontest_monkeypatch_is_structural_filtering_is_downstreamfunctiontest_no_arg_function_has_empty_first_paramfunction
tests.test_parse
parsedfunctiontest_class_methods_are_children_with_method_kindfunctiontest_empty_and_docstringless_modulefunctiontest_function_calls_are_direct_onlyfunctiontest_import_bindings_per_symbol_and_module_levelfunctiontest_imports_collected_with_relative_and_submodule_formsfunctiontest_iter_symbols_flattens_parents_before_childrenfunctiontest_local_import_not_hoisted_to_bindingsfunctiontest_method_callsfunctiontest_module_docstring_first_linefunctiontest_nested_function_is_its_own_symbol_with_own_callsfunctiontest_refs_are_superset_of_calls_capturing_bases_and_annotationsfunctiontest_syntax_error_propagatesfunctiontest_top_level_symbolsfunction
tests.test_regions_emit
test_codetext_regions_cover_the_non_def_sourcefunctiontest_decompose_attaches_body_and_order_to_top_level_symbolsfunctiontest_decompose_emit_round_trip_from_nodesfunctiontest_emit_is_ast_equal_and_seam_canonical_on_messy_inputfunctiontest_emit_regions_round_trips_pep8_byte_exactfunctiontest_parse_regions_orders_symbols_and_textfunctiontest_symbol_body_is_verbatim_with_decorators_and_leading_commentsfunction
tests_manual.imports_projection
sweepfunction — Decompose every arc-lib module and tally false prunes + genuine dead-import prunes.
Dependencies
Depends on: cjm-dev-graph-schema
Used by: cjm-context-graph-projection, cjm-notebook-decompose-core
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cjm_python_decompose_core-0.0.6.tar.gz.
File metadata
- Download URL: cjm_python_decompose_core-0.0.6.tar.gz
- Upload date:
- Size: 34.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0c8b6b160cc3074ea29a6e5944ce8f8a1d2f067edb9c992b5d5ef6a0a5369b6
|
|
| MD5 |
3c7007a5f36b590db4a388e50413afb8
|
|
| BLAKE2b-256 |
ab7d1d08c42bfd68fe12fce11786c52ea8fa9da82cc064aa1c3661acc826be02
|
File details
Details for the file cjm_python_decompose_core-0.0.6-py3-none-any.whl.
File metadata
- Download URL: cjm_python_decompose_core-0.0.6-py3-none-any.whl
- Upload date:
- Size: 27.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93e1c887f5c754732eb55cc82e226f79f992e03953aaead53b1e973daf2cbaf4
|
|
| MD5 |
3aff63831df0cac88b400112aaa00217
|
|
| BLAKE2b-256 |
0c346de3367b9d7339509ce41af5ded33bf78f01012e7ba7110e2c2dacf45bba
|