codmap 0.0.37__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.37 → codmap-0.0.38}/PKG-INFO +2 -2
  2. {codmap-0.0.37 → codmap-0.0.38}/README.md +1 -1
  3. {codmap-0.0.37 → codmap-0.0.38}/codemap/extract/attrflow.py +2 -2
  4. {codmap-0.0.37 → codmap-0.0.38}/codemap/extract/behavior.py +4 -9
  5. {codmap-0.0.37 → codmap-0.0.38}/codemap/extract/griffe_extractor.py +82 -9
  6. {codmap-0.0.37 → codmap-0.0.38}/codemap/extract/gsource.py +56 -4
  7. {codmap-0.0.37 → codmap-0.0.38}/codmap.egg-info/PKG-INFO +2 -2
  8. {codmap-0.0.37 → codmap-0.0.38}/codmap.egg-info/SOURCES.txt +1 -0
  9. {codmap-0.0.37 → codmap-0.0.38}/pyproject.toml +1 -1
  10. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c72_flat_inference_in_packages.py +1 -1
  11. codmap-0.0.38/tests/test_r1c94_root_builds.py +184 -0
  12. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c95_r1c96_foreign_trees.py +19 -0
  13. {codmap-0.0.37 → codmap-0.0.38}/LICENSE +0 -0
  14. {codmap-0.0.37 → codmap-0.0.38}/codemap/__init__.py +0 -0
  15. {codmap-0.0.37 → codmap-0.0.38}/codemap/apidiff.py +0 -0
  16. {codmap-0.0.37 → codmap-0.0.38}/codemap/arch.py +0 -0
  17. {codmap-0.0.37 → codmap-0.0.38}/codemap/cli.py +0 -0
  18. {codmap-0.0.37 → codmap-0.0.38}/codemap/diagnostics.py +0 -0
  19. {codmap-0.0.37 → codmap-0.0.38}/codemap/extract/__init__.py +0 -0
  20. {codmap-0.0.37 → codmap-0.0.38}/codemap/extract/dataflow.py +0 -0
  21. {codmap-0.0.37 → codmap-0.0.38}/codemap/extract/dispatch.py +0 -0
  22. {codmap-0.0.37 → codmap-0.0.38}/codemap/extract/probe.py +0 -0
  23. {codmap-0.0.37 → codmap-0.0.38}/codemap/extract/roots.py +0 -0
  24. {codmap-0.0.37 → codmap-0.0.38}/codemap/extract/union.py +0 -0
  25. {codmap-0.0.37 → codmap-0.0.38}/codemap/freshness.py +0 -0
  26. {codmap-0.0.37 → codmap-0.0.38}/codemap/incremental.py +0 -0
  27. {codmap-0.0.37 → codmap-0.0.38}/codemap/integrations/__init__.py +0 -0
  28. {codmap-0.0.37 → codmap-0.0.38}/codemap/integrations/base.py +0 -0
  29. {codmap-0.0.37 → codmap-0.0.38}/codemap/integrations/cocoindex.py +0 -0
  30. {codmap-0.0.37 → codmap-0.0.38}/codemap/integrations/gate.py +0 -0
  31. {codmap-0.0.37 → codmap-0.0.38}/codemap/integrations/gitnexus.py +0 -0
  32. {codmap-0.0.37 → codmap-0.0.38}/codemap/integrations/registry.py +0 -0
  33. {codmap-0.0.37 → codmap-0.0.38}/codemap/integrations/transport.py +0 -0
  34. {codmap-0.0.37 → codmap-0.0.38}/codemap/model.py +0 -0
  35. {codmap-0.0.37 → codmap-0.0.38}/codemap/provenance.py +0 -0
  36. {codmap-0.0.37 → codmap-0.0.38}/codemap/query.py +0 -0
  37. {codmap-0.0.37 → codmap-0.0.38}/codemap/scope.py +0 -0
  38. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/__init__.py +0 -0
  39. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/_scip_pb2.py +0 -0
  40. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/api_surface.py +0 -0
  41. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/apidiff.py +0 -0
  42. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/architecture.py +0 -0
  43. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/audit.py +0 -0
  44. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/check.py +0 -0
  45. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/ctags.py +0 -0
  46. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/currency.py +0 -0
  47. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/impact.py +0 -0
  48. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/limits.py +0 -0
  49. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/livingdocs.py +0 -0
  50. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/mcp_server.py +0 -0
  51. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/mermaid.py +0 -0
  52. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/pack.py +0 -0
  53. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/rag.py +0 -0
  54. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/review.py +0 -0
  55. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/scip.py +0 -0
  56. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/semantic.py +0 -0
  57. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/server.py +0 -0
  58. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/session.py +0 -0
  59. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/subsystems.py +0 -0
  60. {codmap-0.0.37 → codmap-0.0.38}/codemap/serve/vault.py +0 -0
  61. {codmap-0.0.37 → codmap-0.0.38}/codemap/store.py +0 -0
  62. {codmap-0.0.37 → codmap-0.0.38}/codemap/tomlio.py +0 -0
  63. {codmap-0.0.37 → codmap-0.0.38}/codemap/watch.py +0 -0
  64. {codmap-0.0.37 → codmap-0.0.38}/codmap.egg-info/dependency_links.txt +0 -0
  65. {codmap-0.0.37 → codmap-0.0.38}/codmap.egg-info/entry_points.txt +0 -0
  66. {codmap-0.0.37 → codmap-0.0.38}/codmap.egg-info/requires.txt +0 -0
  67. {codmap-0.0.37 → codmap-0.0.38}/codmap.egg-info/top_level.txt +0 -0
  68. {codmap-0.0.37 → codmap-0.0.38}/setup.cfg +0 -0
  69. {codmap-0.0.37 → codmap-0.0.38}/tests/test_epistemic.py +0 -0
  70. {codmap-0.0.37 → codmap-0.0.38}/tests/test_gitnexus_router.py +0 -0
  71. {codmap-0.0.37 → codmap-0.0.38}/tests/test_impact_depth.py +0 -0
  72. {codmap-0.0.37 → codmap-0.0.38}/tests/test_integrations.py +0 -0
  73. {codmap-0.0.37 → codmap-0.0.38}/tests/test_issue3_serve_freshness.py +0 -0
  74. {codmap-0.0.37 → codmap-0.0.38}/tests/test_livingdocs.py +0 -0
  75. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m0_api_surface.py +0 -0
  76. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m11_argcontract.py +0 -0
  77. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m12_dataflow.py +0 -0
  78. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m15_review.py +0 -0
  79. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m16_architecture.py +0 -0
  80. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m17_mcp.py +0 -0
  81. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m18_freshness.py +0 -0
  82. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m1_5_semantics.py +0 -0
  83. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m1_query.py +0 -0
  84. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m2_views.py +0 -0
  85. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m32_watch.py +0 -0
  86. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m3_serve.py +0 -0
  87. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m4_behavior.py +0 -0
  88. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m5_deep.py +0 -0
  89. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m6_repo_scope.py +0 -0
  90. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m7_dispatch.py +0 -0
  91. {codmap-0.0.37 → codmap-0.0.38}/tests/test_m9_family.py +0 -0
  92. {codmap-0.0.37 → codmap-0.0.38}/tests/test_pack_honesty.py +0 -0
  93. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c13_callgraph_accuracy.py +0 -0
  94. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c13_grep_vs_graph.py +0 -0
  95. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c16_semantic.py +0 -0
  96. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c20_attribute_edges.py +0 -0
  97. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c21_flat_layout.py +0 -0
  98. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c22_source_visible_refs.py +0 -0
  99. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c23_hard_python.py +0 -0
  100. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c24_test_mapping.py +0 -0
  101. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c25_provenance.py +0 -0
  102. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c26_deep_union.py +0 -0
  103. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c27_config_honesty.py +0 -0
  104. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c28_limit_envelope.py +0 -0
  105. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c29_lazy_imports.py +0 -0
  106. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c2_ctags.py +0 -0
  107. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c30_local_import_calls.py +0 -0
  108. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c30f1_reexport_calls.py +0 -0
  109. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c30f2_check_scope.py +0 -0
  110. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c31_path_origin.py +0 -0
  111. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c32_report_json.py +0 -0
  112. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c33_query_signature.py +0 -0
  113. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c34_signature_kinds.py +0 -0
  114. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c35_contract_location.py +0 -0
  115. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c36_target_resolution.py +0 -0
  116. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c37_rule_mutation.py +0 -0
  117. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c38_tool_drift.py +0 -0
  118. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c39_edge_resolution.py +0 -0
  119. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c3_arch_contract.py +0 -0
  120. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c3_dogfood.py +0 -0
  121. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c40_flow_reach.py +0 -0
  122. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c41_scope_membership.py +0 -0
  123. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c42_deep_tier_stability.py +0 -0
  124. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c43_incremental_splice.py +0 -0
  125. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c44_absent_answers.py +0 -0
  126. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c45_repeat_union.py +0 -0
  127. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c46_shadowed_definitions.py +0 -0
  128. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c47_incremental_resample.py +0 -0
  129. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c48_type_checking_imports.py +0 -0
  130. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c49_type_only_cycles.py +0 -0
  131. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c4_complexity.py +0 -0
  132. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c50_flow_entry_points.py +0 -0
  133. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c53_narrowing_declared.py +0 -0
  134. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c54_deterministic_rendering.py +0 -0
  135. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c55_override_grade.py +0 -0
  136. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c56_stub_files.py +0 -0
  137. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c57_facade_package.py +0 -0
  138. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c58_cycle_tangles.py +0 -0
  139. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c59_completeness_drop.py +0 -0
  140. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c5_apidiff.py +0 -0
  141. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c60_nested_definitions.py +0 -0
  142. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c62_phantom_rules.py +0 -0
  143. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c63_answer_format.py +0 -0
  144. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c64_dependency_probe.py +0 -0
  145. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c66_pack_direction.py +0 -0
  146. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c68_dotted_imports.py +0 -0
  147. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c69_contract_validation.py +0 -0
  148. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c6_pack.py +0 -0
  149. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c70_check_graph_currency.py +0 -0
  150. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c71_attribute_chain_calls.py +0 -0
  151. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c73_cli_version.py +0 -0
  152. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c74_call_site_conservation.py +0 -0
  153. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c75_reexported_class_calls.py +0 -0
  154. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c76_contract_table_typo.py +0 -0
  155. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c77_gate_probe_battery.py +0 -0
  156. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c78_forbidden_chains.py +0 -0
  157. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c7_edge_vocab.py +0 -0
  158. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c80_tests_through_helpers.py +0 -0
  159. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c81_protocol_dispatch.py +0 -0
  160. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c82_review_changed_lines.py +0 -0
  161. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c83_foreign_graph_paths.py +0 -0
  162. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c84_missing_roots.py +0 -0
  163. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c85_mcp_graph_currency.py +0 -0
  164. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c86_incremental_repo_scope.py +0 -0
  165. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c87_review_path_base.py +0 -0
  166. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c89_review_docs.py +0 -0
  167. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c8_deadcode.py +0 -0
  168. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c90_currency_without_recipe.py +0 -0
  169. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c91_route_vocabulary.py +0 -0
  170. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c92_sidecar_pair.py +0 -0
  171. {codmap-0.0.37 → codmap-0.0.38}/tests/test_r1c9_incremental.py +0 -0
  172. {codmap-0.0.37 → codmap-0.0.38}/tests/test_scip_export.py +0 -0
  173. {codmap-0.0.37 → codmap-0.0.38}/tests/test_scope.py +0 -0
  174. {codmap-0.0.37 → 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.37
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, **1287 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, **1287 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 &
@@ -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.
@@ -29,8 +29,8 @@ from pathlib import Path
29
29
 
30
30
  import griffe
31
31
 
32
- from codemap.extract.gsource import (NESTED_IMPORT_HINT, flat_inference_applies, module_file,
33
- module_imports, qualify_target)
32
+ from codemap.extract.gsource import (NESTED_IMPORT_HINT, flat_known_modules, flat_resolve,
33
+ module_file, module_imports, qualify_target)
34
34
  from codemap.model import Edge
35
35
 
36
36
  _BUILTINS = set(vars(__import__("builtins")))
@@ -55,7 +55,7 @@ def add_behavior(graph, griffe_root, target_pkg: str, *, deep: bool = False,
55
55
  modules = _index_modules(griffe_root)
56
56
  # R1-C21 flat-layout sibling lookup — empty, so it never fires, in a core that imports
57
57
  # itself by name (R1-C72): there `import warnings` is the standard library.
58
- 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
59
59
  project = _jedi_project(search_path) if deep else None
60
60
  # R1-C30-f1: a call to a re-exported name points at a name that is not a definition.
61
61
  # The structural pass already recorded where each re-export really leads.
@@ -289,12 +289,7 @@ def _flat_qualify(full_name: str, modpath: str, known_modules) -> str | None:
289
289
  Same guard as the import-edge rule: only a name that is not already package-internal,
290
290
  and only when its head names a module sitting **beside** the caller.
291
291
  """
292
- if "." not in modpath:
293
- return None
294
- parent = modpath.rsplit(".", 1)[0]
295
- head = full_name.split(".", 1)[0]
296
- candidate = f"{parent}.{head}"
297
- 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
298
293
 
299
294
 
300
295
  def _resolve_jedi(call, script, target_pkg, *, modpath="", known_modules=frozenset()):
@@ -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
@@ -146,6 +147,71 @@ def _package_on_path(name: str, search_path: Path) -> bool:
146
147
  or (search_path / f"{name}.py").is_file() or (search_path / f"{name}.pyi").is_file()
147
148
 
148
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
+
149
215
  def build_structural(package_path: str | Path):
150
216
  """The cheap, deterministic base: griffe load + definition nodes + structural
151
217
  edges (contains / imports / inherits / decorated_by / export). No behavioral
@@ -171,6 +237,9 @@ def build_structural(package_path: str | Path):
171
237
  # answer here is invisible downstream — it is well-formed, complete and about the
172
238
  # wrong tree — so it fails loudly instead.
173
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)
174
243
 
175
244
  graph = Graph(target=module_name)
176
245
  walk = _Walk()
@@ -635,7 +704,9 @@ def _resolve_edges(graph, target_pkg, aliases, imports) -> None:
635
704
  (n.id for n in graph.nodes.values() if n.kind == "module"), key=len, reverse=True
636
705
  )
637
706
 
638
- 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)
639
710
  # R1-C72 (design ``flat_inference_in_packages.md`` D1, revised): the flat inference is for
640
711
  # a directory that is itself on sys.path. The evidence is a bare import that can only be a
641
712
  # sibling — it names a module beside the importer (not the importer itself) and is no
@@ -643,7 +714,6 @@ def _resolve_edges(graph, target_pkg, aliases, imports) -> None:
643
714
  # rewritten; without it, `import warnings` beside `_pytest/warnings.py` is the standard
644
715
  # library and nothing is. A namespace root needs no evidence. Decided from the collected
645
716
  # imports before anything is emitted, so edge order is kept.
646
- root_node = graph.nodes.get(target_pkg)
647
717
  flat_ok = (root_node is not None and root_node.file is None) or any(
648
718
  (sib := _flat_sibling(src, t, known_modules)) is not None and sib != src
649
719
  and t.split(".", 1)[0] not in sys.stdlib_module_names
@@ -727,11 +797,14 @@ def _flat_sibling(src_module: str, target_path: str, known_modules: set[str]) ->
727
797
  **beside the importer**. Measured on two real packages (codemap, bquant): fires zero
728
798
  times, so a correctly-laid-out package cannot be disturbed by it.
729
799
  """
730
- if "." not in src_module:
731
- return None # a top-level module has no package for siblings to live in
732
- parent = src_module.rsplit(".", 1)[0]
733
- candidate = f"{parent}.{target_path.split('.', 1)[0]}"
734
- 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)
735
808
 
736
809
 
737
810
  def _containing_module(symbol_path: str, module_ids: list[str]) -> str | None:
@@ -97,6 +97,58 @@ def module_imports(mod, modpath: str, known_modules) -> dict[str, str]:
97
97
  for name, target in imports.items()}
98
98
 
99
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
+
100
152
  def qualify_target(target: str, modpath: str, known_modules) -> str:
101
153
  """One import target, package-qualified if it names a flat-layout sibling (R1-C21).
102
154
 
@@ -106,10 +158,10 @@ def qualify_target(target: str, modpath: str, known_modules) -> str:
106
158
  """
107
159
  if "." not in modpath:
108
160
  return target
109
- parent, pkg = modpath.rsplit(".", 1)[0], modpath.split(".", 1)[0] + "."
110
- if not target.startswith(pkg) and f"{parent}.{target.split('.', 1)[0]}" in known_modules:
111
- return f"{parent}.{target}"
112
- 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
113
165
 
114
166
 
115
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.37
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, **1287 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,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_r1c94_root_builds.py
167
168
  tests/test_r1c95_r1c96_foreign_trees.py
168
169
  tests/test_r1c9_incremental.py
169
170
  tests/test_scip_export.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.37"
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"] == \
@@ -0,0 +1,184 @@
1
+ """R1-C94 — namespace subdirectories inside a package are read; flat imports name the module they import.
2
+
3
+ Design `docs/design/root_builds.md` (pre-registered dedb88a).
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ import py_compile
10
+ from pathlib import Path
11
+
12
+ import pytest
13
+
14
+ from codemap.cli import main
15
+ from codemap.extract.griffe_extractor import extract
16
+
17
+
18
+ def _write(root: Path, files: dict) -> None:
19
+ for rel, body in files.items():
20
+ p = root / rel
21
+ p.parent.mkdir(parents=True, exist_ok=True)
22
+ p.write_text(body)
23
+
24
+
25
+ def _edges(graph, kind):
26
+ return {(e.source, e.target) for e in graph.edges if e.type == kind}
27
+
28
+
29
+ NS = {
30
+ "pkg/__init__.py": "",
31
+ "pkg/layers/act.py": "def act():\n return 1\n",
32
+ "pkg/layers/more.py": "from .act import act\n\n\ndef twice():\n return act() + act()\n",
33
+ "pkg/layers/deep/__init__.py": "",
34
+ "pkg/layers/deep/leaf.py": "def leaf():\n return 2\n",
35
+ "pkg/net.py": ("from pkg.layers.act import act\nfrom pkg.layers.deep.leaf import leaf\n\n\n"
36
+ "def run():\n return act() + leaf()\n"),
37
+ }
38
+
39
+
40
+ # -- D1 -------------------------------------------------------------------------------------
41
+
42
+ def test_E1_a_namespace_subdirectory_is_read(tmp_path):
43
+ _write(tmp_path, NS)
44
+ graph = extract(str(tmp_path / "pkg"))
45
+ assert graph.nodes["pkg.layers"].file is None, "a namespace module has no file"
46
+ assert {"pkg.layers.act.act", "pkg.layers.more.twice", "pkg.layers.deep.leaf.leaf"} <= set(graph.nodes)
47
+ calls = _edges(graph, "calls")
48
+ assert ("pkg.net.run", "pkg.layers.act.act") in calls
49
+ assert ("pkg.net.run", "pkg.layers.deep.leaf.leaf") in calls, "a package below a namespace dir"
50
+ assert ("pkg.layers.more.twice", "pkg.layers.act.act") in calls, "relative import inside it"
51
+ assert ("pkg.net", "pkg.layers.act") in _edges(graph, "imports")
52
+ assert "skipped" not in graph.provenance["inputs"]
53
+
54
+
55
+ def test_E3_names_python_cannot_import_stay_unread(tmp_path):
56
+ _write(tmp_path, {"pkg/__init__.py": "", "pkg/my-dir/x.py": "def f():\n return 1\n",
57
+ "pkg/ok/a.b.py": "def g():\n return 1\n", "pkg/ok/fine.py": "Y = 1\n"})
58
+ graph = extract(str(tmp_path / "pkg"))
59
+ skipped = {s["path"] for s in graph.provenance["inputs"].get("skipped", [])}
60
+ assert skipped == {"pkg/my-dir/x.py", "pkg/ok/a.b.py"}
61
+ assert "pkg.ok.fine.Y" in graph.nodes
62
+
63
+
64
+ def test_E3_a_sourceless_pyc_in_a_namespace_dir_is_not_imported(tmp_path):
65
+ _write(tmp_path, {"pkg/__init__.py": "", "pkg/layers/real.py": "Z = 1\n"})
66
+ marker = tmp_path / "MARKER"
67
+ evil = tmp_path / "pkg" / "layers" / "evil.py"
68
+ evil.write_text(f"import pathlib\npathlib.Path({str(marker)!r}).write_text('x')\n")
69
+ py_compile.compile(str(evil), cfile=str(evil.with_suffix(".pyc")), doraise=True)
70
+ evil.unlink()
71
+ graph = extract(str(tmp_path / "pkg"))
72
+ assert not marker.exists()
73
+ assert "pkg.layers.real.Z" in graph.nodes and "pkg.layers.evil" not in graph.nodes
74
+ assert graph.provenance["inputs"]["compiled"] == ["pkg/layers/evil.pyc"]
75
+
76
+
77
+ def test_E1_incremental_equals_full_after_an_edit_in_a_namespace_dir(tmp_path, monkeypatch, capsys):
78
+ root = tmp_path / "t"
79
+ _write(root, NS)
80
+ monkeypatch.chdir(root)
81
+ g, full = tmp_path / "g.json", tmp_path / "full.json"
82
+ assert main(["build", "pkg", "-o", str(g)]) == 0
83
+ _write(root, {"pkg/layers/act.py": "def act():\n return 11\n\n\ndef extra():\n return act()\n"})
84
+ assert main(["build", "pkg", "--incremental", "-o", str(g)]) == 0
85
+ assert main(["build", "pkg", "-o", str(full)]) == 0
86
+ a, b = (json.loads(p.read_text()) for p in (g, full))
87
+ for x in (a, b):
88
+ x["provenance"].pop("incremental", None)
89
+ assert a == b
90
+ assert "pkg.layers.act.extra" in {n["id"] for n in a["nodes"]}
91
+
92
+
93
+ # -- D2 -------------------------------------------------------------------------------------
94
+
95
+ ROOT = {
96
+ "repo/engine/dataset.py": "def get():\n return 1\n",
97
+ "repo/engine/util/io.py": "def load():\n return 2\n",
98
+ "repo/main.py": ("from engine.dataset import get\nimport engine.util.io\n\n\n"
99
+ "def main():\n return get() + engine.util.io.load()\n"),
100
+ "repo/helper.py": "X = 1\n",
101
+ "repo/tool.py": "from helper import X\n",
102
+ }
103
+
104
+
105
+ def test_E2_a_dotted_flat_import_points_at_the_module_it_imports(tmp_path):
106
+ _write(tmp_path, ROOT)
107
+ graph = extract(str(tmp_path / "repo"))
108
+ flat = {(e.source, e.target) for e in graph.edges
109
+ if e.type == "imports" and e.extras.get("resolution") == "flat"}
110
+ assert ("repo.main", "repo.engine.dataset") in flat
111
+ assert ("repo.main", "repo.engine.util.io") in flat
112
+ assert ("repo.main", "repo.engine") not in flat, "not the head any more"
113
+ assert ("repo.tool", "repo.helper") in flat, "a bare sibling import is unchanged"
114
+
115
+
116
+ def test_a_dotted_path_past_the_last_module_stops_at_the_module(tmp_path):
117
+ _write(tmp_path, {"repo/engine/dataset.py": "def get():\n return 1\n",
118
+ "repo/main.py": "from engine.dataset.get import nothing\n"})
119
+ graph = extract(str(tmp_path / "repo"))
120
+ assert ("repo.main", "repo.engine.dataset") in _edges(graph, "imports")
121
+
122
+
123
+ @pytest.mark.parametrize("target", ["engine.missing", "engine"])
124
+ def test_an_unknown_tail_falls_back_to_the_deepest_known_module(tmp_path, target):
125
+ _write(tmp_path, {"repo/engine/__init__.py": "", "repo/engine/dataset.py": "V = 1\n",
126
+ "repo/main.py": f"import {target}\n"})
127
+ graph = extract(str(tmp_path / "repo"))
128
+ assert ("repo.main", "repo.engine") in _edges(graph, "imports")
129
+
130
+
131
+ # -- D3 (amendment): imports anchored at a namespace root ------------------------------------
132
+
133
+ ANCHORED = {
134
+ "repo/python/net.py": "def f():\n return 1\n",
135
+ "repo/teeslice/model.py": "from python.net import f\n\n\ndef model():\n return f()\n",
136
+ "repo/other/python.py": "def g():\n return 2\n",
137
+ "repo/other/user.py": "from python import g\n\n\ndef use():\n return g()\n",
138
+ }
139
+
140
+
141
+ def test_E4b_a_nested_module_importing_from_the_root_resolves(tmp_path):
142
+ _write(tmp_path, ANCHORED)
143
+ graph = extract(str(tmp_path / "repo"))
144
+ flat = {(e.source, e.target) for e in graph.edges
145
+ if e.type == "imports" and e.extras.get("resolution") == "flat"}
146
+ assert ("repo.teeslice.model", "repo.python.net") in flat
147
+ assert ("repo.teeslice.model.model", "repo.python.net.f") in _edges(graph, "calls"), "E4‴"
148
+
149
+
150
+ def test_E4b_a_sibling_with_the_same_head_wins_over_the_root(tmp_path):
151
+ _write(tmp_path, ANCHORED)
152
+ graph = extract(str(tmp_path / "repo"))
153
+ assert ("repo.other.user", "repo.other.python") in _edges(graph, "imports")
154
+ assert ("repo.other.user", "repo.python") not in _edges(graph, "imports")
155
+ assert ("repo.other.user.use", "repo.other.python.g") in _edges(graph, "calls")
156
+
157
+
158
+ def test_a_regular_package_target_is_not_root_anchored(tmp_path):
159
+ files = {k.replace("repo/", "pkg/"): v for k, v in ANCHORED.items()}
160
+ files["pkg/__init__.py"] = ""
161
+ for d in ("python", "teeslice", "other"):
162
+ files[f"pkg/{d}/__init__.py"] = ""
163
+ _write(tmp_path, files)
164
+ graph = extract(str(tmp_path / "pkg"))
165
+ assert not any(t.startswith("pkg.python") for s, t in _edges(graph, "imports")
166
+ if s == "pkg.teeslice.model"), "`python` is not on sys.path for a package"
167
+
168
+
169
+ def test_a_flat_in_practice_package_is_still_not_root_anchored(tmp_path):
170
+ """R1-C72: a package that imports its own modules by bare name is flat in practice, so the
171
+ sibling inference applies. The root anchor must not: the package directory's *parent* is
172
+ on sys.path, not the directory itself, so a nested `from python.net import f` cannot reach
173
+ `pkg/python/net.py`."""
174
+ _write(tmp_path, {
175
+ "pkg/__init__.py": "", "pkg/helper.py": "X = 1\n", "pkg/tool.py": "from helper import X\n",
176
+ "pkg/python/__init__.py": "", "pkg/python/net.py": "def f():\n return 1\n",
177
+ "pkg/teeslice/__init__.py": "",
178
+ "pkg/teeslice/model.py": "from python.net import f\n\n\ndef model():\n return f()\n",
179
+ })
180
+ graph = extract(str(tmp_path / "pkg"))
181
+ assert ("pkg.tool", "pkg.helper") in _edges(graph, "imports"), "flat in practice"
182
+ assert not any(t.startswith("pkg.python") for s, t in _edges(graph, "imports")
183
+ if s == "pkg.teeslice.model")
184
+ assert ("pkg.teeslice.model.model", "pkg.python.net.f") not in _edges(graph, "calls")
@@ -164,3 +164,22 @@ def test_the_cli_build_exits_zero_and_prints_the_note(pyc_tree, tmp_path, capsys
164
164
  assert "[note] 1 compiled module(s) without source were not loaded: pkg/evil.pyc" in err
165
165
  assert not marker.exists()
166
166
  assert sys.modules.get("pkg.evil") is None
167
+
168
+
169
+ def test_orphan_pyc_in_pycache_is_not_listed(tmp_path):
170
+ """A cache of a deleted module is not a module (asked by bquearch, 2026-11-10): Python does
171
+ not import a sourceless `.pyc` from `__pycache__`, and listing it would be noise."""
172
+ pkg = tmp_path / "pkg"
173
+ pkg.mkdir()
174
+ (pkg / "__init__.py").write_text("")
175
+ (pkg / "live.py").write_text("def f():\n return 1\n")
176
+ gone = pkg / "gone.py"
177
+ gone.write_text("X = 1\n")
178
+ py_compile.compile(str(gone), doraise=True) # -> pkg/__pycache__/gone.cpython-XY.pyc
179
+ py_compile.compile(str(pkg / "live.py"), doraise=True)
180
+ gone.unlink()
181
+ assert any((pkg / "__pycache__").glob("gone.*.pyc"))
182
+ graph = extract(str(pkg))
183
+ assert "compiled" not in graph.provenance["inputs"]
184
+ assert not [d for d in diagnostics(graph) if d["code"] == COMPILED_MODULES_NOT_LOADED]
185
+ assert "pkg.gone" not in graph.nodes and "pkg.live.f" in graph.nodes
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