cjm-python-decompose-core 0.0.6__tar.gz → 0.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/PKG-INFO +26 -79
- cjm_python_decompose_core-0.0.8/README.md +77 -0
- cjm_python_decompose_core-0.0.8/cjm_python_decompose_core/__init__.py +1 -0
- cjm_python_decompose_core-0.0.8/cjm_python_decompose_core/elements.py +480 -0
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/cjm_python_decompose_core/emit.py +67 -131
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/cjm_python_decompose_core/extract.py +23 -5
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/cjm_python_decompose_core/parse.py +45 -2
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/cjm_python_decompose_core.egg-info/PKG-INFO +26 -79
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/cjm_python_decompose_core.egg-info/SOURCES.txt +2 -0
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/cjm_python_decompose_core.egg-info/requires.txt +1 -1
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/pyproject.toml +1 -1
- cjm_python_decompose_core-0.0.8/tests/test_elements.py +220 -0
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/tests/test_extract_ingest.py +34 -3
- cjm_python_decompose_core-0.0.8/tests/test_imports_emit.py +165 -0
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/tests/test_parse.py +11 -2
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/tests/test_regions_emit.py +13 -2
- cjm_python_decompose_core-0.0.6/README.md +0 -130
- cjm_python_decompose_core-0.0.6/cjm_python_decompose_core/__init__.py +0 -1
- cjm_python_decompose_core-0.0.6/tests/test_imports_emit.py +0 -183
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/LICENSE +0 -0
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/cjm_python_decompose_core/ingest.py +0 -0
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/cjm_python_decompose_core.egg-info/dependency_links.txt +0 -0
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/cjm_python_decompose_core.egg-info/top_level.txt +0 -0
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/setup.cfg +0 -0
- {cjm_python_decompose_core-0.0.6 → cjm_python_decompose_core-0.0.8}/tests/test_method_attribution.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cjm-python-decompose-core
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.8
|
|
4
4
|
Summary: 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.
|
|
5
5
|
Author-email: "Christian J. Mills" <9126128+cj-mills@users.noreply.github.com>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -10,7 +10,7 @@ Classifier: Programming Language :: Python :: 3 :: Only
|
|
|
10
10
|
Requires-Python: >=3.12
|
|
11
11
|
Description-Content-Type: text/markdown
|
|
12
12
|
License-File: LICENSE
|
|
13
|
-
Requires-Dist: cjm-dev-graph-schema>=0.0.
|
|
13
|
+
Requires-Dist: cjm-dev-graph-schema>=0.0.28
|
|
14
14
|
Requires-Dist: cjm-context-graph-layer>=0.0.7
|
|
15
15
|
Requires-Dist: cjm-context-graph-primitives>=0.0.12
|
|
16
16
|
Dynamic: license-file
|
|
@@ -24,28 +24,38 @@ A Python source-code decomposition core for context graphs: parses .py modules (
|
|
|
24
24
|
## Modules
|
|
25
25
|
|
|
26
26
|
- **`cjm_python_decompose_core.__init__`**
|
|
27
|
+
- **`cjm_python_decompose_core.elements`** — The element source unit for Python modules (design abfc2829 (1); d26e00f9; 3e155cd6).
|
|
27
28
|
- **`cjm_python_decompose_core.emit`** — Project a module BACK out of the graph (graph -> .py) — the canonical emit leg.
|
|
28
29
|
- **`cjm_python_decompose_core.extract`** — Bind parsed Python onto dev-graph-schema code nodes (the dev-domain binding).
|
|
29
30
|
- **`cjm_python_decompose_core.ingest`** — Flatten a decomposed Python corpus into graph elements (the queue-free half).
|
|
30
31
|
- **`cjm_python_decompose_core.parse`** — Schema-free Python parsing (stdlib `ast`).
|
|
31
|
-
- **`tests.test_extract_ingest`** — Extract (parse -> schema nodes) + ingest (corpus -> graph elements) binding.
|
|
32
|
-
- **`tests.test_imports_emit`** — Imports-as-projection: deriving a module's canonical import block from bindings.
|
|
33
|
-
- **`tests.test_method_attribution`** — First-param capture + monkey-patch-assignment detection (the cross-cell method idioms).
|
|
34
|
-
- **`tests.test_parse`** — Schema-free Python parsing: docstrings, imports, the symbol tree, and calls.
|
|
35
|
-
- **`tests.test_regions_emit`** — Verbatim region decomposition + canonical emit (the authoring / round-trip substrate).
|
|
36
|
-
- **`tests_manual.imports_projection`** — Imports-as-projection faithfulness sweep over the real arc libs (corpus harness).
|
|
37
32
|
|
|
38
33
|
## API
|
|
39
34
|
|
|
35
|
+
### `cjm_python_decompose_core.elements`
|
|
36
|
+
|
|
37
|
+
- `CodeElement` _class_ — One element of a module, its text at depth 0.
|
|
38
|
+
- `LiftedModule` _class_ — A module decomposed in the element regime: its elements (one `imports` element among them,
|
|
39
|
+
- `binding_union` _function_ — The union of a module's bindings -- the input the import block renders from.
|
|
40
|
+
- `class_members` _function_ — A class's members as 0-based inclusive line spans: the class's own text ends at `anchor`,
|
|
41
|
+
- `compose_elements` _function_ — Compose elements back into a module: members re-indented by depth, every seam derived.
|
|
42
|
+
- `compose_module` _function_ — Compose a captured module: the imports element's text is rendered from the union of every
|
|
43
|
+
- `decompose_elements` _function_ — Decompose a module into elements -- top-level regions, then class members recursively. A
|
|
44
|
+
- `element_names` _function_ — The names an element's own text uses -- what claims an import binding (abfc2829 (3): a binding
|
|
45
|
+
- `import_slot` _function_ — The import block's derived slot: after a leading docstring or comment preamble, else first --
|
|
46
|
+
- `lift_imports` _function_ — Decompose a module in the element regime: lift its leading run of imports (after the module
|
|
47
|
+
- `string_lines` _function_ — The lines a string literal continues onto -- their whitespace is the string's value.
|
|
48
|
+
- `string_reads` _function_ — The names an element reads through a STRING -- a fixture string (`usefixtures("db")`,
|
|
49
|
+
- `unresolved_names` _function_ — The names a module reads that no module-level binding (an import, an assignment, a def or class,
|
|
50
|
+
|
|
40
51
|
### `cjm_python_decompose_core.emit`
|
|
41
52
|
|
|
42
|
-
- `emit_module_from_nodes` _function_ — Reassemble a module's
|
|
43
|
-
- `module_used_bindings` _function_ — Union of every contained symbol's import bindings + the module-level ones (+ any
|
|
53
|
+
- `emit_module_from_nodes` _function_ — Reassemble a module's `.py` source from its graph nodes (the round-trip): its ordered
|
|
44
54
|
- `nodes_for_module` _function_ — Filter queried region nodes down to one module (by `module_id` property).
|
|
45
55
|
- `regions_from_nodes` _function_ — Collect a module's top-level regions from its nodes, ordered by `order_index`.
|
|
46
56
|
- `render_binding` _function_ — Render one import-binding descriptor back to its canonical import statement.
|
|
47
|
-
- `render_import_block` _function_ —
|
|
48
|
-
- `
|
|
57
|
+
- `render_import_block` _function_ — Render a module's canonical import block from its import bindings (the element regime's
|
|
58
|
+
- `sibling_modules` _function_ — The modules a bare import in `module_path` reaches as siblings: `<dir>/<name>.py` and
|
|
49
59
|
|
|
50
60
|
### `cjm_python_decompose_core.extract`
|
|
51
61
|
|
|
@@ -70,78 +80,15 @@ A Python source-code decomposition core for context graphs: parses .py modules (
|
|
|
70
80
|
- `ParsedModule` _class_ — The structural decomposition of one Python module.
|
|
71
81
|
- `ParsedSymbol` _class_ — One definition within a module (function/class/method), with its nesting.
|
|
72
82
|
- `SourceRegion` _class_ — One ordered top-level region of a module, held verbatim (symbol or text).
|
|
83
|
+
- `accessor_of` _function_ — Whether a def continues the accessor chain of the def directly before it: `@<name>.setter`,
|
|
73
84
|
- `emit_regions` _function_ — Reassemble ordered regions into canonical `.py` source — the graph owns formatting.
|
|
74
85
|
- `iter_symbols` _function_ — Flatten the symbol tree depth-first (parent before its children).
|
|
75
86
|
- `monkeypatch_assignments` _function_ — Top-level monkey-patch assignments: `Class.method = func` (the incremental-class idiom).
|
|
76
87
|
- `parse_module` _function_ — Parse Python source into module docstring + imports + the symbol tree.
|
|
77
88
|
- `parse_regions` _function_ — Decompose a module into ordered verbatim top-level regions (the round-trip substrate).
|
|
78
|
-
|
|
79
|
-
### `tests.test_extract_ingest`
|
|
80
|
-
|
|
81
|
-
- `test_corpus_imports_and_calls_resolve_intra_corpus` _function_
|
|
82
|
-
- `test_decompose_text_builds_module_and_symbols` _function_
|
|
83
|
-
- `test_external_imports_not_minted` _function_
|
|
84
|
-
- `test_import_map_and_call_map` _function_
|
|
85
|
-
- `test_ingest_is_idempotent_in_ids` _function_
|
|
86
|
-
- `test_local_edges_about_repo_and_defines_nesting` _function_
|
|
87
|
-
- `test_module_path_and_import_name` _function_
|
|
88
|
-
- `test_resolve_import_relative_and_absolute` _function_
|
|
89
|
-
|
|
90
|
-
### `tests.test_imports_emit`
|
|
91
|
-
|
|
92
|
-
- `test_coexisting_submodule_imports_both_survive_round_trip` _function_ — import urllib.request + import urllib.error both bind `urllib` and both are
|
|
93
|
-
- `test_derived_block_is_faithful_and_prunes_dead_imports` _function_
|
|
94
|
-
- `test_docstring_lines_starting_with_from_survive_derive` _function_
|
|
95
|
-
- `test_emit_module_default_is_verbatim_not_derived` _function_
|
|
96
|
-
- `test_emit_module_derive_imports_prunes_dead_and_keeps_bodies` _function_
|
|
97
|
-
- `test_parameter_default_reference_is_not_pruned` _function_
|
|
98
|
-
- `test_rebinding_imports_still_supersede` _function_ — Aliased / from-imports rebinding a name follow Python last-binding-wins —
|
|
99
|
-
- `test_render_binding_forms` _function_
|
|
100
|
-
- `test_render_import_block_orders_dedups_and_groups` _function_
|
|
101
|
-
- `test_render_import_block_wraps_long_from_lines_in_aligned_parens` _function_
|
|
102
|
-
- `test_same_module_imported_twice_dedupes` _function_ — A literally duplicated plain import collapses to one statement.
|
|
103
|
-
|
|
104
|
-
### `tests.test_method_attribution`
|
|
105
|
-
|
|
106
|
-
- `test_first_param_and_annotation_captured` _function_
|
|
107
|
-
- `test_first_param_forward_ref_annotation` _function_
|
|
108
|
-
- `test_first_param_unannotated_and_classes_have_none` _function_
|
|
109
|
-
- `test_monkeypatch_assignments_detected` _function_
|
|
110
|
-
- `test_monkeypatch_is_structural_filtering_is_downstream` _function_
|
|
111
|
-
- `test_no_arg_function_has_empty_first_param` _function_
|
|
112
|
-
|
|
113
|
-
### `tests.test_parse`
|
|
114
|
-
|
|
115
|
-
- `parsed` _function_
|
|
116
|
-
- `test_class_methods_are_children_with_method_kind` _function_
|
|
117
|
-
- `test_empty_and_docstringless_module` _function_
|
|
118
|
-
- `test_function_calls_are_direct_only` _function_
|
|
119
|
-
- `test_import_bindings_per_symbol_and_module_level` _function_
|
|
120
|
-
- `test_imports_collected_with_relative_and_submodule_forms` _function_
|
|
121
|
-
- `test_iter_symbols_flattens_parents_before_children` _function_
|
|
122
|
-
- `test_local_import_not_hoisted_to_bindings` _function_
|
|
123
|
-
- `test_method_calls` _function_
|
|
124
|
-
- `test_module_docstring_first_line` _function_
|
|
125
|
-
- `test_nested_function_is_its_own_symbol_with_own_calls` _function_
|
|
126
|
-
- `test_refs_are_superset_of_calls_capturing_bases_and_annotations` _function_
|
|
127
|
-
- `test_syntax_error_propagates` _function_
|
|
128
|
-
- `test_top_level_symbols` _function_
|
|
129
|
-
|
|
130
|
-
### `tests.test_regions_emit`
|
|
131
|
-
|
|
132
|
-
- `test_codetext_regions_cover_the_non_def_source` _function_
|
|
133
|
-
- `test_decompose_attaches_body_and_order_to_top_level_symbols` _function_
|
|
134
|
-
- `test_decompose_emit_round_trip_from_nodes` _function_
|
|
135
|
-
- `test_emit_is_ast_equal_and_seam_canonical_on_messy_input` _function_
|
|
136
|
-
- `test_emit_regions_round_trips_pep8_byte_exact` _function_
|
|
137
|
-
- `test_parse_regions_orders_symbols_and_text` _function_
|
|
138
|
-
- `test_symbol_body_is_verbatim_with_decorators_and_leading_comments` _function_
|
|
139
|
-
|
|
140
|
-
### `tests_manual.imports_projection`
|
|
141
|
-
|
|
142
|
-
- `sweep` _function_ — Decompose every arc-lib module and tally false prunes + genuine dead-import prunes.
|
|
89
|
+
- `source_lines` _function_ — Split source where the tokenizer counts lines -- at \n, \r\n and \r only. `str.splitlines` also
|
|
143
90
|
|
|
144
91
|
## Dependencies
|
|
145
92
|
|
|
146
|
-
**Depends on:** `cjm-dev-graph-schema`
|
|
147
|
-
**Used by:** `cjm-context-graph-projection`, `cjm-notebook-decompose-core`
|
|
93
|
+
**Depends on:** `cjm-context-graph-layer`, `cjm-context-graph-primitives`, `cjm-dev-graph-schema`
|
|
94
|
+
**Used by:** `cjm-context-graph-projection`, `cjm-notebook-decompose-core`, `cjm-substrate`
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# cjm-python-decompose-core
|
|
2
|
+
|
|
3
|
+
<!-- generated from the context graph by `cjm-context-graph readme` — do not edit by hand; edit the graph (the urge to hand-edit = move it on-graph) -->
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
## Modules
|
|
8
|
+
|
|
9
|
+
- **`cjm_python_decompose_core.__init__`**
|
|
10
|
+
- **`cjm_python_decompose_core.elements`** — The element source unit for Python modules (design abfc2829 (1); d26e00f9; 3e155cd6).
|
|
11
|
+
- **`cjm_python_decompose_core.emit`** — Project a module BACK out of the graph (graph -> .py) — the canonical emit leg.
|
|
12
|
+
- **`cjm_python_decompose_core.extract`** — Bind parsed Python onto dev-graph-schema code nodes (the dev-domain binding).
|
|
13
|
+
- **`cjm_python_decompose_core.ingest`** — Flatten a decomposed Python corpus into graph elements (the queue-free half).
|
|
14
|
+
- **`cjm_python_decompose_core.parse`** — Schema-free Python parsing (stdlib `ast`).
|
|
15
|
+
|
|
16
|
+
## API
|
|
17
|
+
|
|
18
|
+
### `cjm_python_decompose_core.elements`
|
|
19
|
+
|
|
20
|
+
- `CodeElement` _class_ — One element of a module, its text at depth 0.
|
|
21
|
+
- `LiftedModule` _class_ — A module decomposed in the element regime: its elements (one `imports` element among them,
|
|
22
|
+
- `binding_union` _function_ — The union of a module's bindings -- the input the import block renders from.
|
|
23
|
+
- `class_members` _function_ — A class's members as 0-based inclusive line spans: the class's own text ends at `anchor`,
|
|
24
|
+
- `compose_elements` _function_ — Compose elements back into a module: members re-indented by depth, every seam derived.
|
|
25
|
+
- `compose_module` _function_ — Compose a captured module: the imports element's text is rendered from the union of every
|
|
26
|
+
- `decompose_elements` _function_ — Decompose a module into elements -- top-level regions, then class members recursively. A
|
|
27
|
+
- `element_names` _function_ — The names an element's own text uses -- what claims an import binding (abfc2829 (3): a binding
|
|
28
|
+
- `import_slot` _function_ — The import block's derived slot: after a leading docstring or comment preamble, else first --
|
|
29
|
+
- `lift_imports` _function_ — Decompose a module in the element regime: lift its leading run of imports (after the module
|
|
30
|
+
- `string_lines` _function_ — The lines a string literal continues onto -- their whitespace is the string's value.
|
|
31
|
+
- `string_reads` _function_ — The names an element reads through a STRING -- a fixture string (`usefixtures("db")`,
|
|
32
|
+
- `unresolved_names` _function_ — The names a module reads that no module-level binding (an import, an assignment, a def or class,
|
|
33
|
+
|
|
34
|
+
### `cjm_python_decompose_core.emit`
|
|
35
|
+
|
|
36
|
+
- `emit_module_from_nodes` _function_ — Reassemble a module's `.py` source from its graph nodes (the round-trip): its ordered
|
|
37
|
+
- `nodes_for_module` _function_ — Filter queried region nodes down to one module (by `module_id` property).
|
|
38
|
+
- `regions_from_nodes` _function_ — Collect a module's top-level regions from its nodes, ordered by `order_index`.
|
|
39
|
+
- `render_binding` _function_ — Render one import-binding descriptor back to its canonical import statement.
|
|
40
|
+
- `render_import_block` _function_ — Render a module's canonical import block from its import bindings (the element regime's
|
|
41
|
+
- `sibling_modules` _function_ — The modules a bare import in `module_path` reaches as siblings: `<dir>/<name>.py` and
|
|
42
|
+
|
|
43
|
+
### `cjm_python_decompose_core.extract`
|
|
44
|
+
|
|
45
|
+
- `DecomposedModule` _class_ — One module bound to schema nodes: the module + its symbols + local edges.
|
|
46
|
+
- `decompose_file` _function_ — Read a `.py` file and decompose it (hash over the raw file bytes).
|
|
47
|
+
- `decompose_package` _function_ — Decompose every `.py` under a package dir (the lib's own importable source).
|
|
48
|
+
- `decompose_paths` _function_ — Decompose an explicit set of files; unparseable files are skipped (recorded by the caller).
|
|
49
|
+
- `decompose_text` _function_ — Parse + bind in one step from in-memory source text.
|
|
50
|
+
- `import_name_for` _function_ — The dotted import name a module is reachable by (drops a trailing `__init__`).
|
|
51
|
+
- `iter_py_files` _function_ — Yield `.py` file paths under `root`, skipping `__pycache__`/build/etc.
|
|
52
|
+
- `module_path_for` _function_ — The repo-relative POSIX path used as the module's identity input.
|
|
53
|
+
|
|
54
|
+
### `cjm_python_decompose_core.ingest`
|
|
55
|
+
|
|
56
|
+
- `build_call_map` _function_ — Map UNAMBIGUOUS bare symbol names to their node ids (the CALLS target table).
|
|
57
|
+
- `build_import_map` _function_ — Map every module's dotted import name to its node id (the IMPORTS target table).
|
|
58
|
+
- `corpus_graph_elements` _function_ — Collect a decomposed corpus into the node + edge wire-dict lists `extend_graph` expects.
|
|
59
|
+
- `resolve_import` _function_ — Resolve a (possibly relative) import to an absolute dotted module name.
|
|
60
|
+
|
|
61
|
+
### `cjm_python_decompose_core.parse`
|
|
62
|
+
|
|
63
|
+
- `ParsedModule` _class_ — The structural decomposition of one Python module.
|
|
64
|
+
- `ParsedSymbol` _class_ — One definition within a module (function/class/method), with its nesting.
|
|
65
|
+
- `SourceRegion` _class_ — One ordered top-level region of a module, held verbatim (symbol or text).
|
|
66
|
+
- `accessor_of` _function_ — Whether a def continues the accessor chain of the def directly before it: `@<name>.setter`,
|
|
67
|
+
- `emit_regions` _function_ — Reassemble ordered regions into canonical `.py` source — the graph owns formatting.
|
|
68
|
+
- `iter_symbols` _function_ — Flatten the symbol tree depth-first (parent before its children).
|
|
69
|
+
- `monkeypatch_assignments` _function_ — Top-level monkey-patch assignments: `Class.method = func` (the incremental-class idiom).
|
|
70
|
+
- `parse_module` _function_ — Parse Python source into module docstring + imports + the symbol tree.
|
|
71
|
+
- `parse_regions` _function_ — Decompose a module into ordered verbatim top-level regions (the round-trip substrate).
|
|
72
|
+
- `source_lines` _function_ — Split source where the tokenizer counts lines -- at \n, \r\n and \r only. `str.splitlines` also
|
|
73
|
+
|
|
74
|
+
## Dependencies
|
|
75
|
+
|
|
76
|
+
**Depends on:** `cjm-context-graph-layer`, `cjm-context-graph-primitives`, `cjm-dev-graph-schema`
|
|
77
|
+
**Used by:** `cjm-context-graph-projection`, `cjm-notebook-decompose-core`, `cjm-substrate`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.8"
|