codmap 0.0.35__tar.gz → 0.0.37__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.
- {codmap-0.0.35 → codmap-0.0.37}/PKG-INFO +2 -2
- {codmap-0.0.35 → codmap-0.0.37}/README.md +1 -1
- {codmap-0.0.35 → codmap-0.0.37}/codemap/cli.py +27 -2
- {codmap-0.0.35 → codmap-0.0.37}/codemap/diagnostics.py +24 -1
- {codmap-0.0.35 → codmap-0.0.37}/codemap/extract/behavior.py +11 -1
- {codmap-0.0.35 → codmap-0.0.37}/codemap/extract/griffe_extractor.py +46 -6
- {codmap-0.0.35 → codmap-0.0.37}/codemap/extract/gsource.py +7 -2
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/currency.py +6 -0
- {codmap-0.0.35 → codmap-0.0.37}/codmap.egg-info/PKG-INFO +2 -2
- {codmap-0.0.35 → codmap-0.0.37}/codmap.egg-info/SOURCES.txt +2 -0
- {codmap-0.0.35 → codmap-0.0.37}/pyproject.toml +1 -1
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c91_route_vocabulary.py +4 -1
- codmap-0.0.37/tests/test_r1c92_sidecar_pair.py +126 -0
- codmap-0.0.37/tests/test_r1c95_r1c96_foreign_trees.py +166 -0
- {codmap-0.0.35 → codmap-0.0.37}/LICENSE +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/__init__.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/apidiff.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/arch.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/extract/__init__.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/extract/attrflow.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/extract/dataflow.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/extract/dispatch.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/extract/probe.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/extract/roots.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/extract/union.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/freshness.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/incremental.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/integrations/__init__.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/integrations/base.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/integrations/cocoindex.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/integrations/gate.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/integrations/gitnexus.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/integrations/registry.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/integrations/transport.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/model.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/provenance.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/query.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/scope.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/__init__.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/_scip_pb2.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/api_surface.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/apidiff.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/architecture.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/audit.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/check.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/ctags.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/impact.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/limits.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/livingdocs.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/mcp_server.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/mermaid.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/pack.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/rag.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/review.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/scip.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/semantic.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/server.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/session.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/subsystems.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/serve/vault.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/store.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/tomlio.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codemap/watch.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codmap.egg-info/dependency_links.txt +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codmap.egg-info/entry_points.txt +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codmap.egg-info/requires.txt +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/codmap.egg-info/top_level.txt +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/setup.cfg +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_epistemic.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_gitnexus_router.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_impact_depth.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_integrations.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_issue3_serve_freshness.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_livingdocs.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m0_api_surface.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m11_argcontract.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m12_dataflow.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m15_review.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m16_architecture.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m17_mcp.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m18_freshness.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m1_5_semantics.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m1_query.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m2_views.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m32_watch.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m3_serve.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m4_behavior.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m5_deep.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m6_repo_scope.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m7_dispatch.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_m9_family.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_pack_honesty.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c13_callgraph_accuracy.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c13_grep_vs_graph.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c16_semantic.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c20_attribute_edges.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c21_flat_layout.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c22_source_visible_refs.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c23_hard_python.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c24_test_mapping.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c25_provenance.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c26_deep_union.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c27_config_honesty.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c28_limit_envelope.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c29_lazy_imports.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c2_ctags.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c30_local_import_calls.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c30f1_reexport_calls.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c30f2_check_scope.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c31_path_origin.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c32_report_json.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c33_query_signature.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c34_signature_kinds.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c35_contract_location.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c36_target_resolution.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c37_rule_mutation.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c38_tool_drift.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c39_edge_resolution.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c3_arch_contract.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c3_dogfood.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c40_flow_reach.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c41_scope_membership.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c42_deep_tier_stability.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c43_incremental_splice.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c44_absent_answers.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c45_repeat_union.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c46_shadowed_definitions.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c47_incremental_resample.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c48_type_checking_imports.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c49_type_only_cycles.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c4_complexity.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c50_flow_entry_points.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c53_narrowing_declared.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c54_deterministic_rendering.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c55_override_grade.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c56_stub_files.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c57_facade_package.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c58_cycle_tangles.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c59_completeness_drop.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c5_apidiff.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c60_nested_definitions.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c62_phantom_rules.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c63_answer_format.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c64_dependency_probe.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c66_pack_direction.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c68_dotted_imports.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c69_contract_validation.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c6_pack.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c70_check_graph_currency.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c71_attribute_chain_calls.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c72_flat_inference_in_packages.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c73_cli_version.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c74_call_site_conservation.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c75_reexported_class_calls.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c76_contract_table_typo.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c77_gate_probe_battery.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c78_forbidden_chains.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c7_edge_vocab.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c80_tests_through_helpers.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c81_protocol_dispatch.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c82_review_changed_lines.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c83_foreign_graph_paths.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c84_missing_roots.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c85_mcp_graph_currency.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c86_incremental_repo_scope.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c87_review_path_base.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c89_review_docs.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c8_deadcode.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c90_currency_without_recipe.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_r1c9_incremental.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_scip_export.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_scope.py +0 -0
- {codmap-0.0.35 → codmap-0.0.37}/tests/test_subsystems.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codmap
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.37
|
|
4
4
|
Summary: Static analyzer that turns a package's source into a queryable code graph.
|
|
5
5
|
Author-email: kogriv <kogriv@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -44,7 +44,7 @@ and a **SCIP index** for interop with Sourcegraph / Glean and other precise-code
|
|
|
44
44
|
|
|
45
45
|
[](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
|
|
46
46
|
|
|
47
|
-
**Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **
|
|
47
|
+
**Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1287 tests with no failures on
|
|
48
48
|
Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
|
|
49
49
|
wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 31 ops (28 exposed
|
|
50
50
|
as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
|
|
@@ -8,7 +8,7 @@ and a **SCIP index** for interop with Sourcegraph / Glean and other precise-code
|
|
|
8
8
|
|
|
9
9
|
[](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
|
|
10
10
|
|
|
11
|
-
**Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **
|
|
11
|
+
**Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1287 tests with no failures on
|
|
12
12
|
Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
|
|
13
13
|
wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 31 ops (28 exposed
|
|
14
14
|
as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
|
|
@@ -219,8 +219,10 @@ def _cmd_build(args) -> int:
|
|
|
219
219
|
cwd=os.getcwd(), target=graph.target, scope=scope,
|
|
220
220
|
roots_base=base)
|
|
221
221
|
if incr_info is not None:
|
|
222
|
+
# R1-C92: a full build that had a reason says it — computed, never shown, before.
|
|
223
|
+
why = f" ({incr_info['reason']})" if incr_info.get("reason") else ""
|
|
222
224
|
print(f"[incremental] {incr_info['mode']}: "
|
|
223
|
-
f"{len(incr_info['affected'])} module(s) recomputed", file=sys.stderr)
|
|
225
|
+
f"{len(incr_info['affected'])} module(s) recomputed{why}", file=sys.stderr)
|
|
224
226
|
print(args.out)
|
|
225
227
|
else:
|
|
226
228
|
print(store.dumps(graph))
|
|
@@ -303,8 +305,12 @@ def _incremental_build(args):
|
|
|
303
305
|
return extract(args.path, deep=args.deep, repeat=getattr(args, "repeat", None) or 1), \
|
|
304
306
|
{"mode": "full", "affected": []}
|
|
305
307
|
old_graph = store.load(args.out)
|
|
306
|
-
new_scope = resolve_scope(args.path)
|
|
307
308
|
repeat = getattr(args, "repeat", None) or 1
|
|
309
|
+
why = _sidecar_mismatch(old_meta, old_graph)
|
|
310
|
+
if why:
|
|
311
|
+
return extract(args.path, deep=args.deep, repeat=repeat), \
|
|
312
|
+
{"mode": "full", "affected": [], "reason": why}
|
|
313
|
+
new_scope = resolve_scope(args.path)
|
|
308
314
|
if old_graph.target != Path(args.path).resolve().name:
|
|
309
315
|
return extract(args.path, deep=args.deep, repeat=repeat), {"mode": "full", "affected": []}
|
|
310
316
|
return update_graph(old_graph, args.path, old_scope, new_scope, deep=args.deep,
|
|
@@ -334,6 +340,22 @@ def _core_subgraph(graph, offset: str = ""):
|
|
|
334
340
|
return core
|
|
335
341
|
|
|
336
342
|
|
|
343
|
+
def _sidecar_mismatch(old_meta, old_graph) -> str | None:
|
|
344
|
+
"""R1-C92 D1: the sidecar is the incremental baseline only if it describes this graph.
|
|
345
|
+
|
|
346
|
+
`meta.scope` and the graph's `provenance.scope_id` are written by one build and are
|
|
347
|
+
equal for a pair that belongs together. A graph replaced from outside (an atomic `mv`
|
|
348
|
+
of a fresh build) with the old sidecar left beside it made the next incremental build
|
|
349
|
+
diff against another tree: a graph 0 next to meta 1 missed every edit between 0 and 1
|
|
350
|
+
and still said `incremental`.
|
|
351
|
+
"""
|
|
352
|
+
meta_id = ((old_meta or {}).get("scope") or {}).get("scope_id")
|
|
353
|
+
graph_id = (old_graph.provenance or {}).get("scope_id")
|
|
354
|
+
if meta_id and graph_id and meta_id != graph_id:
|
|
355
|
+
return "the sidecar describes another build than the graph"
|
|
356
|
+
return None
|
|
357
|
+
|
|
358
|
+
|
|
337
359
|
def _incremental_core(args, repeat):
|
|
338
360
|
"""Update the core of an existing repo-scoped graph at ``args.out`` (R1-C86 D1).
|
|
339
361
|
|
|
@@ -351,6 +373,9 @@ def _incremental_core(args, repeat):
|
|
|
351
373
|
if old_graph.target != Path(args.path).resolve().name or \
|
|
352
374
|
not (old_graph.provenance or {}).get("roots"):
|
|
353
375
|
return None, {"mode": "full", "affected": []}
|
|
376
|
+
why = _sidecar_mismatch(old_meta, old_graph)
|
|
377
|
+
if why:
|
|
378
|
+
return None, {"mode": "full", "affected": [], "reason": why}
|
|
354
379
|
from codemap.extract.roots import _rel_to
|
|
355
380
|
consumers, docs = tuple(args.consumer or ()), tuple(args.docs or ())
|
|
356
381
|
new_scope = resolve_scope(args.path, consumers=consumers, docs=docs)
|
|
@@ -25,6 +25,7 @@ SCOPE_MEMBERSHIP = "scope_membership"
|
|
|
25
25
|
DEEP_TIER_UNSTABLE = "deep_tier_unstable"
|
|
26
26
|
INCREMENTAL_DEEP_SPLICE = "incremental_deep_splice"
|
|
27
27
|
GRAPH_FROM_NEWER_TOOL = "graph_from_newer_tool"
|
|
28
|
+
COMPILED_MODULES_NOT_LOADED = "compiled_modules_not_loaded"
|
|
28
29
|
|
|
29
30
|
#: A ``warning`` invalidates the conclusions a surface draws from the graph — read them as
|
|
30
31
|
#: unknown. A ``note`` states a fact about how the graph was built and invalidates nothing.
|
|
@@ -193,6 +194,27 @@ def unread_inputs_diagnostic(graph) -> dict | None:
|
|
|
193
194
|
}
|
|
194
195
|
|
|
195
196
|
|
|
197
|
+
def compiled_modules_diagnostic(graph) -> dict | None:
|
|
198
|
+
"""Compiled modules without source were not loaded (R1-C96 / design D2).
|
|
199
|
+
|
|
200
|
+
A **note**: everything the graph holds is right. Until 0.0.36 griffe *imported* such a
|
|
201
|
+
module (its default ``allow_inspection``), which ran the target's code; codemap promises
|
|
202
|
+
it never imports the target, so the module is listed instead of read.
|
|
203
|
+
"""
|
|
204
|
+
compiled = ((graph.provenance or {}).get("inputs") or {}).get("compiled") or []
|
|
205
|
+
if not compiled:
|
|
206
|
+
return None
|
|
207
|
+
sample = ", ".join(compiled[:5]) + (" …" if len(compiled) > 5 else "")
|
|
208
|
+
return {
|
|
209
|
+
"code": COMPILED_MODULES_NOT_LOADED,
|
|
210
|
+
"severity": NOTE,
|
|
211
|
+
"compiled": compiled,
|
|
212
|
+
"consequence": ("The graph does not contain them: codemap never imports the target, "
|
|
213
|
+
"and a compiled module has no source to read."),
|
|
214
|
+
"message": f"{len(compiled)} compiled module(s) without source were not loaded: {sample}",
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
196
218
|
def deep_tier_diagnostic(graph) -> dict | None:
|
|
197
219
|
"""State the deep tier's noise floor on the artifact itself (R1-C42).
|
|
198
220
|
|
|
@@ -430,7 +452,8 @@ def diagnostics(graph) -> list[dict]:
|
|
|
430
452
|
cross_root_diagnostic(graph), schema_diagnostic(graph),
|
|
431
453
|
unread_inputs_diagnostic(graph), module_count_diagnostic(graph),
|
|
432
454
|
scope_membership_diagnostic(graph), deep_tier_diagnostic(graph),
|
|
433
|
-
incremental_splice_diagnostic(graph), newer_tool_diagnostic(graph)
|
|
455
|
+
incremental_splice_diagnostic(graph), newer_tool_diagnostic(graph),
|
|
456
|
+
compiled_modules_diagnostic(graph))
|
|
434
457
|
return [d for d in checks if d is not None]
|
|
435
458
|
|
|
436
459
|
|
|
@@ -27,6 +27,8 @@ import ast
|
|
|
27
27
|
import math
|
|
28
28
|
from pathlib import Path
|
|
29
29
|
|
|
30
|
+
import griffe
|
|
31
|
+
|
|
30
32
|
from codemap.extract.gsource import (NESTED_IMPORT_HINT, flat_inference_applies, module_file,
|
|
31
33
|
module_imports, qualify_target)
|
|
32
34
|
from codemap.model import Edge
|
|
@@ -360,7 +362,15 @@ def _class_members(mod, class_stack, modules) -> dict:
|
|
|
360
362
|
bmod = modules.get(".".join(modparts))
|
|
361
363
|
if bmod and cname in bmod.members:
|
|
362
364
|
bclass = bmod.members[cname]
|
|
363
|
-
|
|
365
|
+
try:
|
|
366
|
+
inherited = list(bclass.members)
|
|
367
|
+
except (griffe.AliasResolutionError, griffe.CyclicAliasError):
|
|
368
|
+
# R1-C95 / design D3: the base is the package's re-export of a class
|
|
369
|
+
# from a package nobody loaded. Its members are unknown, so
|
|
370
|
+
# `self.<inherited>()` stays unresolved, as for a base imported straight
|
|
371
|
+
# from that package; the build goes on.
|
|
372
|
+
continue
|
|
373
|
+
for name in inherited:
|
|
364
374
|
owners.setdefault(name, bclass.canonical_path) # own already set → keep
|
|
365
375
|
return owners
|
|
366
376
|
|
|
@@ -105,12 +105,16 @@ def _load_with_siblings(module_name: str, search_path: Path):
|
|
|
105
105
|
Returns ``(root, siblings)``; ``siblings`` is what had to be pulled in, and it is
|
|
106
106
|
recorded in the input report so a reader can see the load was not self-contained.
|
|
107
107
|
"""
|
|
108
|
+
# R1-C96: `allow_inspection=False` on every load. griffe's default imports a module it
|
|
109
|
+
# cannot read from source (`.so`, `.pyd`, a sourceless `.pyc`), which runs the target's
|
|
110
|
+
# code; codemap promises it never imports the target. griffe now skips such a module
|
|
111
|
+
# (LoadingError, caught per submodule) and `_input_report` lists it as `compiled`.
|
|
108
112
|
collection = griffe.ModulesCollection()
|
|
109
113
|
siblings: list[str] = []
|
|
110
114
|
for _ in range(_MAX_SIBLING_LOADS + 1):
|
|
111
115
|
try:
|
|
112
116
|
return griffe.load(module_name, search_paths=[str(search_path)],
|
|
113
|
-
try_relative_path=False,
|
|
117
|
+
try_relative_path=False, allow_inspection=False,
|
|
114
118
|
modules_collection=collection), siblings
|
|
115
119
|
except griffe.AliasResolutionError as exc:
|
|
116
120
|
top = exc.alias.target_path.split(".")[0]
|
|
@@ -119,13 +123,15 @@ def _load_with_siblings(module_name: str, search_path: Path):
|
|
|
119
123
|
if not _package_on_path(top, search_path):
|
|
120
124
|
raise ValueError(
|
|
121
125
|
f"`{module_name}` re-exports `{exc.alias.target_path}`, and "
|
|
122
|
-
f"`{top}` is not beside it in {search_path}.
|
|
123
|
-
f"layout (a public package re-exporting a private one): build
|
|
124
|
-
f"a tree that holds both, or point codemap at the implementation "
|
|
125
|
-
f"package instead."
|
|
126
|
+
f"`{top}` is not beside it in {search_path}. Either this is the "
|
|
127
|
+
f"facade layout (a public package re-exporting a private one): build "
|
|
128
|
+
f"from a tree that holds both, or point codemap at the implementation "
|
|
129
|
+
f"package instead. Or the package imports `{top}` through sys.path "
|
|
130
|
+
f"(a script layout, where `{top}` sits somewhere inside the tree): "
|
|
131
|
+
f"codemap does not build that layout yet (R1-C94)."
|
|
126
132
|
) from exc
|
|
127
133
|
griffe.load(top, search_paths=[str(search_path)], try_relative_path=False,
|
|
128
|
-
modules_collection=collection)
|
|
134
|
+
allow_inspection=False, modules_collection=collection)
|
|
129
135
|
siblings.append(top)
|
|
130
136
|
raise ValueError(
|
|
131
137
|
f"`{module_name}` still had unresolved re-exports after loading "
|
|
@@ -292,6 +298,37 @@ def _enumerate_sources(pkg_dir: Path) -> list[Path]:
|
|
|
292
298
|
return out
|
|
293
299
|
|
|
294
300
|
|
|
301
|
+
#: Module files griffe could only import, never read (R1-C96). `.pyc` in `__pycache__` is
|
|
302
|
+
#: a cache of a `.py` and is not a module of its own.
|
|
303
|
+
_COMPILED_SUFFIXES = (".so", ".pyd", ".pyc")
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def _compiled_without_source(pkg_dir: Path, root: Path) -> list[str]:
|
|
307
|
+
"""Compiled module files inside the package with no ``.py`` of the same module beside
|
|
308
|
+
them (R1-C96 / design D2). codemap never imports the target, so each is a module the
|
|
309
|
+
graph does not contain. A compiled copy beside its source is not listed: the module is
|
|
310
|
+
built from the source.
|
|
311
|
+
"""
|
|
312
|
+
out = []
|
|
313
|
+
seen: set[str] = set()
|
|
314
|
+
for dirpath, dirnames, filenames in os.walk(pkg_dir, followlinks=True):
|
|
315
|
+
real = os.path.realpath(dirpath)
|
|
316
|
+
if real in seen:
|
|
317
|
+
dirnames[:] = []
|
|
318
|
+
continue
|
|
319
|
+
seen.add(real)
|
|
320
|
+
dirnames[:] = sorted(d for d in dirnames if d != "__pycache__")
|
|
321
|
+
names = set(filenames)
|
|
322
|
+
for n in sorted(filenames):
|
|
323
|
+
if not n.endswith(_COMPILED_SUFFIXES):
|
|
324
|
+
continue
|
|
325
|
+
stem = n.split(".", 1)[0] # md.cp38-win32.pyd -> md
|
|
326
|
+
if f"{stem}.py" in names or f"{stem}.pyi" in names:
|
|
327
|
+
continue
|
|
328
|
+
out.append(_rel(Path(dirpath) / n, root))
|
|
329
|
+
return out
|
|
330
|
+
|
|
331
|
+
|
|
295
332
|
def _skip_reason(path: Path) -> str:
|
|
296
333
|
"""Why this file produced no module — asked only of files that produced none."""
|
|
297
334
|
try:
|
|
@@ -322,6 +359,9 @@ def _input_report(graph, pkg_dir: Path, root: Path, walk) -> dict:
|
|
|
322
359
|
report: dict = {"python_files": len(py)}
|
|
323
360
|
if skipped:
|
|
324
361
|
report["skipped"] = skipped
|
|
362
|
+
compiled = _compiled_without_source(pkg_dir, root)
|
|
363
|
+
if compiled:
|
|
364
|
+
report["compiled"] = compiled
|
|
325
365
|
if walk.aliased:
|
|
326
366
|
report["aliased_modules"] = [
|
|
327
367
|
{"id": mid, "same_as": owner} for mid, owner in sorted(walk.aliased)
|
|
@@ -38,11 +38,16 @@ DOTTED_IMPORT_HINT = re.compile(r"^import\s[^\n#]*\w\.\w", re.MULTILINE)
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
def module_file(obj) -> Path | None:
|
|
41
|
-
"""The single source file behind a griffe object, or ``None`` if it has none.
|
|
41
|
+
"""The single source file behind a griffe object, or ``None`` if it has none.
|
|
42
|
+
|
|
43
|
+
Only ``.py``/``.pyi`` count as source (R1-C96 / design D2): a compiled module handed
|
|
44
|
+
over by griffe is not read as text by any layer, whatever griffe chose.
|
|
45
|
+
"""
|
|
42
46
|
fp = getattr(obj, "filepath", None)
|
|
43
47
|
if fp is None or isinstance(fp, list):
|
|
44
48
|
return None
|
|
45
|
-
|
|
49
|
+
fp = Path(fp)
|
|
50
|
+
return fp if fp.suffix in (".py", ".pyi") else None
|
|
46
51
|
|
|
47
52
|
|
|
48
53
|
def is_namespace_dir(obj) -> bool:
|
|
@@ -88,6 +88,12 @@ def graph_currency(graph_path: str, graph_scope_id: str | None, *, roots: dict |
|
|
|
88
88
|
if not meta or not meta.get("argv"):
|
|
89
89
|
return _via_roots(graph_scope_id, roots, target, base,
|
|
90
90
|
"no build recipe beside the graph")
|
|
91
|
+
# R1-C92 D2: a sidecar left beside a replaced graph describes another build — its
|
|
92
|
+
# recipe and its baseline would answer for a tree this graph never saw.
|
|
93
|
+
meta_id = (meta.get("scope") or {}).get("scope_id")
|
|
94
|
+
if meta_id and meta_id != graph_scope_id:
|
|
95
|
+
return _via_roots(graph_scope_id, roots, target, base,
|
|
96
|
+
"the sidecar describes another build than the graph")
|
|
91
97
|
cwd = meta.get("cwd")
|
|
92
98
|
if not cwd or not os.path.isdir(cwd):
|
|
93
99
|
return _via_roots(graph_scope_id, roots, target, base,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codmap
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.37
|
|
4
4
|
Summary: Static analyzer that turns a package's source into a queryable code graph.
|
|
5
5
|
Author-email: kogriv <kogriv@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -44,7 +44,7 @@ and a **SCIP index** for interop with Sourcegraph / Glean and other precise-code
|
|
|
44
44
|
|
|
45
45
|
[](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
|
|
46
46
|
|
|
47
|
-
**Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **
|
|
47
|
+
**Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1287 tests with no failures on
|
|
48
48
|
Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
|
|
49
49
|
wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 31 ops (28 exposed
|
|
50
50
|
as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
|
|
@@ -163,6 +163,8 @@ tests/test_r1c89_review_docs.py
|
|
|
163
163
|
tests/test_r1c8_deadcode.py
|
|
164
164
|
tests/test_r1c90_currency_without_recipe.py
|
|
165
165
|
tests/test_r1c91_route_vocabulary.py
|
|
166
|
+
tests/test_r1c92_sidecar_pair.py
|
|
167
|
+
tests/test_r1c95_r1c96_foreign_trees.py
|
|
166
168
|
tests/test_r1c9_incremental.py
|
|
167
169
|
tests/test_scip_export.py
|
|
168
170
|
tests/test_scope.py
|
|
@@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"
|
|
|
9
9
|
# version. README says this plainly, since `pip install codmap` / `import codemap` is a
|
|
10
10
|
# seam a reader will otherwise hit by surprise.
|
|
11
11
|
name = "codmap"
|
|
12
|
-
version = "0.0.
|
|
12
|
+
version = "0.0.37"
|
|
13
13
|
description = "Static analyzer that turns a package's source into a queryable code graph."
|
|
14
14
|
readme = "README.md"
|
|
15
15
|
# M20/D1: measured, not assumed. Each release of the declared range runs the full suite in
|
|
@@ -96,7 +96,10 @@ def test_E3_unknown_routes_are_listed_with_counts(repo):
|
|
|
96
96
|
graph = _build(repo)
|
|
97
97
|
e = next(e for e in graph.edges if e.extras.get("resolution") == "imported")
|
|
98
98
|
e.extras["resolution"] = "future"
|
|
99
|
-
|
|
99
|
+
# Read the reader's version from the graph itself: a literal here went stale the moment
|
|
100
|
+
# the package version moved past it, and the graph then read as "newer" (0.0.36 release CI).
|
|
101
|
+
built = graph.provenance["tool"]["version"]
|
|
102
|
+
d = newer_tool_diagnostic(graph, running=built)
|
|
100
103
|
assert d["unrecognised"] == {f"{e.type}:future": 1}
|
|
101
104
|
assert "rebuild it with this codemap" in d["message"], "not newer: the remedy is a rebuild"
|
|
102
105
|
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""R1-C92 — a graph and its sidecar must describe one build, or the sidecar is not used.
|
|
2
|
+
|
|
3
|
+
Design `docs/design/sidecar_pair.md` (pre-registered 8f525ea).
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import shutil
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
from codemap import store
|
|
15
|
+
from codemap.cli import main
|
|
16
|
+
from codemap.serve.session import Session
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _write(root: Path, files: dict):
|
|
20
|
+
for rel, body in files.items():
|
|
21
|
+
p = root / rel
|
|
22
|
+
p.parent.mkdir(parents=True, exist_ok=True)
|
|
23
|
+
p.write_text(body)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
BASE = {"pkg/__init__.py": "", **{f"pkg/m{i}.py": f"def f{i}():\n return {i}\n" for i in range(1, 7)}}
|
|
27
|
+
STATE1 = {"pkg/m1.py": "from pkg.m3 import f3\n\n\ndef f1():\n return f3()\n"}
|
|
28
|
+
EDIT = {"pkg/m2.py": "def f2():\n return 22\n"}
|
|
29
|
+
CALL = ("calls", "pkg.m1.f1", "pkg.m3.f3")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _build(out: Path, *extra) -> str:
|
|
33
|
+
return main(["build", "pkg", "-o", str(out), *extra])
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _pair(dst: Path, graph: Path, meta_of: Path):
|
|
37
|
+
shutil.copy(graph, dst)
|
|
38
|
+
shutil.copy(str(meta_of) + ".meta.json", str(dst) + ".meta.json")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _edges(path: Path):
|
|
42
|
+
return {(e["type"], e["source"], e["target"]) for e in json.loads(path.read_text())["edges"]}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _same(a: Path, b: Path) -> bool:
|
|
46
|
+
x, y = json.loads(a.read_text()), json.loads(b.read_text())
|
|
47
|
+
for g in (x, y):
|
|
48
|
+
g["provenance"].pop("incremental", None)
|
|
49
|
+
return x == y
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@pytest.fixture
|
|
53
|
+
def tree(tmp_path, monkeypatch):
|
|
54
|
+
root = tmp_path / "t"
|
|
55
|
+
_write(root, BASE)
|
|
56
|
+
monkeypatch.chdir(root)
|
|
57
|
+
g0, g1 = tmp_path / "g0.json", tmp_path / "g1.json"
|
|
58
|
+
assert _build(g0) == 0
|
|
59
|
+
_write(root, STATE1)
|
|
60
|
+
assert _build(g1) == 0
|
|
61
|
+
return root, tmp_path, g0, g1
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_E1_graph_older_than_its_sidecar_is_rebuilt_in_full(tree, capsys):
|
|
65
|
+
root, tmp, g0, g1 = tree
|
|
66
|
+
g = tmp / "g.json"
|
|
67
|
+
_pair(g, g0, g1)
|
|
68
|
+
_write(root, EDIT)
|
|
69
|
+
capsys.readouterr()
|
|
70
|
+
assert _build(g, "--incremental") == 0
|
|
71
|
+
err = capsys.readouterr().err
|
|
72
|
+
assert "[incremental] full" in err and "the sidecar describes another build" in err
|
|
73
|
+
full = tmp / "full.json"
|
|
74
|
+
assert _build(full) == 0
|
|
75
|
+
assert CALL in _edges(g), "the edit between graph and sidecar must not be lost"
|
|
76
|
+
assert _same(g, full)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_E2_graph_newer_than_its_sidecar_is_rebuilt_in_full(tree, capsys):
|
|
80
|
+
root, tmp, g0, g1 = tree
|
|
81
|
+
g = tmp / "g.json"
|
|
82
|
+
_pair(g, g1, g0)
|
|
83
|
+
_write(root, EDIT)
|
|
84
|
+
capsys.readouterr()
|
|
85
|
+
assert _build(g, "--incremental") == 0
|
|
86
|
+
assert "the sidecar describes another build" in capsys.readouterr().err
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_E3_a_matched_pair_stays_incremental(tree, capsys):
|
|
90
|
+
root, tmp, g0, g1 = tree
|
|
91
|
+
_write(root, EDIT)
|
|
92
|
+
capsys.readouterr()
|
|
93
|
+
assert _build(g1, "--incremental") == 0
|
|
94
|
+
err = capsys.readouterr().err
|
|
95
|
+
assert "[incremental] incremental: 1 module(s) recomputed\n" in err
|
|
96
|
+
full = tmp / "full.json"
|
|
97
|
+
assert _build(full) == 0
|
|
98
|
+
assert _same(g1, full)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_E4_repo_scoped_mismatch_is_rebuilt_in_full(tmp_path, monkeypatch, capsys):
|
|
102
|
+
root = tmp_path / "t"
|
|
103
|
+
_write(root, {**BASE, "tests/test_m.py": "from pkg.m1 import f1\n\n\ndef test_f1():\n f1()\n"})
|
|
104
|
+
monkeypatch.chdir(root)
|
|
105
|
+
flags = ("--consumer", "tests", "--mode", "full")
|
|
106
|
+
g0, g1, g = tmp_path / "g0.json", tmp_path / "g1.json", tmp_path / "g.json"
|
|
107
|
+
assert _build(g0, *flags) == 0
|
|
108
|
+
_write(root, STATE1)
|
|
109
|
+
assert _build(g1, *flags) == 0
|
|
110
|
+
_pair(g, g0, g1)
|
|
111
|
+
_write(root, EDIT)
|
|
112
|
+
capsys.readouterr()
|
|
113
|
+
assert _build(g, *flags, "--incremental") == 0
|
|
114
|
+
assert "the sidecar describes another build" in capsys.readouterr().err
|
|
115
|
+
assert CALL in _edges(g)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_E5_currency_does_not_use_a_foreign_sidecar(tree):
|
|
119
|
+
root, tmp, g0, g1 = tree
|
|
120
|
+
g = tmp / "g.json"
|
|
121
|
+
_pair(g, g0, g1)
|
|
122
|
+
c = Session(store.load(str(g)), graph_path=str(g), currency_ttl=0,
|
|
123
|
+
source_root=str(root)).handle({"op": "stats"})["currency"]
|
|
124
|
+
assert c["status"] == "behind"
|
|
125
|
+
assert c["via"].startswith("provenance roots under"), c
|
|
126
|
+
assert "changed" not in c, "no counts from another build's baseline"
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"""R1-C96 — `build` never imports the target; R1-C95 — it degrades instead of crashing on foreign trees.
|
|
2
|
+
|
|
3
|
+
Design `docs/design/build_on_foreign_trees.md` (pre-registered 45592b2).
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import py_compile
|
|
10
|
+
import shutil
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
import sysconfig
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
import pytest
|
|
17
|
+
|
|
18
|
+
from codemap.diagnostics import COMPILED_MODULES_NOT_LOADED, diagnostics
|
|
19
|
+
from codemap.extract.griffe_extractor import extract
|
|
20
|
+
|
|
21
|
+
MARKER_SRC = '''import pathlib
|
|
22
|
+
pathlib.Path({marker!r}).write_text("imported")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def f():
|
|
26
|
+
return 1
|
|
27
|
+
'''
|
|
28
|
+
USER = "from pkg import evil\n\n\ndef use():\n return evil.f()\n"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _pkg(root: Path) -> Path:
|
|
32
|
+
pkg = root / "pkg"
|
|
33
|
+
pkg.mkdir(parents=True)
|
|
34
|
+
(pkg / "__init__.py").write_text("")
|
|
35
|
+
(pkg / "user.py").write_text(USER)
|
|
36
|
+
return pkg
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# -- D1 + D2: a sourceless .pyc is neither imported nor lost in silence -------------------
|
|
40
|
+
|
|
41
|
+
@pytest.fixture
|
|
42
|
+
def pyc_tree(tmp_path):
|
|
43
|
+
pkg = _pkg(tmp_path)
|
|
44
|
+
marker = tmp_path / "MARKER"
|
|
45
|
+
src = pkg / "evil.py"
|
|
46
|
+
src.write_text(MARKER_SRC.format(marker=str(marker)))
|
|
47
|
+
py_compile.compile(str(src), cfile=str(pkg / "evil.pyc"), doraise=True) # this interpreter
|
|
48
|
+
src.unlink()
|
|
49
|
+
return pkg, marker
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_E1_a_sourceless_pyc_is_not_imported(pyc_tree):
|
|
53
|
+
pkg, marker = pyc_tree
|
|
54
|
+
graph = extract(str(pkg))
|
|
55
|
+
assert not marker.exists(), "codemap imported the target: the .pyc body ran"
|
|
56
|
+
assert "pkg.user.use" in graph.nodes
|
|
57
|
+
assert "pkg.evil" not in graph.nodes
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_E2_it_is_listed_and_noted(pyc_tree):
|
|
61
|
+
pkg, _ = pyc_tree
|
|
62
|
+
graph = extract(str(pkg))
|
|
63
|
+
assert graph.provenance["inputs"]["compiled"] == ["pkg/evil.pyc"]
|
|
64
|
+
d = [x for x in diagnostics(graph) if x["code"] == COMPILED_MODULES_NOT_LOADED]
|
|
65
|
+
assert len(d) == 1 and d[0]["severity"] == "note" and "pkg/evil.pyc" in d[0]["message"]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_E1_deep_tier_does_not_import_it_either(pyc_tree):
|
|
69
|
+
pytest.importorskip("jedi")
|
|
70
|
+
pkg, marker = pyc_tree
|
|
71
|
+
extract(str(pkg), deep=True)
|
|
72
|
+
assert not marker.exists()
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _compiler():
|
|
76
|
+
cc = shutil.which("cc") or shutil.which("gcc")
|
|
77
|
+
inc = sysconfig.get_paths().get("include")
|
|
78
|
+
if not cc or not inc or not (Path(inc) / "Python.h").is_file():
|
|
79
|
+
return None
|
|
80
|
+
return cc, inc
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@pytest.mark.skipif(_compiler() is None, reason="needs a C compiler and Python headers")
|
|
84
|
+
def test_E1_a_c_extension_is_not_imported(tmp_path):
|
|
85
|
+
cc, inc = _compiler()
|
|
86
|
+
pkg = _pkg(tmp_path)
|
|
87
|
+
marker = tmp_path / "MARKER"
|
|
88
|
+
c = tmp_path / "evil.c"
|
|
89
|
+
c.write_text(
|
|
90
|
+
"#include <Python.h>\n#include <stdio.h>\n"
|
|
91
|
+
'static struct PyModuleDef m = {PyModuleDef_HEAD_INIT, "evil", NULL, -1, NULL};\n'
|
|
92
|
+
"PyMODINIT_FUNC PyInit_evil(void){FILE*f=fopen(" + f'"{marker}"' + ',"w");'
|
|
93
|
+
'if(f){fputs("imported",f);fclose(f);} return PyModule_Create(&m);}\n')
|
|
94
|
+
so = pkg / f"evil{sysconfig.get_config_var('EXT_SUFFIX')}"
|
|
95
|
+
subprocess.run([cc, "-shared", "-fPIC", f"-I{inc}", str(c), "-o", str(so)], check=True)
|
|
96
|
+
graph = extract(str(pkg))
|
|
97
|
+
assert not marker.exists(), "codemap imported the target: the extension's PyInit ran"
|
|
98
|
+
assert graph.provenance["inputs"]["compiled"] == [f"pkg/{so.name}"]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# -- D2: a compiled copy beside its source -------------------------------------------------
|
|
102
|
+
|
|
103
|
+
@pytest.mark.parametrize("reverse", [False, True], ids=["py-first", "pyd-first"])
|
|
104
|
+
def test_E3_source_wins_over_a_compiled_copy_in_either_directory_order(tmp_path, monkeypatch,
|
|
105
|
+
reverse):
|
|
106
|
+
pkg = tmp_path / "pkg"
|
|
107
|
+
pkg.mkdir()
|
|
108
|
+
(pkg / "__init__.py").write_text("")
|
|
109
|
+
(pkg / "md.py").write_text("def helper():\n return 1\n\n\ndef f():\n return helper()\n")
|
|
110
|
+
(pkg / "md.cp38-win32.pyd").write_bytes(b"MZ\x90\x00\x03\xffnot text")
|
|
111
|
+
real_walk = os.walk
|
|
112
|
+
|
|
113
|
+
def walk(top, *a, **k): # griffe's finder discovers submodules in os.walk order
|
|
114
|
+
for root, dirs, files in real_walk(top, *a, **k):
|
|
115
|
+
yield root, dirs, sorted(files, key=lambda n: n.endswith(".py"), reverse=not reverse)
|
|
116
|
+
|
|
117
|
+
monkeypatch.setattr(os, "walk", walk)
|
|
118
|
+
graph = extract(str(pkg))
|
|
119
|
+
assert {"pkg.md.helper", "pkg.md.f"} <= set(graph.nodes)
|
|
120
|
+
assert ("calls", "pkg.md.f", "pkg.md.helper") in {(e.type, e.source, e.target) for e in graph.edges}
|
|
121
|
+
assert "compiled" not in graph.provenance["inputs"]
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
# -- D3: a base class behind an unresolvable alias ----------------------------------------
|
|
125
|
+
|
|
126
|
+
def test_E4_a_base_reexported_from_an_absent_package_does_not_crash(tmp_path):
|
|
127
|
+
pkg = tmp_path / "pkg"
|
|
128
|
+
(pkg / "utils").mkdir(parents=True)
|
|
129
|
+
(pkg / "__init__.py").write_text("")
|
|
130
|
+
(pkg / "utils" / "__init__.py").write_text("")
|
|
131
|
+
(pkg / "utils" / "file_io.py").write_text("from extlib.common.file_io import PathHandler\n")
|
|
132
|
+
(pkg / "user.py").write_text("from pkg.utils.file_io import PathHandler\n\n\n"
|
|
133
|
+
"class Mine(PathHandler):\n def go(self):\n"
|
|
134
|
+
" return self.other()\n\n def own(self):\n"
|
|
135
|
+
" return self.go()\n")
|
|
136
|
+
graph = extract(str(pkg))
|
|
137
|
+
assert "pkg.user.Mine.go" in graph.nodes
|
|
138
|
+
calls = {(e.source, e.target) for e in graph.edges if e.type == "calls"}
|
|
139
|
+
assert not any(s == "pkg.user.Mine.go" for s, _ in calls), "self.other() resolves to nothing"
|
|
140
|
+
assert ("pkg.user.Mine.own", "pkg.user.Mine.go") in calls, "the rest of the class resolves"
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# -- D4: the refusal names both shapes ----------------------------------------------------
|
|
144
|
+
|
|
145
|
+
def test_E5_the_refusal_names_the_script_layout_too(tmp_path):
|
|
146
|
+
facade = tmp_path / "facade"
|
|
147
|
+
facade.mkdir()
|
|
148
|
+
(facade / "__init__.py").write_text("from impl.core import field\n\n__all__ = ['field']\n")
|
|
149
|
+
(facade / "__init__.pyi").write_text(
|
|
150
|
+
"from typing import overload\n\nfrom impl.core import field as field\n\n"
|
|
151
|
+
"@overload\ndef field(name: str) -> str: ...\n@overload\ndef field(name: int) -> int: ...\n")
|
|
152
|
+
with pytest.raises(ValueError) as exc:
|
|
153
|
+
extract(str(facade))
|
|
154
|
+
msg = str(exc.value)
|
|
155
|
+
assert "facade layout" in msg and "sys.path" in msg and "R1-C94" in msg
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def test_the_cli_build_exits_zero_and_prints_the_note(pyc_tree, tmp_path, capsys, monkeypatch):
|
|
159
|
+
from codemap.cli import main
|
|
160
|
+
pkg, marker = pyc_tree
|
|
161
|
+
monkeypatch.chdir(pkg.parent)
|
|
162
|
+
assert main(["build", "pkg", "-o", str(tmp_path / "g.json")]) == 0
|
|
163
|
+
err = capsys.readouterr().err
|
|
164
|
+
assert "[note] 1 compiled module(s) without source were not loaded: pkg/evil.pyc" in err
|
|
165
|
+
assert not marker.exists()
|
|
166
|
+
assert sys.modules.get("pkg.evil") is None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|