Skip to main content

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 (stdlib ast).
  • 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_nodes function — Reassemble a module's canonical .py source from its graph nodes (the round-trip).
  • module_used_bindings function — Union of every contained symbol's import bindings + the module-level ones (+ any
  • nodes_for_module function — Filter queried region nodes down to one module (by module_id property).
  • regions_from_nodes function — Collect a module's top-level regions from its nodes, ordered by order_index.
  • render_binding function — Render one import-binding descriptor back to its canonical import statement.
  • render_import_block function — Derive a module's canonical import block from its used import bindings.
  • synth_import function — A synthetic from <import_name> import <local_name> binding (USES-derived).

cjm_python_decompose_core.extract

  • DecomposedModule class — One module bound to schema nodes: the module + its symbols + local edges.
  • decompose_file function — Read a .py file and decompose it (hash over the raw file bytes).
  • decompose_package function — Decompose every .py under a package dir (the lib's own importable source).
  • decompose_paths function — Decompose an explicit set of files; unparseable files are skipped (recorded by the caller).
  • decompose_text function — Parse + bind in one step from in-memory source text.
  • import_name_for function — The dotted import name a module is reachable by (drops a trailing __init__).
  • iter_py_files function — Yield .py file paths under root, skipping __pycache__/build/etc.
  • module_path_for function — The repo-relative POSIX path used as the module's identity input.

cjm_python_decompose_core.ingest

  • build_call_map function — Map UNAMBIGUOUS bare symbol names to their node ids (the CALLS target table).
  • build_import_map function — Map every module's dotted import name to its node id (the IMPORTS target table).
  • corpus_graph_elements function — Collect a decomposed corpus into the node + edge wire-dict lists extend_graph expects.
  • resolve_import function — Resolve a (possibly relative) import to an absolute dotted module name.

cjm_python_decompose_core.parse

  • ParsedModule class — The structural decomposition of one Python module.
  • ParsedSymbol class — One definition within a module (function/class/method), with its nesting.
  • SourceRegion class — One ordered top-level region of a module, held verbatim (symbol or text).
  • emit_regions function — Reassemble ordered regions into canonical .py source — the graph owns formatting.
  • iter_symbols function — Flatten the symbol tree depth-first (parent before its children).
  • monkeypatch_assignments function — Top-level monkey-patch assignments: Class.method = func (the incremental-class idiom).
  • parse_module function — Parse Python source into module docstring + imports + the symbol tree.
  • parse_regions function — Decompose a module into ordered verbatim top-level regions (the round-trip substrate).

tests.test_extract_ingest

  • test_corpus_imports_and_calls_resolve_intra_corpus function
  • test_decompose_text_builds_module_and_symbols function
  • test_external_imports_not_minted function
  • test_import_map_and_call_map function
  • test_ingest_is_idempotent_in_ids function
  • test_local_edges_about_repo_and_defines_nesting function
  • test_module_path_and_import_name function
  • test_resolve_import_relative_and_absolute function

tests.test_imports_emit

  • test_coexisting_submodule_imports_both_survive_round_trip function — import urllib.request + import urllib.error both bind urllib and both are
  • test_derived_block_is_faithful_and_prunes_dead_imports function
  • test_docstring_lines_starting_with_from_survive_derive function
  • test_emit_module_default_is_verbatim_not_derived function
  • test_emit_module_derive_imports_prunes_dead_and_keeps_bodies function
  • test_parameter_default_reference_is_not_pruned function
  • test_rebinding_imports_still_supersede function — Aliased / from-imports rebinding a name follow Python last-binding-wins —
  • test_render_binding_forms function
  • test_render_import_block_orders_dedups_and_groups function
  • test_render_import_block_wraps_long_from_lines_in_aligned_parens function
  • test_same_module_imported_twice_dedupes function — A literally duplicated plain import collapses to one statement.

tests.test_method_attribution

  • test_first_param_and_annotation_captured function
  • test_first_param_forward_ref_annotation function
  • test_first_param_unannotated_and_classes_have_none function
  • test_monkeypatch_assignments_detected function
  • test_monkeypatch_is_structural_filtering_is_downstream function
  • test_no_arg_function_has_empty_first_param function

tests.test_parse

  • parsed function
  • test_class_methods_are_children_with_method_kind function
  • test_empty_and_docstringless_module function
  • test_function_calls_are_direct_only function
  • test_import_bindings_per_symbol_and_module_level function
  • test_imports_collected_with_relative_and_submodule_forms function
  • test_iter_symbols_flattens_parents_before_children function
  • test_local_import_not_hoisted_to_bindings function
  • test_method_calls function
  • test_module_docstring_first_line function
  • test_nested_function_is_its_own_symbol_with_own_calls function
  • test_refs_are_superset_of_calls_capturing_bases_and_annotations function
  • test_syntax_error_propagates function
  • test_top_level_symbols function

tests.test_regions_emit

  • test_codetext_regions_cover_the_non_def_source function
  • test_decompose_attaches_body_and_order_to_top_level_symbols function
  • test_decompose_emit_round_trip_from_nodes function
  • test_emit_is_ast_equal_and_seam_canonical_on_messy_input function
  • test_emit_regions_round_trips_pep8_byte_exact function
  • test_parse_regions_orders_symbols_and_text function
  • test_symbol_body_is_verbatim_with_decorators_and_leading_comments function

tests_manual.imports_projection

  • sweep function — 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cjm_python_decompose_core-0.0.6.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cjm_python_decompose_core-0.0.6-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file cjm_python_decompose_core-0.0.6.tar.gz.

File metadata

File hashes

Hashes for cjm_python_decompose_core-0.0.6.tar.gz
Algorithm Hash digest
SHA256 f0c8b6b160cc3074ea29a6e5944ce8f8a1d2f067edb9c992b5d5ef6a0a5369b6
MD5 3c7007a5f36b590db4a388e50413afb8
BLAKE2b-256 ab7d1d08c42bfd68fe12fce11786c52ea8fa9da82cc064aa1c3661acc826be02

See more details on using hashes here.

File details

Details for the file cjm_python_decompose_core-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for cjm_python_decompose_core-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 93e1c887f5c754732eb55cc82e226f79f992e03953aaead53b1e973daf2cbaf4
MD5 3aff63831df0cac88b400112aaa00217
BLAKE2b-256 0c346de3367b9d7339509ce41af5ded33bf78f01012e7ba7110e2c2dacf45bba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page