periplus-map 0.2.1__py3-none-any.whl

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 (272) hide show
  1. periplus/__init__.py +70 -0
  2. periplus/checkmap.py +80 -0
  3. periplus/cli.py +658 -0
  4. periplus/contract/schema/map.schema.json +138 -0
  5. periplus/contract/schema/navigation.schema.json +200 -0
  6. periplus/contract/schema/pack-file.schema.json +1405 -0
  7. periplus/contract/schema/pack-manifest.schema.json +245 -0
  8. periplus/contract/schema/project-settings.schema.json +85 -0
  9. periplus/contract/spec/engine.md +151 -0
  10. periplus/contract/spec/rules.md +352 -0
  11. periplus/detect.py +228 -0
  12. periplus/engine/__init__.py +5 -0
  13. periplus/engine/check.py +481 -0
  14. periplus/engine/emit.py +368 -0
  15. periplus/engine/packload.py +2321 -0
  16. periplus/engine/pattern.py +27 -0
  17. periplus/engine/rules.py +1946 -0
  18. periplus/engine/select.py +491 -0
  19. periplus/engine/source.py +172 -0
  20. periplus/engine/tree.py +424 -0
  21. periplus/errors.py +332 -0
  22. periplus/init.py +358 -0
  23. periplus/layout.py +28 -0
  24. periplus/manifest.py +498 -0
  25. periplus/map.py +364 -0
  26. periplus/navigate/__init__.py +1 -0
  27. periplus/navigate/find.py +143 -0
  28. periplus/navigate/ids.py +30 -0
  29. periplus/navigate/listing.py +42 -0
  30. periplus/navigate/mapfile.py +189 -0
  31. periplus/navigate/path.py +175 -0
  32. periplus/navigate/show.py +175 -0
  33. periplus/navigate/types.py +83 -0
  34. periplus/navigate/walk.py +138 -0
  35. periplus/packs/advancedqueue_basic@0.0.1/pack.yaml +14 -0
  36. periplus/packs/advancedqueue_basic@0.0.1/queue_job_type/queue_job_type.yaml +9 -0
  37. periplus/packs/advancedqueue_basic@0.0.1/queue_job_type/queue_job_type_annotation.yaml +43 -0
  38. periplus/packs/advancedqueue_basic@0.0.1/queue_job_type/queue_job_type_attribute.yaml +43 -0
  39. periplus/packs/ai_basic@0.0.1/ai_agent/ai_agent.yaml +8 -0
  40. periplus/packs/ai_basic@0.0.1/ai_agent/ai_agent_attribute.yaml +43 -0
  41. periplus/packs/ai_basic@0.0.1/ai_function_call/ai_function_call.yaml +8 -0
  42. periplus/packs/ai_basic@0.0.1/ai_function_call/ai_function_call_attribute.yaml +43 -0
  43. periplus/packs/ai_basic@0.0.1/pack.yaml +15 -0
  44. periplus/packs/config_pages_basic@0.0.1/bundle/config_pages_bundle_config.yaml +54 -0
  45. periplus/packs/config_pages_basic@0.0.1/pack.yaml +11 -0
  46. periplus/packs/crop_basic@0.0.1/bundle/crop_bundle_config.yaml +54 -0
  47. periplus/packs/crop_basic@0.0.1/pack.yaml +11 -0
  48. periplus/packs/drupal@0.1.0/block/block_placement.yaml +25 -0
  49. periplus/packs/drupal@0.1.0/block/block_placement_code.yaml +58 -0
  50. periplus/packs/drupal@0.1.0/block/block_placement_config.yaml +53 -0
  51. periplus/packs/drupal@0.1.0/block/block_plugin.yaml +52 -0
  52. periplus/packs/drupal@0.1.0/block/block_plugin_altered.yaml +61 -0
  53. periplus/packs/drupal@0.1.0/block/block_plugin_annotation.yaml +69 -0
  54. periplus/packs/drupal@0.1.0/block/block_plugin_attribute.yaml +56 -0
  55. periplus/packs/drupal@0.1.0/block/block_plugin_content.yaml +46 -0
  56. periplus/packs/drupal@0.1.0/block/block_plugin_derived.yaml +110 -0
  57. periplus/packs/drupal@0.1.0/block/block_plugin_deriver.yaml +30 -0
  58. periplus/packs/drupal@0.1.0/block/block_type.yaml +14 -0
  59. periplus/packs/drupal@0.1.0/block/block_type_code.yaml +43 -0
  60. periplus/packs/drupal@0.1.0/block/block_type_config.yaml +45 -0
  61. periplus/packs/drupal@0.1.0/cache/cache.yaml +18 -0
  62. periplus/packs/drupal@0.1.0/cache/cache_backend.yaml +31 -0
  63. periplus/packs/drupal@0.1.0/component/sdc.yaml +19 -0
  64. periplus/packs/drupal@0.1.0/component/sdc_definition.yaml +25 -0
  65. periplus/packs/drupal@0.1.0/component/sdc_use.yaml +25 -0
  66. periplus/packs/drupal@0.1.0/config/config_object.yaml +65 -0
  67. periplus/packs/drupal@0.1.0/display/display.yaml +32 -0
  68. periplus/packs/drupal@0.1.0/display/display_code.yaml +53 -0
  69. periplus/packs/drupal@0.1.0/display/display_config.yaml +95 -0
  70. periplus/packs/drupal@0.1.0/entity/entity.yaml +33 -0
  71. periplus/packs/drupal@0.1.0/entity/entity_class.yaml +60 -0
  72. periplus/packs/drupal@0.1.0/entity/entity_save.yaml +27 -0
  73. periplus/packs/drupal@0.1.0/entity/entity_type_annotation.yaml +85 -0
  74. periplus/packs/drupal@0.1.0/entity/entity_type_attribute.yaml +76 -0
  75. periplus/packs/drupal@0.1.0/field/field_instance_code.yaml +40 -0
  76. periplus/packs/drupal@0.1.0/field/field_instance_config.yaml +58 -0
  77. periplus/packs/drupal@0.1.0/field/field_storage.yaml +37 -0
  78. periplus/packs/drupal@0.1.0/field/field_storage_code.yaml +39 -0
  79. periplus/packs/drupal@0.1.0/field/field_storage_config.yaml +24 -0
  80. periplus/packs/drupal@0.1.0/form/form.yaml +48 -0
  81. periplus/packs/drupal@0.1.0/form/form_class.yaml +50 -0
  82. periplus/packs/drupal@0.1.0/form/form_id.yaml +48 -0
  83. periplus/packs/drupal@0.1.0/form/form_methods.yaml +39 -0
  84. periplus/packs/drupal@0.1.0/hook/hook.yaml +8 -0
  85. periplus/packs/drupal@0.1.0/hook/hook_attribute.yaml +28 -0
  86. periplus/packs/drupal@0.1.0/module/module.yaml +8 -0
  87. periplus/packs/drupal@0.1.0/module/module_info.yaml +50 -0
  88. periplus/packs/drupal@0.1.0/pack.yaml +184 -0
  89. periplus/packs/drupal@0.1.0/plugin/plugin.yaml +17 -0
  90. periplus/packs/drupal@0.1.0/plugin/plugin_annotation.yaml +120 -0
  91. periplus/packs/drupal@0.1.0/recommendations/recommendations.yaml +14 -0
  92. periplus/packs/drupal@0.1.0/service/service.yaml +19 -0
  93. periplus/packs/drupal@0.1.0/service/service_autowire.yaml +28 -0
  94. periplus/packs/drupal@0.1.0/service/service_definition.yaml +24 -0
  95. periplus/packs/drupal@0.1.0/service/service_use.yaml +43 -0
  96. periplus/packs/drupal_basic@0.3.0/action/action.yaml +9 -0
  97. periplus/packs/drupal_basic@0.3.0/action/action_annotation.yaml +43 -0
  98. periplus/packs/drupal_basic@0.3.0/action/action_attribute.yaml +43 -0
  99. periplus/packs/drupal_basic@0.3.0/block/block_placement.yaml +16 -0
  100. periplus/packs/drupal_basic@0.3.0/block/block_placement_config.yaml +51 -0
  101. periplus/packs/drupal_basic@0.3.0/block_plugin/block_plugin.yaml +14 -0
  102. periplus/packs/drupal_basic@0.3.0/block_plugin/block_plugin_annotation.yaml +47 -0
  103. periplus/packs/drupal_basic@0.3.0/block_plugin/block_plugin_attribute.yaml +43 -0
  104. periplus/packs/drupal_basic@0.3.0/block_type/block_type.yaml +8 -0
  105. periplus/packs/drupal_basic@0.3.0/block_type/block_type_config.yaml +54 -0
  106. periplus/packs/drupal_basic@0.3.0/boundary/boundary_types.yaml +19 -0
  107. periplus/packs/drupal_basic@0.3.0/bundle/bundle.yaml +20 -0
  108. periplus/packs/drupal_basic@0.3.0/bundle/bundle_config.yaml +393 -0
  109. periplus/packs/drupal_basic@0.3.0/call/call.yaml +349 -0
  110. periplus/packs/drupal_basic@0.3.0/component/component.yaml +30 -0
  111. periplus/packs/drupal_basic@0.3.0/config/config_object.yaml +119 -0
  112. periplus/packs/drupal_basic@0.3.0/constraint/constraint.yaml +8 -0
  113. periplus/packs/drupal_basic@0.3.0/constraint/constraint_annotation.yaml +43 -0
  114. periplus/packs/drupal_basic@0.3.0/constraint/constraint_attribute.yaml +43 -0
  115. periplus/packs/drupal_basic@0.3.0/display/display.yaml +30 -0
  116. periplus/packs/drupal_basic@0.3.0/display/display_config.yaml +203 -0
  117. periplus/packs/drupal_basic@0.3.0/display/display_mode_config.yaml +60 -0
  118. periplus/packs/drupal_basic@0.3.0/entity_type/config_entity_type_annotation.yaml +46 -0
  119. periplus/packs/drupal_basic@0.3.0/entity_type/config_entity_type_attribute.yaml +43 -0
  120. periplus/packs/drupal_basic@0.3.0/entity_type/content_entity_type_annotation.yaml +46 -0
  121. periplus/packs/drupal_basic@0.3.0/entity_type/content_entity_type_attribute.yaml +43 -0
  122. periplus/packs/drupal_basic@0.3.0/entity_type/entity_type.yaml +16 -0
  123. periplus/packs/drupal_basic@0.3.0/field/field_instance_config.yaml +116 -0
  124. periplus/packs/drupal_basic@0.3.0/field/field_storage.yaml +21 -0
  125. periplus/packs/drupal_basic@0.3.0/field/field_storage_config.yaml +45 -0
  126. periplus/packs/drupal_basic@0.3.0/field_formatter/field_formatter.yaml +8 -0
  127. periplus/packs/drupal_basic@0.3.0/field_formatter/field_formatter_annotation.yaml +46 -0
  128. periplus/packs/drupal_basic@0.3.0/field_formatter/field_formatter_attribute.yaml +43 -0
  129. periplus/packs/drupal_basic@0.3.0/field_type/field_type_annotation.yaml +46 -0
  130. periplus/packs/drupal_basic@0.3.0/field_type/field_type_attribute.yaml +50 -0
  131. periplus/packs/drupal_basic@0.3.0/field_widget/field_widget_annotation.yaml +46 -0
  132. periplus/packs/drupal_basic@0.3.0/field_widget/field_widget_attribute.yaml +50 -0
  133. periplus/packs/drupal_basic@0.3.0/form/form_id.yaml +80 -0
  134. periplus/packs/drupal_basic@0.3.0/hook/hook.yaml +100 -0
  135. periplus/packs/drupal_basic@0.3.0/hook/hook_attribute.yaml +64 -0
  136. periplus/packs/drupal_basic@0.3.0/hook/hook_theme_include.yaml +34 -0
  137. periplus/packs/drupal_basic@0.3.0/library/library.yaml +12 -0
  138. periplus/packs/drupal_basic@0.3.0/library/library_definition.yaml +58 -0
  139. periplus/packs/drupal_basic@0.3.0/local_action/local_action.yaml +12 -0
  140. periplus/packs/drupal_basic@0.3.0/local_action/local_action_definition.yaml +49 -0
  141. periplus/packs/drupal_basic@0.3.0/mail/mail.yaml +8 -0
  142. periplus/packs/drupal_basic@0.3.0/mail/mail_attribute.yaml +43 -0
  143. periplus/packs/drupal_basic@0.3.0/media_source/media_source.yaml +8 -0
  144. periplus/packs/drupal_basic@0.3.0/media_source/media_source_annotation.yaml +43 -0
  145. periplus/packs/drupal_basic@0.3.0/media_source/media_source_attribute.yaml +79 -0
  146. periplus/packs/drupal_basic@0.3.0/menu_link/menu_link.yaml +18 -0
  147. periplus/packs/drupal_basic@0.3.0/menu_link/menu_link_definition.yaml +48 -0
  148. periplus/packs/drupal_basic@0.3.0/module/module.yaml +7 -0
  149. periplus/packs/drupal_basic@0.3.0/module/module_info.yaml +58 -0
  150. periplus/packs/drupal_basic@0.3.0/pack.yaml +528 -0
  151. periplus/packs/drupal_basic@0.3.0/permission/permission.yaml +7 -0
  152. periplus/packs/drupal_basic@0.3.0/permission/permission_definition.yaml +27 -0
  153. periplus/packs/drupal_basic@0.3.0/queue_worker/queue_worker.yaml +9 -0
  154. periplus/packs/drupal_basic@0.3.0/queue_worker/queue_worker_annotation.yaml +43 -0
  155. periplus/packs/drupal_basic@0.3.0/queue_worker/queue_worker_attribute.yaml +43 -0
  156. periplus/packs/drupal_basic@0.3.0/rest_resource/rest_resource.yaml +8 -0
  157. periplus/packs/drupal_basic@0.3.0/rest_resource/rest_resource_annotation.yaml +43 -0
  158. periplus/packs/drupal_basic@0.3.0/rest_resource/rest_resource_attribute.yaml +43 -0
  159. periplus/packs/drupal_basic@0.3.0/role/role.yaml +14 -0
  160. periplus/packs/drupal_basic@0.3.0/role/role_config.yaml +44 -0
  161. periplus/packs/drupal_basic@0.3.0/route/route.yaml +42 -0
  162. periplus/packs/drupal_basic@0.3.0/route/route_definition.yaml +113 -0
  163. periplus/packs/drupal_basic@0.3.0/route/route_options.yaml +55 -0
  164. periplus/packs/drupal_basic@0.3.0/route/route_requirements.yaml +108 -0
  165. periplus/packs/drupal_basic@0.3.0/service/service.yaml +56 -0
  166. periplus/packs/drupal_basic@0.3.0/service/service_definition.yaml +181 -0
  167. periplus/packs/drupal_basic@0.3.0/template/template.yaml +86 -0
  168. periplus/packs/drupal_basic@0.3.0/template/template_route_link.yaml +30 -0
  169. periplus/packs/drupal_basic@0.3.0/theme/theme.yaml +15 -0
  170. periplus/packs/drupal_basic@0.3.0/theme/theme_info.yaml +61 -0
  171. periplus/packs/drupal_basic@0.3.0/theme_hook/template_suggestion.yaml +29 -0
  172. periplus/packs/drupal_basic@0.3.0/theme_hook/theme_hook.yaml +87 -0
  173. periplus/packs/drupal_basic@0.3.0/theme_hook/theme_hook_render.yaml +20 -0
  174. periplus/packs/drupal_basic@0.3.0/url/url.yaml +88 -0
  175. periplus/packs/drupal_basic@0.3.0/views_plugin/views_field_attribute.yaml +80 -0
  176. periplus/packs/drupal_basic@0.3.0/views_plugin/views_filter_attribute.yaml +80 -0
  177. periplus/packs/drupal_basic@0.3.0/views_plugin/views_plugin.yaml +15 -0
  178. periplus/packs/drupal_basic@0.3.0/views_plugin/views_style_attribute.yaml +80 -0
  179. periplus/packs/drupal_js_basic@0.0.1/attachment/attachment.yaml +12 -0
  180. periplus/packs/drupal_js_basic@0.0.1/attachment/attachment_in_php.yaml +15 -0
  181. periplus/packs/drupal_js_basic@0.0.1/attachment/attachment_in_php_array.yaml +52 -0
  182. periplus/packs/drupal_js_basic@0.0.1/attachment/attachment_in_twig.yaml +26 -0
  183. periplus/packs/drupal_js_basic@0.0.1/attachment/php_function_holder.yaml +13 -0
  184. periplus/packs/drupal_js_basic@0.0.1/behavior/behavior.yaml +198 -0
  185. periplus/packs/drupal_js_basic@0.0.1/pack.yaml +153 -0
  186. periplus/packs/drupal_js_basic@0.0.1/setting/setting.yaml +13 -0
  187. periplus/packs/drupal_js_basic@0.0.1/setting/setting_in_js.yaml +15 -0
  188. periplus/packs/drupal_js_basic@0.0.1/setting/setting_in_php.yaml +92 -0
  189. periplus/packs/drush_basic@0.0.1/command/command.yaml +15 -0
  190. periplus/packs/drush_basic@0.0.1/command/command_annotation.yaml +60 -0
  191. periplus/packs/drush_basic@0.0.1/command/command_attribute.yaml +88 -0
  192. periplus/packs/drush_basic@0.0.1/pack.yaml +29 -0
  193. periplus/packs/eck_basic@0.0.1/bundle/eck_bundle_config.yaml +56 -0
  194. periplus/packs/eck_basic@0.0.1/entity_type/eck_entity_type_config.yaml +26 -0
  195. periplus/packs/eck_basic@0.0.1/pack.yaml +28 -0
  196. periplus/packs/go@0.0.2/interfaces/satisfies.yaml +47 -0
  197. periplus/packs/go@0.0.2/pack.yaml +51 -0
  198. periplus/packs/go@0.0.2/types/find_declarations.yaml +137 -0
  199. periplus/packs/go@0.0.2/types/node_types.yaml +36 -0
  200. periplus/packs/go_basic@0.0.3/pack.yaml +104 -0
  201. periplus/packs/go_basic@0.0.3/rules/calls.yaml +25 -0
  202. periplus/packs/go_basic@0.0.3/rules/declarations.yaml +40 -0
  203. periplus/packs/go_basic@0.0.3/rules/imports.yaml +16 -0
  204. periplus/packs/go_basic@0.0.3/types/node_types.yaml +15 -0
  205. periplus/packs/js_basic@0.0.1/function/function.yaml +68 -0
  206. periplus/packs/js_basic@0.0.1/pack.yaml +50 -0
  207. periplus/packs/laravel_basic@0.0.5/pack.yaml +313 -0
  208. periplus/packs/laravel_basic@0.0.5/rules/classes.yaml +42 -0
  209. periplus/packs/laravel_basic@0.0.5/rules/config.yaml +229 -0
  210. periplus/packs/laravel_basic@0.0.5/rules/routes.yaml +210 -0
  211. periplus/packs/laravel_basic@0.0.5/rules/types.yaml +50 -0
  212. periplus/packs/laravel_basic@0.0.5/rules/views.yaml +100 -0
  213. periplus/packs/paragraphs_basic@0.0.1/bundle/paragraph_bundle_config.yaml +54 -0
  214. periplus/packs/paragraphs_basic@0.0.1/pack.yaml +12 -0
  215. periplus/packs/php@0.1.0/edges/edge_kinds.yaml +64 -0
  216. periplus/packs/php@0.1.0/edges/find_calls.yaml +34 -0
  217. periplus/packs/php@0.1.0/edges/find_imports.yaml +18 -0
  218. periplus/packs/php@0.1.0/edges/find_member_access.yaml +22 -0
  219. periplus/packs/php@0.1.0/edges/find_structure.yaml +38 -0
  220. periplus/packs/php@0.1.0/embedded/embedded_regions.yaml +19 -0
  221. periplus/packs/php@0.1.0/imports/imports.yaml +20 -0
  222. periplus/packs/php@0.1.0/pack.yaml +117 -0
  223. periplus/packs/php@0.1.0/resolution/excluded_tokens.yaml +23 -0
  224. periplus/packs/php@0.1.0/resolution/resolution.yaml +35 -0
  225. periplus/packs/php@0.1.0/types/find_declarations.yaml +102 -0
  226. periplus/packs/php@0.1.0/types/node_types.yaml +55 -0
  227. periplus/packs/php_basic@0.2.0/edges/edge_kinds.yaml +48 -0
  228. periplus/packs/php_basic@0.2.0/edges/find_structure.yaml +750 -0
  229. periplus/packs/php_basic@0.2.0/imports/imports.yaml +19 -0
  230. periplus/packs/php_basic@0.2.0/pack.yaml +94 -0
  231. periplus/packs/php_basic@0.2.0/types/find_declarations.yaml +267 -0
  232. periplus/packs/php_basic@0.2.0/types/node_types.yaml +55 -0
  233. periplus/packs/profile_basic@0.0.1/bundle/profile_bundle_config.yaml +54 -0
  234. periplus/packs/profile_basic@0.0.1/pack.yaml +12 -0
  235. periplus/packs/salesforce_basic@0.0.1/event/salesforce_event.yaml +36 -0
  236. periplus/packs/salesforce_basic@0.0.1/pack.yaml +31 -0
  237. periplus/packs/salesforce_basic@0.0.1/salesforce_mapping/salesforce_mapping.yaml +19 -0
  238. periplus/packs/salesforce_basic@0.0.1/salesforce_mapping/salesforce_mapping_config.yaml +83 -0
  239. periplus/packs/salesforce_basic@0.0.1/salesforce_mapping_field/salesforce_mapping_field.yaml +8 -0
  240. periplus/packs/salesforce_basic@0.0.1/salesforce_mapping_field/salesforce_mapping_field_annotation.yaml +43 -0
  241. periplus/packs/twig@0.0.1/pack.yaml +26 -0
  242. periplus/packs/twig@0.0.1/types/template.yaml +57 -0
  243. periplus/packs/twig_basic@0.1.0/pack.yaml +11 -0
  244. periplus/packs/twig_tweak_basic@0.0.1/pack.yaml +27 -0
  245. periplus/packs/twig_tweak_basic@0.0.1/rules/block.yaml +20 -0
  246. periplus/packs/twig_tweak_basic@0.0.1/rules/entity.yaml +35 -0
  247. periplus/packs/twig_tweak_basic@0.0.1/rules/field.yaml +21 -0
  248. periplus/packs/twig_tweak_basic@0.0.1/rules/menu.yaml +21 -0
  249. periplus/packs/webform_basic@0.0.1/bundle/webform_submission_bundle_config.yaml +54 -0
  250. periplus/packs/webform_basic@0.0.1/pack.yaml +20 -0
  251. periplus/packs/webform_basic@0.0.1/webform_handler/webform_handler.yaml +8 -0
  252. periplus/packs/webform_basic@0.0.1/webform_handler/webform_handler_annotation.yaml +43 -0
  253. periplus/packs/yaml@0.0.1/pack.yaml +72 -0
  254. periplus/packs/yaml@0.0.1/types/find_mapping_entry.yaml +21 -0
  255. periplus/packs/yaml@0.0.1/types/yaml_types.yaml +44 -0
  256. periplus/packs/yaml_basic@0.1.0/pack.yaml +10 -0
  257. periplus/packs.py +447 -0
  258. periplus/preflight.py +102 -0
  259. periplus/py.typed +0 -0
  260. periplus/report.py +596 -0
  261. periplus/resolution.py +355 -0
  262. periplus/settings.py +617 -0
  263. periplus/settings.stub.yml +99 -0
  264. periplus/spec.py +774 -0
  265. periplus/update.py +197 -0
  266. periplus/validate.py +655 -0
  267. periplus_map-0.2.1.dist-info/METADATA +566 -0
  268. periplus_map-0.2.1.dist-info/RECORD +272 -0
  269. periplus_map-0.2.1.dist-info/WHEEL +4 -0
  270. periplus_map-0.2.1.dist-info/entry_points.txt +2 -0
  271. periplus_map-0.2.1.dist-info/licenses/LICENSE +202 -0
  272. periplus_map-0.2.1.dist-info/licenses/NOTICE +2 -0
@@ -0,0 +1,491 @@
1
+ """Step two: turn folder names into directories, and directories into sorted file paths."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import posixpath
6
+ import re
7
+ from collections.abc import Mapping, Sequence
8
+ from dataclasses import dataclass
9
+ from errno import EBADF, ELOOP, ENOENT, ENOTDIR
10
+ from pathlib import Path, PurePosixPath
11
+ from stat import S_ISDIR, S_ISLNK, S_ISREG
12
+
13
+ from periplus.engine.source import SHORT_FORM_FORMAT, SourceUnreadable
14
+ from periplus.errors import ExitCode, HarnessError
15
+ from periplus.manifest import LoadedPack
16
+
17
+ __all__ = [
18
+ "FileType",
19
+ "FileTypes",
20
+ "FolderUnresolved",
21
+ "Selection",
22
+ "extended",
23
+ "files_in",
24
+ "folder_values",
25
+ "holds_double_star",
26
+ "reachable",
27
+ "resolve_folders",
28
+ "select_files",
29
+ ]
30
+
31
+ _REFERENCE = re.compile(r"\{([^{}]*)\}")
32
+
33
+
34
+ class FolderUnresolved(HarnessError):
35
+ """A folder name is unknown, cyclic, in conflict between packs, or leaves the project root."""
36
+
37
+ code = ExitCode.FOLDER_UNRESOLVED
38
+
39
+
40
+ def resolve_folders(
41
+ names: Sequence[str],
42
+ packs: Sequence[LoadedPack],
43
+ overrides: Mapping[str, str | Sequence[str]],
44
+ root: Path,
45
+ selection: Selection | None = None,
46
+ ) -> dict[str, tuple[str, ...]]:
47
+ """Each folder name as the sorted repository-relative directories it stands for.
48
+
49
+ The value comes from the settings overrides first, then from the pack manifests, where
50
+ ``folder_values`` settles which pack's value is used. A value is one string or a list of them,
51
+ and the folder stands for the union of their directories. A braced name inside a value is
52
+ another folder, each of its values in turn, a star that is a whole path segment expands to the
53
+ sorted directories present at that level, and a ``**`` segment to the directory and every
54
+ directory below it, links followed. A directory that does not exist is left out. A directory
55
+ reached through a link is named under the link's path. Only the names asked for, and those
56
+ they reference, are resolved. A ``**`` walk does not enter a folder ``selection`` skips.
57
+ """
58
+ _, settled = folder_values(packs)
59
+ return {
60
+ name: tuple(
61
+ sorted(
62
+ {
63
+ directory
64
+ for pattern in _patterns(name, settled, overrides, ())
65
+ for directory in _expand(pattern, root, selection)
66
+ }
67
+ )
68
+ )
69
+ for name in names
70
+ }
71
+
72
+
73
+ def holds_double_star(
74
+ name: str, packs: Sequence[LoadedPack], overrides: Mapping[str, str | Sequence[str]]
75
+ ) -> bool:
76
+ """Whether the folder's value, with each folder it names, holds a ``**`` segment. Raises
77
+ ``FolderUnresolved`` as ``resolve_folders`` does."""
78
+ _, settled = folder_values(packs)
79
+ return any("**" in pattern.split("/") for pattern in _patterns(name, settled, overrides, ()))
80
+
81
+
82
+ def reachable(pack: LoadedPack, packs: Sequence[LoadedPack]) -> set[str]:
83
+ """The pack's own name and the names of every pack it depends on, directly or not."""
84
+ manifests = {p.name.pack: p.manifest.document for p in packs}
85
+ seen: set[str] = set()
86
+ pending = [pack.name.pack]
87
+ while pending:
88
+ name = pending.pop()
89
+ if name not in seen:
90
+ seen.add(name)
91
+ depends = manifests.get(name, {}).get("depends")
92
+ pending.extend(depends if isinstance(depends, list) else [])
93
+ return seen
94
+
95
+
96
+ def folder_values(
97
+ packs: Sequence[LoadedPack],
98
+ ) -> tuple[dict[str, dict[tuple[str, ...], set[str]]], dict[str, tuple[str, ...] | None]]:
99
+ """Each folder name's values with the packs that give them, and the values that are used.
100
+
101
+ A pack's values for one folder are kept sorted, so two packs giving one set agree.
102
+
103
+ A pack that depends, directly or not, on every other pack giving the folder a value wins. The
104
+ value used is ``None`` when no pack does: two packs, neither depending on the other, conflict.
105
+ """
106
+ reach = {pack.name.pack: reachable(pack, packs) for pack in packs}
107
+ values: dict[str, dict[tuple[str, ...], set[str]]] = {}
108
+ for pack in packs:
109
+ folders = pack.manifest.document.get("folders")
110
+ for name, value in folders.items() if isinstance(folders, dict) else []:
111
+ given = tuple(sorted({value} if isinstance(value, str) else set(value)))
112
+ values.setdefault(name, {}).setdefault(given, set()).add(pack.name.pack)
113
+ settled: dict[str, tuple[str, ...] | None] = {}
114
+ for name, seen in values.items():
115
+ givers = {pack for owners in seen.values() for pack in owners}
116
+ winners = {
117
+ value
118
+ for value, owners in seen.items()
119
+ if any(givers <= reach[owner] for owner in owners)
120
+ }
121
+ settled[name] = winners.pop() if len(winners) == 1 else None
122
+ return values, settled
123
+
124
+
125
+ def _patterns(
126
+ name: str,
127
+ declared: Mapping[str, tuple[str, ...] | None],
128
+ overrides: Mapping[str, str | Sequence[str]],
129
+ stack: tuple[str, ...],
130
+ ) -> list[str]:
131
+ if name in stack:
132
+ raise FolderUnresolved(
133
+ f"folder {name} refers back to itself", {"folder": name, "chain": " -> ".join(stack)}
134
+ )
135
+ if name in overrides:
136
+ value = overrides[name]
137
+ elif (settled := declared.get(name)) is not None:
138
+ value = settled
139
+ else:
140
+ raise FolderUnresolved(f"folder {name} is not declared", {"folder": name})
141
+ patterns = []
142
+ for item in [value] if isinstance(value, str) else value:
143
+ # Split leaves text at even places and a referenced name at odd ones.
144
+ combined = [""]
145
+ for place, part in enumerate(_REFERENCE.split(item)):
146
+ options = _patterns(part, declared, overrides, (*stack, name)) if place % 2 else [part]
147
+ combined = [done + option for done in combined for option in options]
148
+ patterns.extend(combined)
149
+ return patterns
150
+
151
+
152
+ def _expand(pattern: str, root: Path, selection: Selection | None) -> tuple[str, ...]:
153
+ normal = posixpath.normpath(pattern)
154
+ if normal.startswith("/") or ".." in normal.split("/"):
155
+ raise FolderUnresolved(
156
+ f"folder value {pattern} leaves the project root", {"value": pattern}
157
+ )
158
+ found = [""]
159
+ for segment in normal.split("/"):
160
+ if segment == "**":
161
+ found = [below for base in found for below in _below(root, base, selection)]
162
+ elif segment == "*":
163
+ found = [
164
+ posixpath.join(base, child.name)
165
+ for base in found
166
+ for child in sorted(_listing(root, base) if (root / base).is_dir() else [])
167
+ if child.is_dir()
168
+ ]
169
+ else:
170
+ found = [posixpath.join(base, segment) for base in found]
171
+ return tuple(sorted({path for path in found if (root / path).is_dir()}))
172
+
173
+
174
+ def _below(root: Path, base: str, selection: Selection | None) -> list[str]:
175
+ """The directory and every directory below it, links followed.
176
+
177
+ A link whose real folder is the real folder of the directory holding it, or of one of that
178
+ directory's parents up to the filesystem root, is a loop and is not entered. Nor is a folder
179
+ the selection skips. A folder that cannot be listed raises ``SourceUnreadable``.
180
+ """
181
+ found: list[str] = []
182
+ above = {*(root / base).resolve().parents}
183
+ above.update((root / up).resolve() for up in PurePosixPath(base).parents)
184
+ pending: list[tuple[str, frozenset[Path]]] = [(base, frozenset(above))]
185
+ while pending:
186
+ path, parents = pending.pop()
187
+ folder = root / path
188
+ if folder.resolve() in parents or (selection is not None and selection.skips(path)):
189
+ continue
190
+ found.append(path)
191
+ if folder.is_dir():
192
+ inside = parents | {folder.resolve()}
193
+ pending.extend(
194
+ (posixpath.join(path, child.name), inside)
195
+ for child in _listing(root, path)
196
+ if child.is_dir()
197
+ )
198
+ return found
199
+
200
+
201
+ def _listing(root: Path, path: str) -> list[Path]:
202
+ """What the folder holds; a folder that cannot be listed raises ``SourceUnreadable``."""
203
+ try:
204
+ return list((root / path).iterdir())
205
+ except OSError as error:
206
+ message = f"folder {path} cannot be read: {error.strerror or error}"
207
+ raise SourceUnreadable(message, {"folder": path}) from error
208
+
209
+
210
+ @dataclass(frozen=True, slots=True)
211
+ class FileType:
212
+ """One file type: its names, the endings and whole file names that claim it, its reader, one of
213
+ ``data``, ``text`` or ``tree``, the pack that declares it, ``""`` for the settings, and whether
214
+ it is declared under ``files.types`` rather than by the short form or the settings, and the
215
+ data format it is read in."""
216
+
217
+ names: frozenset[str]
218
+ endings: frozenset[str]
219
+ whole: frozenset[str]
220
+ reader: str
221
+ pack: str
222
+ declared: bool = False
223
+ format: str = SHORT_FORM_FORMAT
224
+
225
+
226
+ @dataclass(frozen=True, slots=True)
227
+ class FileTypes:
228
+ """Every file type the loaded packs and the settings declare."""
229
+
230
+ types: tuple[FileType, ...]
231
+
232
+ @classmethod
233
+ def build(cls, packs: Sequence[LoadedPack], added: Mapping[str, str]) -> FileTypes:
234
+ """The packs' ``files.types``, and the short form ``files.extensions``: one type named by
235
+ each listed ending and claimed by them all, read as a tree when the pack pins a grammar and
236
+ as data otherwise.
237
+
238
+ A pack whose ``files.extends`` names a pack adds its ``files.add_extensions`` to each type
239
+ that pack declares. ``added`` is the settings key ``extensions``, ending to type name; the
240
+ ending moves to that type, a type of that name read as data when no pack declares one.
241
+ """
242
+ found: list[tuple[set[str], set[str], set[str], str, str, bool, str]] = []
243
+ for pack in packs:
244
+ document = pack.manifest.document
245
+ files = document.get("files")
246
+ files = files if isinstance(files, Mapping) else {}
247
+ listed = files.get("extensions")
248
+ if isinstance(listed, list) and listed:
249
+ reader = "tree" if isinstance(document.get("grammar"), Mapping) else "data"
250
+ bare = {*map(_bare, listed)}
251
+ found.append(({*listed}, bare, set(), reader, pack.name.pack, False, ""))
252
+ declared = files.get("types")
253
+ for name, spec in declared.items() if isinstance(declared, Mapping) else ():
254
+ endings = {_bare(ending) for ending in spec.get("endings", [])}
255
+ whole = set(spec.get("names", []))
256
+ reader, form = str(spec["reader"]), str(spec.get("format", ""))
257
+ found.append(({name}, endings, whole, reader, pack.name.pack, True, form))
258
+ for pack in packs:
259
+ files = pack.manifest.document.get("files")
260
+ if isinstance(files, Mapping):
261
+ adds = {_bare(ending) for ending in files.get("add_extensions", [])}
262
+ for _, endings, _, _, owner, _, _ in found:
263
+ if owner in extended(files):
264
+ endings.update(adds)
265
+ for ending, name in added.items():
266
+ for _, endings, _, _, _, _, _ in found:
267
+ endings.discard(_bare(ending))
268
+ target = [entry for entry in found if name in entry[0]]
269
+ if not target:
270
+ target = [({name}, set(), set(), "data", "", False, "")]
271
+ found.extend(target)
272
+ for _, endings, _, _, _, _, _ in target:
273
+ endings.add(_bare(ending))
274
+ return cls(
275
+ tuple(
276
+ FileType(frozenset(n), frozenset(e), frozenset(w), r, p, d, f or SHORT_FORM_FORMAT)
277
+ for n, e, w, r, p, d, f in found
278
+ )
279
+ )
280
+
281
+ def named(self, name: str) -> tuple[FileType, ...]:
282
+ """The types the name names."""
283
+ return tuple(kind for kind in self.types if name in kind.names)
284
+
285
+ def names_of(self, file_name: str) -> frozenset[str]:
286
+ """The names of the types that claim a file name; empty when none does."""
287
+ claimed = self.claim(file_name)
288
+ return claimed[0] if claimed is not None else frozenset()
289
+
290
+ def claim(self, file_name: str) -> tuple[frozenset[str], str] | None:
291
+ """The names of the types that claim a file name, and its stem; ``None`` when none does.
292
+
293
+ A whole file name claims first, and its stem is the whole name. Otherwise the longest
294
+ ending, after a dot and with something before it, claims, and the stem is the name with
295
+ that dot and ending removed.
296
+ """
297
+ whole = [kind.names for kind in self.types if file_name in kind.whole]
298
+ if whole:
299
+ return frozenset().union(*whole), file_name
300
+ best = max(
301
+ (
302
+ ending
303
+ for kind in self.types
304
+ for ending in kind.endings
305
+ if len(file_name) > len(ending) + 1 and file_name.endswith(f".{ending}")
306
+ ),
307
+ key=len,
308
+ default=None,
309
+ )
310
+ if best is None:
311
+ return None
312
+ claimants = [kind.names for kind in self.types if best in kind.endings]
313
+ return frozenset().union(*claimants), file_name[: -len(best) - 1]
314
+
315
+
316
+ def _bare(ending: str) -> str:
317
+ return ending.removeprefix(".")
318
+
319
+
320
+ def extended(files: Mapping[str, object]) -> set[str]:
321
+ """The packs a ``files`` block's ``extends`` names: one string, or a list of them."""
322
+ extends = files.get("extends")
323
+ return (
324
+ {extends}
325
+ if isinstance(extends, str)
326
+ else set(extends)
327
+ if isinstance(extends, list)
328
+ else set()
329
+ )
330
+
331
+
332
+ def _glob(pattern: str) -> re.Pattern[str]:
333
+ """A path pattern as a regular expression: ``*`` stays in one segment, ``**`` crosses them."""
334
+ out: list[str] = []
335
+ rest = pattern.removeprefix("./")
336
+ while rest:
337
+ for token, expression in (
338
+ ("**/", "(?:.*/)?"),
339
+ ("**", ".*"),
340
+ ("*", "[^/]*"),
341
+ ("?", "[^/]"),
342
+ ):
343
+ if rest.startswith(token):
344
+ out.append(expression)
345
+ rest = rest[len(token) :]
346
+ break
347
+ else:
348
+ out.append(re.escape(rest[0]))
349
+ rest = rest[1:]
350
+ return re.compile("".join(out))
351
+
352
+
353
+ @dataclass(frozen=True, slots=True)
354
+ class Selection:
355
+ """Which candidate files are read: the settings' patterns and the packs' excludes.
356
+
357
+ ``extensions`` is the settings key of that name, a mapping of extension to file type. Every
358
+ other field holds compiled patterns, each matched against a whole path relative to the project
359
+ root.
360
+ """
361
+
362
+ extensions: Mapping[str, str]
363
+ include: tuple[re.Pattern[str], ...]
364
+ first_party_exclude: tuple[re.Pattern[str], ...]
365
+ exclude: tuple[re.Pattern[str], ...]
366
+ re_include: tuple[re.Pattern[str], ...]
367
+
368
+ @classmethod
369
+ def build(
370
+ cls,
371
+ packs: Sequence[LoadedPack],
372
+ extensions: Mapping[str, str],
373
+ include: Sequence[str],
374
+ first_party_exclude: Sequence[str],
375
+ exclude: Sequence[str],
376
+ re_include: Sequence[str],
377
+ ) -> Selection:
378
+ """The settings' lists plus the packs' ``files.exclude`` and ``files.add_excludes``."""
379
+ excluded = list(exclude)
380
+ for pack in packs:
381
+ files = pack.manifest.document.get("files")
382
+ for key in ("exclude", "add_excludes"):
383
+ listed = files.get(key) if isinstance(files, dict) else None
384
+ excluded.extend(listed if isinstance(listed, list) else [])
385
+ return cls(
386
+ extensions,
387
+ *(
388
+ tuple(_glob(p) for p in patterns)
389
+ for patterns in (include, first_party_exclude, excluded, re_include)
390
+ ),
391
+ )
392
+
393
+ def skips(self, folder: str) -> bool:
394
+ """Whether every file below the folder is excluded: no ``re_include`` is set and one
395
+ exclude pattern matches the folder followed by any name, at one level and at two."""
396
+ probes = (f"{folder}/\0", f"{folder}/\0/\0")
397
+ return not self.re_include and any(
398
+ all(pattern.fullmatch(probe) for probe in probes) for pattern in self.exclude
399
+ )
400
+
401
+ def reads(self, path: str) -> bool:
402
+ """Whether the file is read."""
403
+ return (
404
+ (not self.include or _any(self.include, path))
405
+ and not _any(self.first_party_exclude, path)
406
+ and (not _any(self.exclude, path) or _any(self.re_include, path))
407
+ )
408
+
409
+
410
+ def _any(patterns: Sequence[re.Pattern[str]], path: str) -> bool:
411
+ return any(pattern.fullmatch(path) for pattern in patterns)
412
+
413
+
414
+ def _followed_mode(link: Path) -> int:
415
+ """The mode of the file a link leads to, or 0 when it leads nowhere, as 3.11 ``Path.is_file``
416
+ decides; any other fault raises."""
417
+ try:
418
+ return link.stat().st_mode
419
+ except OSError as error:
420
+ if error.errno in (ENOENT, ENOTDIR, EBADF, ELOOP):
421
+ return 0
422
+ raise
423
+
424
+
425
+ def files_in(
426
+ root: Path, directories: Sequence[str], selection: Selection
427
+ ) -> tuple[list[str], list[str]]:
428
+ """Every file at any depth below the directories that the selection reads, of any type, sorted,
429
+ and the folders that could not be listed, sorted.
430
+
431
+ A folder is listed once; a linked folder, or one whose every file is excluded, is not entered.
432
+ This walk only reports, so a folder it cannot list, or whose children it cannot examine, is
433
+ recorded rather than raised, and none of its children are taken; selection
434
+ for rules lists through ``_listing`` alone and still raises.
435
+ """
436
+ found: set[str] = set()
437
+ unlisted: set[str] = set()
438
+ pending = [directory for directory in directories if (root / directory).is_dir()]
439
+ walked: set[str] = set()
440
+ while pending:
441
+ directory = pending.pop()
442
+ if directory in walked:
443
+ continue
444
+ walked.add(directory)
445
+ try:
446
+ # From 3.13 is_file, is_dir and is_symlink return False on any OSError; lstat and
447
+ # stat still raise for a child of a folder that cannot be searched.
448
+ modes = [(child, child.lstat().st_mode) for child in _listing(root, directory)]
449
+ children = [
450
+ (
451
+ posixpath.join(directory, child.name),
452
+ S_ISREG(kind := _followed_mode(child) if S_ISLNK(mode) else mode),
453
+ S_ISDIR(kind),
454
+ S_ISLNK(mode),
455
+ )
456
+ for child, mode in modes
457
+ ]
458
+ except (SourceUnreadable, OSError):
459
+ unlisted.add(directory)
460
+ continue
461
+ for path, is_file, is_dir, is_link in children:
462
+ if is_file:
463
+ found.add(path)
464
+ elif is_dir and not is_link and not selection.skips(path):
465
+ pending.append(path)
466
+ return sorted(path for path in found if selection.reads(path)), sorted(unlisted)
467
+
468
+
469
+ def select_files(
470
+ root: Path,
471
+ directories: Sequence[str],
472
+ filetype: str,
473
+ types: FileTypes,
474
+ selection: Selection,
475
+ ) -> tuple[list[str], list[str]]:
476
+ """The candidates inside the directories, sorted: those read, then those the patterns removed.
477
+
478
+ A candidate is a file directly inside a directory that a type of the name ``filetype`` claims.
479
+ """
480
+ candidates: set[str] = set()
481
+ for directory in directories:
482
+ folder = root / directory
483
+ if not folder.is_dir():
484
+ continue
485
+ candidates.update(
486
+ posixpath.join(directory, child.name)
487
+ for child in _listing(root, directory)
488
+ if child.is_file() and filetype in types.names_of(child.name)
489
+ )
490
+ read = sorted(path for path in candidates if selection.reads(path))
491
+ return read, sorted(candidates.difference(read))
@@ -0,0 +1,172 @@
1
+ """Read a YAML source file as plain values that keep the line of every key and list item."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import math
6
+ from collections.abc import Callable, Mapping, Sequence
7
+ from dataclasses import dataclass
8
+ from pathlib import Path
9
+ from typing import Any
10
+
11
+ from ruamel.yaml import YAML
12
+ from ruamel.yaml.error import YAMLError
13
+ from ruamel.yaml.nodes import MappingNode, Node, ScalarNode, SequenceNode
14
+
15
+ from periplus.errors import ExitCode, HarnessError
16
+
17
+ __all__ = [
18
+ "DATA_READERS",
19
+ "SHORT_FORM_FORMAT",
20
+ "Entry",
21
+ "Hit",
22
+ "SourceUnreadable",
23
+ "load_data",
24
+ "load_text",
25
+ "plain",
26
+ "resolve_path",
27
+ ]
28
+
29
+ _CORE = "tag:yaml.org,2002:"
30
+ # binary and timestamp are standard types an exporter writes; both are read as their text.
31
+ _TAGS = {
32
+ _CORE + name
33
+ for name in ("str", "int", "float", "bool", "null", "map", "seq", "binary", "timestamp")
34
+ }
35
+
36
+
37
+ class SourceUnreadable(HarnessError):
38
+ """A source file cannot be read as data."""
39
+
40
+ code = ExitCode.SOURCE_UNREADABLE
41
+
42
+
43
+ @dataclass(frozen=True, slots=True)
44
+ class Entry:
45
+ """A value with its 1-based line: a scalar, a ``dict`` of entries, or a ``list`` of entries."""
46
+
47
+ value: Any
48
+ line: int
49
+
50
+
51
+ @dataclass(frozen=True, slots=True)
52
+ class Hit:
53
+ """One place a key path reached: its value, the line of its key or item, and its last key."""
54
+
55
+ value: Any
56
+ line: int
57
+ key: str | None
58
+
59
+
60
+ def load_data(path: Path, name: str) -> dict[str, Entry]:
61
+ """The file's root mapping. ``name`` is the repository-relative path used in the message.
62
+
63
+ Raises ``SourceUnreadable`` for a parse error, bytes that are not UTF-8, a root that is not a
64
+ mapping, a tag outside the YAML core set on a key, a tag in the YAML namespace outside that set
65
+ on a value, and a key written twice in one mapping. A value with a local tag, one written with
66
+ a single ``!``, is read as if untagged: text as its text. The text is composed, never
67
+ constructed, so no tag runs anything.
68
+ """
69
+ try:
70
+ root = YAML(typ="safe", pure=True).compose(path.read_bytes().decode("utf-8"))
71
+ except (UnicodeDecodeError, YAMLError) as error:
72
+ raise SourceUnreadable(f"{name} cannot be read: {error}", {"file": name}) from error
73
+ if not isinstance(root, MappingNode):
74
+ raise SourceUnreadable(f"{name} does not hold a mapping at its root", {"file": name})
75
+ value: dict[str, Entry] = _convert(root, name, ())
76
+ return value
77
+
78
+
79
+ #: Each data format the engine reads, by the name a declared file type gives under ``format``.
80
+ DATA_READERS: Mapping[str, Callable[[Path, str], dict[str, Entry]]] = {"yaml": load_data}
81
+
82
+ #: The format of a data type that names none: the short form ``extensions`` and the settings'.
83
+ SHORT_FORM_FORMAT = "yaml"
84
+
85
+
86
+ def load_text(path: Path, name: str) -> str:
87
+ """The file's text, each carriage return and line feed made one line feed, so a checkout with
88
+ either line end gives one map. Raises ``SourceUnreadable`` for bytes that are not UTF-8."""
89
+ try:
90
+ return path.read_bytes().decode("utf-8").replace("\r\n", "\n")
91
+ except UnicodeDecodeError as error:
92
+ raise SourceUnreadable(f"{name} cannot be read as text: {error}", {"file": name}) from error
93
+
94
+
95
+ def _convert(node: Node, name: str, active: tuple[int, ...]) -> Any:
96
+ local = str(node.tag).startswith("!")
97
+ if (node.tag not in _TAGS and not local) or id(node) in active:
98
+ raise SourceUnreadable(
99
+ f"{name} line {node.start_mark.line + 1} holds the tag {node.tag} "
100
+ "or an alias that contains itself",
101
+ {"file": name},
102
+ )
103
+ inside = (*active, id(node))
104
+ if isinstance(node, MappingNode):
105
+ mapping: dict[str, Entry] = {}
106
+ for key, item in node.value:
107
+ if key.tag not in _TAGS:
108
+ raise SourceUnreadable(
109
+ f"{name} line {key.start_mark.line + 1} holds the key tag {key.tag}",
110
+ {"file": name},
111
+ )
112
+ text = str(key.value) if isinstance(key, ScalarNode) else ""
113
+ if not text or text in mapping:
114
+ raise SourceUnreadable(
115
+ f"{name} line {key.start_mark.line + 1} writes the key {text!r} twice "
116
+ "or uses a key that is not a plain scalar",
117
+ {"file": name},
118
+ )
119
+ mapping[text] = Entry(_convert(item, name, inside), key.start_mark.line + 1)
120
+ return mapping
121
+ if isinstance(node, SequenceNode):
122
+ return [
123
+ Entry(_convert(item, name, inside), item.start_mark.line + 1) for item in node.value
124
+ ]
125
+ return str(node.value) if local else _scalar(str(node.tag).removeprefix(_CORE), str(node.value))
126
+
127
+
128
+ def _scalar(tag: str, text: str) -> Any:
129
+ if tag == "null":
130
+ return None
131
+ if tag == "bool":
132
+ return text.lower() == "true"
133
+ if tag == "int":
134
+ try:
135
+ return int(text)
136
+ except ValueError:
137
+ return int(text, 0)
138
+ if tag == "float":
139
+ lowered = text.lower().replace("_", "")
140
+ if lowered.endswith(".inf"):
141
+ return -math.inf if lowered.startswith("-") else math.inf
142
+ return math.nan if lowered == ".nan" else float(lowered)
143
+ return text
144
+
145
+
146
+ def plain(value: Any) -> Any:
147
+ """The value with every ``Entry`` unwrapped, for writing into the map."""
148
+ if isinstance(value, dict):
149
+ return {key: plain(item.value) for key, item in value.items()}
150
+ if isinstance(value, list):
151
+ return [plain(item.value) for item in value]
152
+ return value
153
+
154
+
155
+ def resolve_path(root: dict[str, Entry], path: str) -> list[Hit]:
156
+ """Every place the key path reaches. A star as a whole segment takes each key or item."""
157
+ hits = [Hit(root, 1, None)]
158
+ for segment in path.split("."):
159
+ found: list[Hit] = []
160
+ for hit in hits:
161
+ found.extend(_step(hit.value, segment))
162
+ hits = found
163
+ return hits
164
+
165
+
166
+ def _step(value: Any, segment: str) -> Sequence[Hit]:
167
+ if isinstance(value, dict):
168
+ keys = list(value) if segment == "*" else [segment] if segment in value else []
169
+ return [Hit(value[key].value, value[key].line, key) for key in keys]
170
+ if isinstance(value, list) and segment == "*":
171
+ return [Hit(item.value, item.line, None) for item in value]
172
+ return []