codmap 0.0.36__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.
Files changed (173) hide show
  1. {codmap-0.0.36 → codmap-0.0.37}/PKG-INFO +2 -2
  2. {codmap-0.0.36 → codmap-0.0.37}/README.md +1 -1
  3. {codmap-0.0.36 → codmap-0.0.37}/codemap/diagnostics.py +24 -1
  4. {codmap-0.0.36 → codmap-0.0.37}/codemap/extract/behavior.py +11 -1
  5. {codmap-0.0.36 → codmap-0.0.37}/codemap/extract/griffe_extractor.py +46 -6
  6. {codmap-0.0.36 → codmap-0.0.37}/codemap/extract/gsource.py +7 -2
  7. {codmap-0.0.36 → codmap-0.0.37}/codmap.egg-info/PKG-INFO +2 -2
  8. {codmap-0.0.36 → codmap-0.0.37}/codmap.egg-info/SOURCES.txt +1 -0
  9. {codmap-0.0.36 → codmap-0.0.37}/pyproject.toml +1 -1
  10. codmap-0.0.37/tests/test_r1c95_r1c96_foreign_trees.py +166 -0
  11. {codmap-0.0.36 → codmap-0.0.37}/LICENSE +0 -0
  12. {codmap-0.0.36 → codmap-0.0.37}/codemap/__init__.py +0 -0
  13. {codmap-0.0.36 → codmap-0.0.37}/codemap/apidiff.py +0 -0
  14. {codmap-0.0.36 → codmap-0.0.37}/codemap/arch.py +0 -0
  15. {codmap-0.0.36 → codmap-0.0.37}/codemap/cli.py +0 -0
  16. {codmap-0.0.36 → codmap-0.0.37}/codemap/extract/__init__.py +0 -0
  17. {codmap-0.0.36 → codmap-0.0.37}/codemap/extract/attrflow.py +0 -0
  18. {codmap-0.0.36 → codmap-0.0.37}/codemap/extract/dataflow.py +0 -0
  19. {codmap-0.0.36 → codmap-0.0.37}/codemap/extract/dispatch.py +0 -0
  20. {codmap-0.0.36 → codmap-0.0.37}/codemap/extract/probe.py +0 -0
  21. {codmap-0.0.36 → codmap-0.0.37}/codemap/extract/roots.py +0 -0
  22. {codmap-0.0.36 → codmap-0.0.37}/codemap/extract/union.py +0 -0
  23. {codmap-0.0.36 → codmap-0.0.37}/codemap/freshness.py +0 -0
  24. {codmap-0.0.36 → codmap-0.0.37}/codemap/incremental.py +0 -0
  25. {codmap-0.0.36 → codmap-0.0.37}/codemap/integrations/__init__.py +0 -0
  26. {codmap-0.0.36 → codmap-0.0.37}/codemap/integrations/base.py +0 -0
  27. {codmap-0.0.36 → codmap-0.0.37}/codemap/integrations/cocoindex.py +0 -0
  28. {codmap-0.0.36 → codmap-0.0.37}/codemap/integrations/gate.py +0 -0
  29. {codmap-0.0.36 → codmap-0.0.37}/codemap/integrations/gitnexus.py +0 -0
  30. {codmap-0.0.36 → codmap-0.0.37}/codemap/integrations/registry.py +0 -0
  31. {codmap-0.0.36 → codmap-0.0.37}/codemap/integrations/transport.py +0 -0
  32. {codmap-0.0.36 → codmap-0.0.37}/codemap/model.py +0 -0
  33. {codmap-0.0.36 → codmap-0.0.37}/codemap/provenance.py +0 -0
  34. {codmap-0.0.36 → codmap-0.0.37}/codemap/query.py +0 -0
  35. {codmap-0.0.36 → codmap-0.0.37}/codemap/scope.py +0 -0
  36. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/__init__.py +0 -0
  37. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/_scip_pb2.py +0 -0
  38. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/api_surface.py +0 -0
  39. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/apidiff.py +0 -0
  40. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/architecture.py +0 -0
  41. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/audit.py +0 -0
  42. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/check.py +0 -0
  43. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/ctags.py +0 -0
  44. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/currency.py +0 -0
  45. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/impact.py +0 -0
  46. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/limits.py +0 -0
  47. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/livingdocs.py +0 -0
  48. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/mcp_server.py +0 -0
  49. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/mermaid.py +0 -0
  50. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/pack.py +0 -0
  51. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/rag.py +0 -0
  52. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/review.py +0 -0
  53. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/scip.py +0 -0
  54. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/semantic.py +0 -0
  55. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/server.py +0 -0
  56. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/session.py +0 -0
  57. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/subsystems.py +0 -0
  58. {codmap-0.0.36 → codmap-0.0.37}/codemap/serve/vault.py +0 -0
  59. {codmap-0.0.36 → codmap-0.0.37}/codemap/store.py +0 -0
  60. {codmap-0.0.36 → codmap-0.0.37}/codemap/tomlio.py +0 -0
  61. {codmap-0.0.36 → codmap-0.0.37}/codemap/watch.py +0 -0
  62. {codmap-0.0.36 → codmap-0.0.37}/codmap.egg-info/dependency_links.txt +0 -0
  63. {codmap-0.0.36 → codmap-0.0.37}/codmap.egg-info/entry_points.txt +0 -0
  64. {codmap-0.0.36 → codmap-0.0.37}/codmap.egg-info/requires.txt +0 -0
  65. {codmap-0.0.36 → codmap-0.0.37}/codmap.egg-info/top_level.txt +0 -0
  66. {codmap-0.0.36 → codmap-0.0.37}/setup.cfg +0 -0
  67. {codmap-0.0.36 → codmap-0.0.37}/tests/test_epistemic.py +0 -0
  68. {codmap-0.0.36 → codmap-0.0.37}/tests/test_gitnexus_router.py +0 -0
  69. {codmap-0.0.36 → codmap-0.0.37}/tests/test_impact_depth.py +0 -0
  70. {codmap-0.0.36 → codmap-0.0.37}/tests/test_integrations.py +0 -0
  71. {codmap-0.0.36 → codmap-0.0.37}/tests/test_issue3_serve_freshness.py +0 -0
  72. {codmap-0.0.36 → codmap-0.0.37}/tests/test_livingdocs.py +0 -0
  73. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m0_api_surface.py +0 -0
  74. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m11_argcontract.py +0 -0
  75. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m12_dataflow.py +0 -0
  76. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m15_review.py +0 -0
  77. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m16_architecture.py +0 -0
  78. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m17_mcp.py +0 -0
  79. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m18_freshness.py +0 -0
  80. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m1_5_semantics.py +0 -0
  81. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m1_query.py +0 -0
  82. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m2_views.py +0 -0
  83. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m32_watch.py +0 -0
  84. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m3_serve.py +0 -0
  85. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m4_behavior.py +0 -0
  86. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m5_deep.py +0 -0
  87. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m6_repo_scope.py +0 -0
  88. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m7_dispatch.py +0 -0
  89. {codmap-0.0.36 → codmap-0.0.37}/tests/test_m9_family.py +0 -0
  90. {codmap-0.0.36 → codmap-0.0.37}/tests/test_pack_honesty.py +0 -0
  91. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c13_callgraph_accuracy.py +0 -0
  92. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c13_grep_vs_graph.py +0 -0
  93. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c16_semantic.py +0 -0
  94. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c20_attribute_edges.py +0 -0
  95. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c21_flat_layout.py +0 -0
  96. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c22_source_visible_refs.py +0 -0
  97. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c23_hard_python.py +0 -0
  98. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c24_test_mapping.py +0 -0
  99. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c25_provenance.py +0 -0
  100. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c26_deep_union.py +0 -0
  101. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c27_config_honesty.py +0 -0
  102. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c28_limit_envelope.py +0 -0
  103. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c29_lazy_imports.py +0 -0
  104. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c2_ctags.py +0 -0
  105. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c30_local_import_calls.py +0 -0
  106. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c30f1_reexport_calls.py +0 -0
  107. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c30f2_check_scope.py +0 -0
  108. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c31_path_origin.py +0 -0
  109. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c32_report_json.py +0 -0
  110. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c33_query_signature.py +0 -0
  111. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c34_signature_kinds.py +0 -0
  112. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c35_contract_location.py +0 -0
  113. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c36_target_resolution.py +0 -0
  114. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c37_rule_mutation.py +0 -0
  115. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c38_tool_drift.py +0 -0
  116. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c39_edge_resolution.py +0 -0
  117. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c3_arch_contract.py +0 -0
  118. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c3_dogfood.py +0 -0
  119. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c40_flow_reach.py +0 -0
  120. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c41_scope_membership.py +0 -0
  121. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c42_deep_tier_stability.py +0 -0
  122. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c43_incremental_splice.py +0 -0
  123. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c44_absent_answers.py +0 -0
  124. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c45_repeat_union.py +0 -0
  125. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c46_shadowed_definitions.py +0 -0
  126. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c47_incremental_resample.py +0 -0
  127. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c48_type_checking_imports.py +0 -0
  128. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c49_type_only_cycles.py +0 -0
  129. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c4_complexity.py +0 -0
  130. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c50_flow_entry_points.py +0 -0
  131. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c53_narrowing_declared.py +0 -0
  132. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c54_deterministic_rendering.py +0 -0
  133. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c55_override_grade.py +0 -0
  134. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c56_stub_files.py +0 -0
  135. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c57_facade_package.py +0 -0
  136. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c58_cycle_tangles.py +0 -0
  137. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c59_completeness_drop.py +0 -0
  138. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c5_apidiff.py +0 -0
  139. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c60_nested_definitions.py +0 -0
  140. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c62_phantom_rules.py +0 -0
  141. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c63_answer_format.py +0 -0
  142. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c64_dependency_probe.py +0 -0
  143. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c66_pack_direction.py +0 -0
  144. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c68_dotted_imports.py +0 -0
  145. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c69_contract_validation.py +0 -0
  146. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c6_pack.py +0 -0
  147. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c70_check_graph_currency.py +0 -0
  148. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c71_attribute_chain_calls.py +0 -0
  149. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c72_flat_inference_in_packages.py +0 -0
  150. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c73_cli_version.py +0 -0
  151. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c74_call_site_conservation.py +0 -0
  152. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c75_reexported_class_calls.py +0 -0
  153. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c76_contract_table_typo.py +0 -0
  154. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c77_gate_probe_battery.py +0 -0
  155. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c78_forbidden_chains.py +0 -0
  156. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c7_edge_vocab.py +0 -0
  157. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c80_tests_through_helpers.py +0 -0
  158. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c81_protocol_dispatch.py +0 -0
  159. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c82_review_changed_lines.py +0 -0
  160. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c83_foreign_graph_paths.py +0 -0
  161. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c84_missing_roots.py +0 -0
  162. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c85_mcp_graph_currency.py +0 -0
  163. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c86_incremental_repo_scope.py +0 -0
  164. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c87_review_path_base.py +0 -0
  165. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c89_review_docs.py +0 -0
  166. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c8_deadcode.py +0 -0
  167. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c90_currency_without_recipe.py +0 -0
  168. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c91_route_vocabulary.py +0 -0
  169. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c92_sidecar_pair.py +0 -0
  170. {codmap-0.0.36 → codmap-0.0.37}/tests/test_r1c9_incremental.py +0 -0
  171. {codmap-0.0.36 → codmap-0.0.37}/tests/test_scip_export.py +0 -0
  172. {codmap-0.0.36 → codmap-0.0.37}/tests/test_scope.py +0 -0
  173. {codmap-0.0.36 → 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.36
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
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
46
46
 
47
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1278 tests with no failures on
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
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
10
10
 
11
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1278 tests with no failures on
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 &
@@ -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
- for name in bclass.members:
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}. This is the facade "
123
- f"layout (a public package re-exporting a private one): build from "
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
- return Path(fp)
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.36
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
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
46
46
 
47
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1278 tests with no failures on
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 &
@@ -164,6 +164,7 @@ tests/test_r1c8_deadcode.py
164
164
  tests/test_r1c90_currency_without_recipe.py
165
165
  tests/test_r1c91_route_vocabulary.py
166
166
  tests/test_r1c92_sidecar_pair.py
167
+ tests/test_r1c95_r1c96_foreign_trees.py
167
168
  tests/test_r1c9_incremental.py
168
169
  tests/test_scip_export.py
169
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.36"
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
@@ -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
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes