codmap 0.0.36__tar.gz → 0.0.38__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 (174) hide show
  1. {codmap-0.0.36 → codmap-0.0.38}/PKG-INFO +2 -2
  2. {codmap-0.0.36 → codmap-0.0.38}/README.md +1 -1
  3. {codmap-0.0.36 → codmap-0.0.38}/codemap/diagnostics.py +24 -1
  4. {codmap-0.0.36 → codmap-0.0.38}/codemap/extract/attrflow.py +2 -2
  5. {codmap-0.0.36 → codmap-0.0.38}/codemap/extract/behavior.py +15 -10
  6. {codmap-0.0.36 → codmap-0.0.38}/codemap/extract/griffe_extractor.py +128 -15
  7. {codmap-0.0.36 → codmap-0.0.38}/codemap/extract/gsource.py +63 -6
  8. {codmap-0.0.36 → codmap-0.0.38}/codmap.egg-info/PKG-INFO +2 -2
  9. {codmap-0.0.36 → codmap-0.0.38}/codmap.egg-info/SOURCES.txt +2 -0
  10. {codmap-0.0.36 → codmap-0.0.38}/pyproject.toml +1 -1
  11. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c72_flat_inference_in_packages.py +1 -1
  12. codmap-0.0.38/tests/test_r1c94_root_builds.py +184 -0
  13. codmap-0.0.38/tests/test_r1c95_r1c96_foreign_trees.py +185 -0
  14. {codmap-0.0.36 → codmap-0.0.38}/LICENSE +0 -0
  15. {codmap-0.0.36 → codmap-0.0.38}/codemap/__init__.py +0 -0
  16. {codmap-0.0.36 → codmap-0.0.38}/codemap/apidiff.py +0 -0
  17. {codmap-0.0.36 → codmap-0.0.38}/codemap/arch.py +0 -0
  18. {codmap-0.0.36 → codmap-0.0.38}/codemap/cli.py +0 -0
  19. {codmap-0.0.36 → codmap-0.0.38}/codemap/extract/__init__.py +0 -0
  20. {codmap-0.0.36 → codmap-0.0.38}/codemap/extract/dataflow.py +0 -0
  21. {codmap-0.0.36 → codmap-0.0.38}/codemap/extract/dispatch.py +0 -0
  22. {codmap-0.0.36 → codmap-0.0.38}/codemap/extract/probe.py +0 -0
  23. {codmap-0.0.36 → codmap-0.0.38}/codemap/extract/roots.py +0 -0
  24. {codmap-0.0.36 → codmap-0.0.38}/codemap/extract/union.py +0 -0
  25. {codmap-0.0.36 → codmap-0.0.38}/codemap/freshness.py +0 -0
  26. {codmap-0.0.36 → codmap-0.0.38}/codemap/incremental.py +0 -0
  27. {codmap-0.0.36 → codmap-0.0.38}/codemap/integrations/__init__.py +0 -0
  28. {codmap-0.0.36 → codmap-0.0.38}/codemap/integrations/base.py +0 -0
  29. {codmap-0.0.36 → codmap-0.0.38}/codemap/integrations/cocoindex.py +0 -0
  30. {codmap-0.0.36 → codmap-0.0.38}/codemap/integrations/gate.py +0 -0
  31. {codmap-0.0.36 → codmap-0.0.38}/codemap/integrations/gitnexus.py +0 -0
  32. {codmap-0.0.36 → codmap-0.0.38}/codemap/integrations/registry.py +0 -0
  33. {codmap-0.0.36 → codmap-0.0.38}/codemap/integrations/transport.py +0 -0
  34. {codmap-0.0.36 → codmap-0.0.38}/codemap/model.py +0 -0
  35. {codmap-0.0.36 → codmap-0.0.38}/codemap/provenance.py +0 -0
  36. {codmap-0.0.36 → codmap-0.0.38}/codemap/query.py +0 -0
  37. {codmap-0.0.36 → codmap-0.0.38}/codemap/scope.py +0 -0
  38. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/__init__.py +0 -0
  39. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/_scip_pb2.py +0 -0
  40. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/api_surface.py +0 -0
  41. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/apidiff.py +0 -0
  42. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/architecture.py +0 -0
  43. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/audit.py +0 -0
  44. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/check.py +0 -0
  45. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/ctags.py +0 -0
  46. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/currency.py +0 -0
  47. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/impact.py +0 -0
  48. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/limits.py +0 -0
  49. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/livingdocs.py +0 -0
  50. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/mcp_server.py +0 -0
  51. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/mermaid.py +0 -0
  52. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/pack.py +0 -0
  53. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/rag.py +0 -0
  54. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/review.py +0 -0
  55. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/scip.py +0 -0
  56. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/semantic.py +0 -0
  57. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/server.py +0 -0
  58. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/session.py +0 -0
  59. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/subsystems.py +0 -0
  60. {codmap-0.0.36 → codmap-0.0.38}/codemap/serve/vault.py +0 -0
  61. {codmap-0.0.36 → codmap-0.0.38}/codemap/store.py +0 -0
  62. {codmap-0.0.36 → codmap-0.0.38}/codemap/tomlio.py +0 -0
  63. {codmap-0.0.36 → codmap-0.0.38}/codemap/watch.py +0 -0
  64. {codmap-0.0.36 → codmap-0.0.38}/codmap.egg-info/dependency_links.txt +0 -0
  65. {codmap-0.0.36 → codmap-0.0.38}/codmap.egg-info/entry_points.txt +0 -0
  66. {codmap-0.0.36 → codmap-0.0.38}/codmap.egg-info/requires.txt +0 -0
  67. {codmap-0.0.36 → codmap-0.0.38}/codmap.egg-info/top_level.txt +0 -0
  68. {codmap-0.0.36 → codmap-0.0.38}/setup.cfg +0 -0
  69. {codmap-0.0.36 → codmap-0.0.38}/tests/test_epistemic.py +0 -0
  70. {codmap-0.0.36 → codmap-0.0.38}/tests/test_gitnexus_router.py +0 -0
  71. {codmap-0.0.36 → codmap-0.0.38}/tests/test_impact_depth.py +0 -0
  72. {codmap-0.0.36 → codmap-0.0.38}/tests/test_integrations.py +0 -0
  73. {codmap-0.0.36 → codmap-0.0.38}/tests/test_issue3_serve_freshness.py +0 -0
  74. {codmap-0.0.36 → codmap-0.0.38}/tests/test_livingdocs.py +0 -0
  75. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m0_api_surface.py +0 -0
  76. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m11_argcontract.py +0 -0
  77. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m12_dataflow.py +0 -0
  78. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m15_review.py +0 -0
  79. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m16_architecture.py +0 -0
  80. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m17_mcp.py +0 -0
  81. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m18_freshness.py +0 -0
  82. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m1_5_semantics.py +0 -0
  83. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m1_query.py +0 -0
  84. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m2_views.py +0 -0
  85. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m32_watch.py +0 -0
  86. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m3_serve.py +0 -0
  87. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m4_behavior.py +0 -0
  88. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m5_deep.py +0 -0
  89. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m6_repo_scope.py +0 -0
  90. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m7_dispatch.py +0 -0
  91. {codmap-0.0.36 → codmap-0.0.38}/tests/test_m9_family.py +0 -0
  92. {codmap-0.0.36 → codmap-0.0.38}/tests/test_pack_honesty.py +0 -0
  93. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c13_callgraph_accuracy.py +0 -0
  94. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c13_grep_vs_graph.py +0 -0
  95. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c16_semantic.py +0 -0
  96. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c20_attribute_edges.py +0 -0
  97. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c21_flat_layout.py +0 -0
  98. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c22_source_visible_refs.py +0 -0
  99. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c23_hard_python.py +0 -0
  100. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c24_test_mapping.py +0 -0
  101. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c25_provenance.py +0 -0
  102. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c26_deep_union.py +0 -0
  103. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c27_config_honesty.py +0 -0
  104. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c28_limit_envelope.py +0 -0
  105. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c29_lazy_imports.py +0 -0
  106. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c2_ctags.py +0 -0
  107. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c30_local_import_calls.py +0 -0
  108. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c30f1_reexport_calls.py +0 -0
  109. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c30f2_check_scope.py +0 -0
  110. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c31_path_origin.py +0 -0
  111. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c32_report_json.py +0 -0
  112. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c33_query_signature.py +0 -0
  113. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c34_signature_kinds.py +0 -0
  114. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c35_contract_location.py +0 -0
  115. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c36_target_resolution.py +0 -0
  116. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c37_rule_mutation.py +0 -0
  117. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c38_tool_drift.py +0 -0
  118. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c39_edge_resolution.py +0 -0
  119. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c3_arch_contract.py +0 -0
  120. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c3_dogfood.py +0 -0
  121. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c40_flow_reach.py +0 -0
  122. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c41_scope_membership.py +0 -0
  123. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c42_deep_tier_stability.py +0 -0
  124. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c43_incremental_splice.py +0 -0
  125. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c44_absent_answers.py +0 -0
  126. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c45_repeat_union.py +0 -0
  127. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c46_shadowed_definitions.py +0 -0
  128. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c47_incremental_resample.py +0 -0
  129. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c48_type_checking_imports.py +0 -0
  130. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c49_type_only_cycles.py +0 -0
  131. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c4_complexity.py +0 -0
  132. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c50_flow_entry_points.py +0 -0
  133. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c53_narrowing_declared.py +0 -0
  134. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c54_deterministic_rendering.py +0 -0
  135. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c55_override_grade.py +0 -0
  136. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c56_stub_files.py +0 -0
  137. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c57_facade_package.py +0 -0
  138. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c58_cycle_tangles.py +0 -0
  139. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c59_completeness_drop.py +0 -0
  140. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c5_apidiff.py +0 -0
  141. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c60_nested_definitions.py +0 -0
  142. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c62_phantom_rules.py +0 -0
  143. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c63_answer_format.py +0 -0
  144. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c64_dependency_probe.py +0 -0
  145. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c66_pack_direction.py +0 -0
  146. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c68_dotted_imports.py +0 -0
  147. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c69_contract_validation.py +0 -0
  148. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c6_pack.py +0 -0
  149. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c70_check_graph_currency.py +0 -0
  150. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c71_attribute_chain_calls.py +0 -0
  151. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c73_cli_version.py +0 -0
  152. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c74_call_site_conservation.py +0 -0
  153. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c75_reexported_class_calls.py +0 -0
  154. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c76_contract_table_typo.py +0 -0
  155. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c77_gate_probe_battery.py +0 -0
  156. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c78_forbidden_chains.py +0 -0
  157. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c7_edge_vocab.py +0 -0
  158. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c80_tests_through_helpers.py +0 -0
  159. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c81_protocol_dispatch.py +0 -0
  160. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c82_review_changed_lines.py +0 -0
  161. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c83_foreign_graph_paths.py +0 -0
  162. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c84_missing_roots.py +0 -0
  163. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c85_mcp_graph_currency.py +0 -0
  164. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c86_incremental_repo_scope.py +0 -0
  165. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c87_review_path_base.py +0 -0
  166. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c89_review_docs.py +0 -0
  167. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c8_deadcode.py +0 -0
  168. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c90_currency_without_recipe.py +0 -0
  169. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c91_route_vocabulary.py +0 -0
  170. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c92_sidecar_pair.py +0 -0
  171. {codmap-0.0.36 → codmap-0.0.38}/tests/test_r1c9_incremental.py +0 -0
  172. {codmap-0.0.36 → codmap-0.0.38}/tests/test_scip_export.py +0 -0
  173. {codmap-0.0.36 → codmap-0.0.38}/tests/test_scope.py +0 -0
  174. {codmap-0.0.36 → codmap-0.0.38}/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.38
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, **1300 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, **1300 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
 
@@ -50,7 +50,7 @@ from codemap.extract.behavior import (
50
50
  _node_id,
51
51
  _own_nodes,
52
52
  )
53
- from codemap.extract.gsource import flat_inference_applies, module_file, module_imports
53
+ from codemap.extract.gsource import flat_known_modules, module_file, module_imports
54
54
  from codemap.model import Edge
55
55
 
56
56
 
@@ -67,7 +67,7 @@ def add_attrflow(graph, griffe_root, target_pkg: str, *, deep: bool = False,
67
67
  """
68
68
  modules = _index_modules(griffe_root)
69
69
  # R1-C21 sibling lookup, gated like behavior's (R1-C72).
70
- known_modules = set(modules) if flat_inference_applies(graph, target_pkg) else frozenset()
70
+ known_modules = flat_known_modules(graph, target_pkg, modules) # R1-C94 D3: + root anchor
71
71
  project = _jedi_project(search_path) if deep else None
72
72
  pkg = target_pkg + "."
73
73
  # (func_id, attr_id, access, resolution) — dedup collapses repeated sites.
@@ -27,8 +27,10 @@ import ast
27
27
  import math
28
28
  from pathlib import Path
29
29
 
30
- from codemap.extract.gsource import (NESTED_IMPORT_HINT, flat_inference_applies, module_file,
31
- module_imports, qualify_target)
30
+ import griffe
31
+
32
+ from codemap.extract.gsource import (NESTED_IMPORT_HINT, flat_known_modules, flat_resolve,
33
+ module_file, module_imports, qualify_target)
32
34
  from codemap.model import Edge
33
35
 
34
36
  _BUILTINS = set(vars(__import__("builtins")))
@@ -53,7 +55,7 @@ def add_behavior(graph, griffe_root, target_pkg: str, *, deep: bool = False,
53
55
  modules = _index_modules(griffe_root)
54
56
  # R1-C21 flat-layout sibling lookup — empty, so it never fires, in a core that imports
55
57
  # itself by name (R1-C72): there `import warnings` is the standard library.
56
- known_modules = set(modules) if flat_inference_applies(graph, target_pkg) else frozenset()
58
+ known_modules = flat_known_modules(graph, target_pkg, modules) # R1-C94 D3: + root anchor
57
59
  project = _jedi_project(search_path) if deep else None
58
60
  # R1-C30-f1: a call to a re-exported name points at a name that is not a definition.
59
61
  # The structural pass already recorded where each re-export really leads.
@@ -287,12 +289,7 @@ def _flat_qualify(full_name: str, modpath: str, known_modules) -> str | None:
287
289
  Same guard as the import-edge rule: only a name that is not already package-internal,
288
290
  and only when its head names a module sitting **beside** the caller.
289
291
  """
290
- if "." not in modpath:
291
- return None
292
- parent = modpath.rsplit(".", 1)[0]
293
- head = full_name.split(".", 1)[0]
294
- candidate = f"{parent}.{head}"
295
- return f"{parent}.{full_name}" if candidate in known_modules else None
292
+ return flat_resolve(full_name, modpath, known_modules) # R1-C94: sibling, then root
296
293
 
297
294
 
298
295
  def _resolve_jedi(call, script, target_pkg, *, modpath="", known_modules=frozenset()):
@@ -360,7 +357,15 @@ def _class_members(mod, class_stack, modules) -> dict:
360
357
  bmod = modules.get(".".join(modparts))
361
358
  if bmod and cname in bmod.members:
362
359
  bclass = bmod.members[cname]
363
- for name in bclass.members:
360
+ try:
361
+ inherited = list(bclass.members)
362
+ except (griffe.AliasResolutionError, griffe.CyclicAliasError):
363
+ # R1-C95 / design D3: the base is the package's re-export of a class
364
+ # from a package nobody loaded. Its members are unknown, so
365
+ # `self.<inherited>()` stays unresolved, as for a base imported straight
366
+ # from that package; the build goes on.
367
+ continue
368
+ for name in inherited:
364
369
  owners.setdefault(name, bclass.canonical_path) # own already set → keep
365
370
  return owners
366
371
 
@@ -18,6 +18,7 @@ Emits (M0 + M1 + M1.5):
18
18
  from __future__ import annotations
19
19
 
20
20
  import ast
21
+ import keyword
21
22
  import multiprocessing
22
23
  import os
23
24
  import sys
@@ -31,8 +32,8 @@ from codemap.extract.behavior import add_behavior
31
32
  from codemap.extract.dataflow import add_dataflow
32
33
  from codemap.extract.dispatch import (add_dispatch, add_family_links, add_protocol_dispatch,
33
34
  add_structural_implements)
34
- from codemap.extract.gsource import (DOTTED_IMPORT_HINT, NESTED_IMPORT_HINT, module_file,
35
- module_identity)
35
+ from codemap.extract.gsource import (DOTTED_IMPORT_HINT, NESTED_IMPORT_HINT, KnownModules,
36
+ deepest_module, flat_resolve, module_file, module_identity)
36
37
  from codemap.extract.union import merge_samples
37
38
  from codemap.provenance import build_provenance
38
39
  from codemap.model import Edge, Graph, Node, check_routes
@@ -105,12 +106,16 @@ def _load_with_siblings(module_name: str, search_path: Path):
105
106
  Returns ``(root, siblings)``; ``siblings`` is what had to be pulled in, and it is
106
107
  recorded in the input report so a reader can see the load was not self-contained.
107
108
  """
109
+ # R1-C96: `allow_inspection=False` on every load. griffe's default imports a module it
110
+ # cannot read from source (`.so`, `.pyd`, a sourceless `.pyc`), which runs the target's
111
+ # code; codemap promises it never imports the target. griffe now skips such a module
112
+ # (LoadingError, caught per submodule) and `_input_report` lists it as `compiled`.
108
113
  collection = griffe.ModulesCollection()
109
114
  siblings: list[str] = []
110
115
  for _ in range(_MAX_SIBLING_LOADS + 1):
111
116
  try:
112
117
  return griffe.load(module_name, search_paths=[str(search_path)],
113
- try_relative_path=False,
118
+ try_relative_path=False, allow_inspection=False,
114
119
  modules_collection=collection), siblings
115
120
  except griffe.AliasResolutionError as exc:
116
121
  top = exc.alias.target_path.split(".")[0]
@@ -119,13 +124,15 @@ def _load_with_siblings(module_name: str, search_path: Path):
119
124
  if not _package_on_path(top, search_path):
120
125
  raise ValueError(
121
126
  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."
127
+ f"`{top}` is not beside it in {search_path}. Either this is the "
128
+ f"facade layout (a public package re-exporting a private one): build "
129
+ f"from a tree that holds both, or point codemap at the implementation "
130
+ f"package instead. Or the package imports `{top}` through sys.path "
131
+ f"(a script layout, where `{top}` sits somewhere inside the tree): "
132
+ f"codemap does not build that layout yet (R1-C94)."
126
133
  ) from exc
127
134
  griffe.load(top, search_paths=[str(search_path)], try_relative_path=False,
128
- modules_collection=collection)
135
+ allow_inspection=False, modules_collection=collection)
129
136
  siblings.append(top)
130
137
  raise ValueError(
131
138
  f"`{module_name}` still had unresolved re-exports after loading "
@@ -140,6 +147,71 @@ def _package_on_path(name: str, search_path: Path) -> bool:
140
147
  or (search_path / f"{name}.py").is_file() or (search_path / f"{name}.pyi").is_file()
141
148
 
142
149
 
150
+ def _importable_name(name: str) -> bool:
151
+ return name.isidentifier() and not keyword.iskeyword(name)
152
+
153
+
154
+ def _visit_source(name: str, path: Path, parent, root):
155
+ """Read one source file into a griffe module under ``parent``; None if it cannot be read
156
+ (it then keeps its ``skipped`` entry with the reason ``_skip_reason`` finds)."""
157
+ try:
158
+ code = path.read_text(encoding="utf-8")
159
+ return griffe.visit(name, path, code, parent=parent,
160
+ lines_collection=root.lines_collection,
161
+ modules_collection=root.modules_collection)
162
+ except (OSError, UnicodeDecodeError, SyntaxError, ValueError):
163
+ return None
164
+
165
+
166
+ def _load_namespace_subdirs(root, pkg_dir: Path) -> None:
167
+ """Load the namespace subpackages griffe leaves out (R1-C94 / design D1).
168
+
169
+ griffe does not load a directory without ``__init__.py`` below a regular package: its
170
+ author treats that as a user error or a folder of scripts (comment in griffe's
171
+ ``_load_submodule``). Python 3 imports it as a namespace subpackage (PEP 420), and
172
+ research code is laid out that way all the time; codemap used to drop every module in
173
+ it, with an ``unread`` entry. Here such a directory becomes a namespace module and each
174
+ importable ``.py`` in it is read with ``griffe.visit`` — static, public API, no import.
175
+ Names Python cannot import (``my-dir``, ``a.b.py``) stay out, as they do for Python.
176
+ """
177
+ seen: set[str] = set()
178
+
179
+ def walk(module, directory: Path) -> None:
180
+ real = os.path.realpath(directory)
181
+ if real in seen:
182
+ return
183
+ seen.add(real)
184
+ for child in sorted(directory.iterdir()):
185
+ name = child.name
186
+ if child.is_dir():
187
+ if name == "__pycache__" or name.startswith(".") or not _importable_name(name):
188
+ continue
189
+ member = module.members.get(name)
190
+ if member is None:
191
+ if not any(child.rglob("*.py")):
192
+ continue
193
+ init = child / "__init__.py"
194
+ sub = (_visit_source(name, init, module, root) if init.is_file()
195
+ else griffe.Module(name, filepath=[child], parent=module,
196
+ lines_collection=root.lines_collection,
197
+ modules_collection=root.modules_collection))
198
+ if sub is None:
199
+ continue
200
+ module.set_member(name, sub)
201
+ walk(sub, child)
202
+ elif not member.is_alias and member.is_module:
203
+ walk(member, child)
204
+ elif child.suffix == ".py" and child.stem != "__init__":
205
+ stem = child.stem
206
+ if not _importable_name(stem) or stem in module.members:
207
+ continue
208
+ sub = _visit_source(stem, child, module, root)
209
+ if sub is not None:
210
+ module.set_member(stem, sub)
211
+
212
+ walk(root, pkg_dir)
213
+
214
+
143
215
  def build_structural(package_path: str | Path):
144
216
  """The cheap, deterministic base: griffe load + definition nodes + structural
145
217
  edges (contains / imports / inherits / decorated_by / export). No behavioral
@@ -165,6 +237,9 @@ def build_structural(package_path: str | Path):
165
237
  # answer here is invisible downstream — it is well-formed, complete and about the
166
238
  # wrong tree — so it fails loudly instead.
167
239
  _assert_is_the_target(getattr(root, "filepath", None), pkg_dir, module_name)
240
+ # R1-C94 / design D1: griffe skips a directory without __init__.py inside a regular
241
+ # package on purpose; Python imports it as a namespace subpackage. Read those too.
242
+ _load_namespace_subdirs(root, pkg_dir)
168
243
 
169
244
  graph = Graph(target=module_name)
170
245
  walk = _Walk()
@@ -292,6 +367,37 @@ def _enumerate_sources(pkg_dir: Path) -> list[Path]:
292
367
  return out
293
368
 
294
369
 
370
+ #: Module files griffe could only import, never read (R1-C96). `.pyc` in `__pycache__` is
371
+ #: a cache of a `.py` and is not a module of its own.
372
+ _COMPILED_SUFFIXES = (".so", ".pyd", ".pyc")
373
+
374
+
375
+ def _compiled_without_source(pkg_dir: Path, root: Path) -> list[str]:
376
+ """Compiled module files inside the package with no ``.py`` of the same module beside
377
+ them (R1-C96 / design D2). codemap never imports the target, so each is a module the
378
+ graph does not contain. A compiled copy beside its source is not listed: the module is
379
+ built from the source.
380
+ """
381
+ out = []
382
+ seen: set[str] = set()
383
+ for dirpath, dirnames, filenames in os.walk(pkg_dir, followlinks=True):
384
+ real = os.path.realpath(dirpath)
385
+ if real in seen:
386
+ dirnames[:] = []
387
+ continue
388
+ seen.add(real)
389
+ dirnames[:] = sorted(d for d in dirnames if d != "__pycache__")
390
+ names = set(filenames)
391
+ for n in sorted(filenames):
392
+ if not n.endswith(_COMPILED_SUFFIXES):
393
+ continue
394
+ stem = n.split(".", 1)[0] # md.cp38-win32.pyd -> md
395
+ if f"{stem}.py" in names or f"{stem}.pyi" in names:
396
+ continue
397
+ out.append(_rel(Path(dirpath) / n, root))
398
+ return out
399
+
400
+
295
401
  def _skip_reason(path: Path) -> str:
296
402
  """Why this file produced no module — asked only of files that produced none."""
297
403
  try:
@@ -322,6 +428,9 @@ def _input_report(graph, pkg_dir: Path, root: Path, walk) -> dict:
322
428
  report: dict = {"python_files": len(py)}
323
429
  if skipped:
324
430
  report["skipped"] = skipped
431
+ compiled = _compiled_without_source(pkg_dir, root)
432
+ if compiled:
433
+ report["compiled"] = compiled
325
434
  if walk.aliased:
326
435
  report["aliased_modules"] = [
327
436
  {"id": mid, "same_as": owner} for mid, owner in sorted(walk.aliased)
@@ -595,7 +704,9 @@ def _resolve_edges(graph, target_pkg, aliases, imports) -> None:
595
704
  (n.id for n in graph.nodes.values() if n.kind == "module"), key=len, reverse=True
596
705
  )
597
706
 
598
- known_modules = set(module_ids)
707
+ root_node = graph.nodes.get(target_pkg)
708
+ known_modules = KnownModules(module_ids, target_pkg if root_node is not None
709
+ and root_node.file is None else None)
599
710
  # R1-C72 (design ``flat_inference_in_packages.md`` D1, revised): the flat inference is for
600
711
  # a directory that is itself on sys.path. The evidence is a bare import that can only be a
601
712
  # sibling — it names a module beside the importer (not the importer itself) and is no
@@ -603,7 +714,6 @@ def _resolve_edges(graph, target_pkg, aliases, imports) -> None:
603
714
  # rewritten; without it, `import warnings` beside `_pytest/warnings.py` is the standard
604
715
  # library and nothing is. A namespace root needs no evidence. Decided from the collected
605
716
  # imports before anything is emitted, so edge order is kept.
606
- root_node = graph.nodes.get(target_pkg)
607
717
  flat_ok = (root_node is not None and root_node.file is None) or any(
608
718
  (sib := _flat_sibling(src, t, known_modules)) is not None and sib != src
609
719
  and t.split(".", 1)[0] not in sys.stdlib_module_names
@@ -687,11 +797,14 @@ def _flat_sibling(src_module: str, target_path: str, known_modules: set[str]) ->
687
797
  **beside the importer**. Measured on two real packages (codemap, bquant): fires zero
688
798
  times, so a correctly-laid-out package cannot be disturbed by it.
689
799
  """
690
- if "." not in src_module:
691
- return None # a top-level module has no package for siblings to live in
692
- parent = src_module.rsplit(".", 1)[0]
693
- candidate = f"{parent}.{target_path.split('.', 1)[0]}"
694
- return candidate if candidate in known_modules else None
800
+ # R1-C94: the gate is the head (D2: beside the importer; D3: on a namespace root, directly
801
+ # under the root); the answer is the deepest module the path names.
802
+ # `from engine.dataset import get` depends on `engine.dataset`, not on `engine`.
803
+ full = flat_resolve(target_path, src_module, known_modules)
804
+ if full is None:
805
+ return None
806
+ anchor_len = len(full) - len(target_path) # "<parent-or-root>."
807
+ return deepest_module(full, full[:anchor_len] + target_path.split(".", 1)[0], known_modules)
695
808
 
696
809
 
697
810
  def _containing_module(symbol_path: str, module_ids: list[str]) -> str | None:
@@ -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:
@@ -92,6 +97,58 @@ def module_imports(mod, modpath: str, known_modules) -> dict[str, str]:
92
97
  for name, target in imports.items()}
93
98
 
94
99
 
100
+ class KnownModules(frozenset):
101
+ """The module ids the flat inference may resolve to, plus the root anchor (R1-C94 D3).
102
+
103
+ ``root_anchor`` is the target package id when the target is a namespace root (no
104
+ ``__init__.py``: the repository-root case, whose directory is on ``sys.path``), else
105
+ None. Then an import whose head names a module directly under the root resolves there
106
+ when no sibling of the importer matches first.
107
+ """
108
+
109
+ root_anchor: str | None = None
110
+
111
+ def __new__(cls, ids=(), root_anchor: str | None = None):
112
+ self = super().__new__(cls, ids)
113
+ self.root_anchor = root_anchor
114
+ return self
115
+
116
+
117
+ def flat_known_modules(graph, core_pkg: str, modules) -> KnownModules:
118
+ """``known_modules`` for the import map: empty unless the flat inference applies."""
119
+ if not flat_inference_applies(graph, core_pkg):
120
+ return KnownModules()
121
+ root = graph.nodes.get(core_pkg)
122
+ return KnownModules(modules, core_pkg if root is not None and root.file is None else None)
123
+
124
+
125
+ def deepest_module(path: str, stop: str, known_modules) -> str:
126
+ """The longest prefix of ``path`` that is a known module, not shorter than ``stop``."""
127
+ while path != stop and path not in known_modules:
128
+ path = path.rsplit(".", 1)[0]
129
+ return path
130
+
131
+
132
+ def flat_resolve(target: str, modpath: str, known_modules) -> str | None:
133
+ """The module-qualified form of a flat-layout import target, or None (R1-C21, R1-C94).
134
+
135
+ Sibling first (D2: the head names a module beside the importer), then — on a namespace
136
+ root only — the root (D3: the head names a module directly under the target). The
137
+ nearer one wins, as ``sys.path[0]`` (the script's own directory) wins at runtime.
138
+ Returns the qualified *path* (``<parent>.<target>``), not truncated to a module.
139
+ """
140
+ if "." not in modpath:
141
+ return None
142
+ head = target.split(".", 1)[0]
143
+ parent = modpath.rsplit(".", 1)[0]
144
+ if f"{parent}.{head}" in known_modules:
145
+ return f"{parent}.{target}"
146
+ anchor = getattr(known_modules, "root_anchor", None)
147
+ if anchor and parent != anchor and f"{anchor}.{head}" in known_modules:
148
+ return f"{anchor}.{target}"
149
+ return None
150
+
151
+
95
152
  def qualify_target(target: str, modpath: str, known_modules) -> str:
96
153
  """One import target, package-qualified if it names a flat-layout sibling (R1-C21).
97
154
 
@@ -101,10 +158,10 @@ def qualify_target(target: str, modpath: str, known_modules) -> str:
101
158
  """
102
159
  if "." not in modpath:
103
160
  return target
104
- parent, pkg = modpath.rsplit(".", 1)[0], modpath.split(".", 1)[0] + "."
105
- if not target.startswith(pkg) and f"{parent}.{target.split('.', 1)[0]}" in known_modules:
106
- return f"{parent}.{target}"
107
- return target
161
+ pkg = modpath.split(".", 1)[0] + "."
162
+ if target.startswith(pkg):
163
+ return target
164
+ return flat_resolve(target, modpath, known_modules) or target
108
165
 
109
166
 
110
167
  def flat_inference_applies(graph, core_pkg: str) -> bool:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.36
3
+ Version: 0.0.38
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, **1300 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,8 @@ 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_r1c94_root_builds.py
168
+ tests/test_r1c95_r1c96_foreign_trees.py
167
169
  tests/test_r1c9_incremental.py
168
170
  tests/test_scip_export.py
169
171
  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.38"
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
@@ -90,7 +90,7 @@ def test_mutation_without_the_stdlib_exclusion_the_twin_is_rewritten_again(tmp_p
90
90
  def test_mutation_without_the_import_map_gate_the_call_is_internal_again(tmp_path):
91
91
  """D2: with the import map ungated, `logging.getLogger()` is rewritten into the package
92
92
  even though no flat edge was emitted, and it stops counting as external."""
93
- with mock.patch("codemap.extract.behavior.flat_inference_applies", lambda g, p: True):
93
+ with mock.patch("codemap.extract.gsource.flat_inference_applies", lambda g, p: True):
94
94
  g = _tree(tmp_path / "m", {"logging": TWIN, "a": A, "b": "from tpkg import a\n"})
95
95
  assert g.nodes["tpkg.a.g"].extras["calls"].get("external", 0) == 0
96
96
  assert [e.target for e in g.edges if e.type == "calls" and e.source == "tpkg.a.g"] == \