plain-parser 0.2.1.dev23__tar.gz → 1.0.0.dev1__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 (218) hide show
  1. plain_parser-1.0.0.dev1/PKG-INFO +15 -0
  2. plain_parser-1.0.0.dev1/pyproject.toml +32 -0
  3. plain_parser-1.0.0.dev1/resources/error_messages.md +154 -0
  4. plain_parser-1.0.0.dev1/resources/python_api.md +199 -0
  5. {plain_parser-0.2.1.dev23 → plain_parser-1.0.0.dev1}/src/plain_parser/__init__.py +3 -3
  6. plain_parser-1.0.0.dev1/src/plain_parser/cli.py +246 -0
  7. plain_parser-1.0.0.dev1/src/plain_parser/concept_utils.py +188 -0
  8. {plain_parser-0.2.1.dev23 → plain_parser-1.0.0.dev1}/src/plain_parser/exceptions.py +3 -11
  9. plain_parser-1.0.0.dev1/src/plain_parser/graph.py +132 -0
  10. plain_parser-1.0.0.dev1/src/plain_parser/liquid_nodes.py +63 -0
  11. plain_parser-1.0.0.dev1/src/plain_parser/loaders.py +149 -0
  12. plain_parser-1.0.0.dev1/src/plain_parser/plain_file.py +671 -0
  13. plain_parser-1.0.0.dev1/src/plain_parser/plain_spec.py +223 -0
  14. plain_parser-1.0.0.dev1/src/plain_parser/project.py +155 -0
  15. plain_parser-1.0.0.dev1/src/plain_parser/test_plain_file.py +230 -0
  16. plain_parser-1.0.0.dev1/tests/test_cli.py +174 -0
  17. plain_parser-1.0.0.dev1/tests/test_concept_utils.py +103 -0
  18. plain_parser-1.0.0.dev1/tests/test_exceptions.py +24 -0
  19. plain_parser-1.0.0.dev1/tests/test_graph.py +58 -0
  20. plain_parser-1.0.0.dev1/tests/test_import_modules.py +114 -0
  21. plain_parser-1.0.0.dev1/tests/test_liquid_rendering.py +107 -0
  22. plain_parser-1.0.0.dev1/tests/test_loaders.py +61 -0
  23. plain_parser-1.0.0.dev1/tests/test_parse_scenarios.py +88 -0
  24. plain_parser-1.0.0.dev1/tests/test_parse_sections.py +181 -0
  25. plain_parser-1.0.0.dev1/tests/test_parse_single_module.py +82 -0
  26. plain_parser-1.0.0.dev1/tests/test_plain_file.py +20 -0
  27. plain_parser-1.0.0.dev1/tests/test_plain_spec.py +185 -0
  28. plain_parser-1.0.0.dev1/tests/test_project.py +146 -0
  29. plain_parser-1.0.0.dev1/tests/test_requires_chain.py +116 -0
  30. plain_parser-1.0.0.dev1/tests/test_test_plain_file.py +37 -0
  31. plain_parser-0.2.1.dev23/.flake8 +0 -13
  32. plain_parser-0.2.1.dev23/.github/dependabot.yml +0 -38
  33. plain_parser-0.2.1.dev23/.github/scripts/record-linear-release.cjs +0 -232
  34. plain_parser-0.2.1.dev23/.github/workflows/lint-and-test.yml +0 -50
  35. plain_parser-0.2.1.dev23/.github/workflows/notify-slack-on-main-merge.yml +0 -42
  36. plain_parser-0.2.1.dev23/.github/workflows/publish-dev-to-pypi.yml +0 -204
  37. plain_parser-0.2.1.dev23/.github/workflows/publish-to-pypi.yml +0 -290
  38. plain_parser-0.2.1.dev23/.gitignore +0 -8
  39. plain_parser-0.2.1.dev23/LICENSE +0 -21
  40. plain_parser-0.2.1.dev23/PKG-INFO +0 -145
  41. plain_parser-0.2.1.dev23/README.md +0 -122
  42. plain_parser-0.2.1.dev23/pyproject.toml +0 -71
  43. plain_parser-0.2.1.dev23/src/plain_parser/cli.py +0 -303
  44. plain_parser-0.2.1.dev23/src/plain_parser/concept_utils.py +0 -241
  45. plain_parser-0.2.1.dev23/src/plain_parser/graph.py +0 -164
  46. plain_parser-0.2.1.dev23/src/plain_parser/liquid_nodes.py +0 -109
  47. plain_parser-0.2.1.dev23/src/plain_parser/loaders.py +0 -151
  48. plain_parser-0.2.1.dev23/src/plain_parser/plain_file.py +0 -916
  49. plain_parser-0.2.1.dev23/src/plain_parser/plain_spec.py +0 -283
  50. plain_parser-0.2.1.dev23/src/plain_parser/project.py +0 -160
  51. plain_parser-0.2.1.dev23/src/plain_parser/test_plain_file.py +0 -247
  52. plain_parser-0.2.1.dev23/tests/__init__.py +0 -0
  53. plain_parser-0.2.1.dev23/tests/conftest.py +0 -31
  54. plain_parser-0.2.1.dev23/tests/data/cli/base64_resource.plain +0 -8
  55. plain_parser-0.2.1.dev23/tests/data/cli/binary.bin +0 -0
  56. plain_parser-0.2.1.dev23/tests/data/cli/binary_resource.plain +0 -8
  57. plain_parser-0.2.1.dev23/tests/data/cli/code_variable_conflict.plain +0 -11
  58. plain_parser-0.2.1.dev23/tests/data/cli/code_variable_template.plain +0 -1
  59. plain_parser-0.2.1.dev23/tests/data/cli/missing_resource.plain +0 -8
  60. plain_parser-0.2.1.dev23/tests/data/cli/not_plain.md +0 -1
  61. plain_parser-0.2.1.dev23/tests/data/cli/notes.md +0 -3
  62. plain_parser-0.2.1.dev23/tests/data/cli/parent_link/a/spec/top.plain +0 -8
  63. plain_parser-0.2.1.dev23/tests/data/cli/parent_link/b/shared/notes.md +0 -1
  64. plain_parser-0.2.1.dev23/tests/data/cli/parent_link/b/tpl/.gitkeep +0 -0
  65. plain_parser-0.2.1.dev23/tests/data/cli/project/config.yaml +0 -3
  66. plain_parser-0.2.1.dev23/tests/data/cli/project/tests/todo/add-task.plain +0 -17
  67. plain_parser-0.2.1.dev23/tests/data/cli/project/tests/todo/list-tasks.plain +0 -11
  68. plain_parser-0.2.1.dev23/tests/data/cli/project/todo.plain +0 -15
  69. plain_parser-0.2.1.dev23/tests/data/cli/requires_binary_resource_base.plain +0 -8
  70. plain_parser-0.2.1.dev23/tests/data/cli/requires_binary_resource_top.plain +0 -13
  71. plain_parser-0.2.1.dev23/tests/data/cli/resource_before_frid_walk/base.plain +0 -9
  72. plain_parser-0.2.1.dev23/tests/data/cli/resource_before_frid_walk/snippet.plain +0 -1
  73. plain_parser-0.2.1.dev23/tests/data/cli/resource_before_frid_walk/top.plain +0 -16
  74. plain_parser-0.2.1.dev23/tests/data/cli/shared_link_helper.plain +0 -8
  75. plain_parser-0.2.1.dev23/tests/data/cli/shared_link_top.plain +0 -13
  76. plain_parser-0.2.1.dev23/tests/data/cli/subdir/nested.plain +0 -8
  77. plain_parser-0.2.1.dev23/tests/data/cli/template_link/spec/top.plain +0 -8
  78. plain_parser-0.2.1.dev23/tests/data/cli/template_link/tpl/notes.md +0 -1
  79. plain_parser-0.2.1.dev23/tests/data/cli/undefined_concept.plain +0 -15
  80. plain_parser-0.2.1.dev23/tests/data/cli/valid.plain +0 -12
  81. plain_parser-0.2.1.dev23/tests/data/imports/circular_imports_1.plain +0 -8
  82. plain_parser-0.2.1.dev23/tests/data/imports/circular_imports_2.plain +0 -8
  83. plain_parser-0.2.1.dev23/tests/data/imports/circular_imports_main.plain +0 -13
  84. plain_parser-0.2.1.dev23/tests/data/imports/diamond_import_1.plain +0 -16
  85. plain_parser-0.2.1.dev23/tests/data/imports/diamond_import_2.plain +0 -16
  86. plain_parser-0.2.1.dev23/tests/data/imports/diamond_import_common.plain +0 -11
  87. plain_parser-0.2.1.dev23/tests/data/imports/diamond_imports_main.plain +0 -14
  88. plain_parser-0.2.1.dev23/tests/data/imports/import_with_functionalities.plain +0 -8
  89. plain_parser-0.2.1.dev23/tests/data/imports/imports_module_with_functionalities.plain +0 -13
  90. plain_parser-0.2.1.dev23/tests/data/imports/non_existent_import.plain +0 -13
  91. plain_parser-0.2.1.dev23/tests/data/plainfile/add_new_task_modal_specification.yaml +0 -1
  92. plain_parser-0.2.1.dev23/tests/data/plainfile/duplicate_specification_heading.plain +0 -7
  93. plain_parser-0.2.1.dev23/tests/data/plainfile/empty_functional_specs_section.plain +0 -4
  94. plain_parser-0.2.1.dev23/tests/data/plainfile/invalid_specification_order.plain +0 -7
  95. plain_parser-0.2.1.dev23/tests/data/plainfile/missing_non_functional_requirements.plain +0 -6
  96. plain_parser-0.2.1.dev23/tests/data/plainfile/no_functional_specs_section.plain +0 -5
  97. plain_parser-0.2.1.dev23/tests/data/plainfile/plain_source_with_absolute_link.plain +0 -10
  98. plain_parser-0.2.1.dev23/tests/data/plainfile/plain_source_with_missing_link.plain +0 -10
  99. plain_parser-0.2.1.dev23/tests/data/plainfile/plain_source_with_url_link.plain +0 -10
  100. plain_parser-0.2.1.dev23/tests/data/plainfile/task_list_ui_specification.yaml +0 -1
  101. plain_parser-0.2.1.dev23/tests/data/plainfile/task_manager_with_reference_links.plain +0 -46
  102. plain_parser-0.2.1.dev23/tests/data/plainfile/without_non_functional_requirement.plain +0 -6
  103. plain_parser-0.2.1.dev23/tests/data/plainfileparser/concept_validation_defined_nondefined.plain +0 -19
  104. plain_parser-0.2.1.dev23/tests/data/plainfileparser/concept_validation_defined_nondefined_2.plain +0 -19
  105. plain_parser-0.2.1.dev23/tests/data/plainfileparser/concept_validation_definition.plain +0 -17
  106. plain_parser-0.2.1.dev23/tests/data/plainfileparser/concept_validation_noconcepts.plain +0 -18
  107. plain_parser-0.2.1.dev23/tests/data/plainfileparser/concept_validation_nonconcept.plain +0 -16
  108. plain_parser-0.2.1.dev23/tests/data/plainfileparser/concept_validation_nondefined.plain +0 -19
  109. plain_parser-0.2.1.dev23/tests/data/plainfileparser/concept_validation_redefinition.plain +0 -19
  110. plain_parser-0.2.1.dev23/tests/data/plainfileparser/concept_validation_several_concepts.plain +0 -16
  111. plain_parser-0.2.1.dev23/tests/data/plainfileparser/concept_validation_valid.plain +0 -17
  112. plain_parser-0.2.1.dev23/tests/data/plainfileparser/cyclic_definitions.plain +0 -10
  113. plain_parser-0.2.1.dev23/tests/data/plainfileparser/cyclic_definitions_across_import.plain +0 -14
  114. plain_parser-0.2.1.dev23/tests/data/plainfileparser/cyclic_definitions_long.plain +0 -12
  115. plain_parser-0.2.1.dev23/tests/data/plainfileparser/cyclic_definitions_sub_bullet.plain +0 -12
  116. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts.plain +0 -14
  117. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_base.plain +0 -2
  118. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_defaults_exported.plain +0 -14
  119. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_example.plain +0 -14
  120. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_imported_exported.plain +0 -13
  121. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_inherited_reexported.plain +0 -16
  122. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_malformed.plain +0 -14
  123. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_missing_definition.plain +0 -15
  124. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_missing_definition_example.plain +0 -14
  125. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_multiple_per_bullet.plain +0 -15
  126. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_multiple_per_bullet_undefined.plain +0 -14
  127. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_nested.plain +0 -16
  128. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_nested_example.plain +0 -14
  129. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_no_definitions.plain +0 -11
  130. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_not_declared.plain +0 -9
  131. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_not_declared_example.plain +0 -14
  132. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_transitive_example.plain +0 -14
  133. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_transitive_l1.plain +0 -14
  134. plain_parser-0.2.1.dev23/tests/data/plainfileparser/exported_concepts_transitive_l2.plain +0 -14
  135. plain_parser-0.2.1.dev23/tests/data/plainfileparser/func_id_duplicate.plain +0 -14
  136. plain_parser-0.2.1.dev23/tests/data/plainfileparser/func_id_invalid.plain +0 -11
  137. plain_parser-0.2.1.dev23/tests/data/plainfileparser/old_syntax_functional_specs.plain +0 -11
  138. plain_parser-0.2.1.dev23/tests/data/plainfileparser/plain_file_parser_with_comments.plain +0 -9
  139. plain_parser-0.2.1.dev23/tests/data/plainfileparser/plain_file_with_comments_indented.plain +0 -11
  140. plain_parser-0.2.1.dev23/tests/data/plainfileparser/regular_plain_source.plain +0 -12
  141. plain_parser-0.2.1.dev23/tests/data/plainfileparser/required_concepts.plain +0 -7
  142. plain_parser-0.2.1.dev23/tests/data/plainfileparser/required_concepts_defs.plain +0 -2
  143. plain_parser-0.2.1.dev23/tests/data/plainfileparser/required_concepts_example.plain +0 -14
  144. plain_parser-0.2.1.dev23/tests/data/plainfileparser/required_concepts_l1.plain +0 -7
  145. plain_parser-0.2.1.dev23/tests/data/plainfileparser/required_concepts_l2.plain +0 -5
  146. plain_parser-0.2.1.dev23/tests/data/plainfileparser/required_concepts_missing.plain +0 -11
  147. plain_parser-0.2.1.dev23/tests/data/plainfileparser/required_concepts_module.plain +0 -12
  148. plain_parser-0.2.1.dev23/tests/data/plainfileparser/required_concepts_partial.plain +0 -14
  149. plain_parser-0.2.1.dev23/tests/data/plainfileparser/required_concepts_partial_duplicate.plain +0 -15
  150. plain_parser-0.2.1.dev23/tests/data/plainfileparser/requires_without_definitions_example.plain +0 -11
  151. plain_parser-0.2.1.dev23/tests/data/plainfileparser/topological_sort.plain +0 -17
  152. plain_parser-0.2.1.dev23/tests/data/plainfileparser/topological_sort_not_referenced.plain +0 -26
  153. plain_parser-0.2.1.dev23/tests/data/requires/chain_base.plain +0 -8
  154. plain_parser-0.2.1.dev23/tests/data/requires/chain_fork_top.plain +0 -14
  155. plain_parser-0.2.1.dev23/tests/data/requires/chain_middle.plain +0 -13
  156. plain_parser-0.2.1.dev23/tests/data/requires/chain_top.plain +0 -13
  157. plain_parser-0.2.1.dev23/tests/data/requires/circular_requires_main.plain +0 -19
  158. plain_parser-0.2.1.dev23/tests/data/requires/circular_requires_sub.plain +0 -13
  159. plain_parser-0.2.1.dev23/tests/data/requires/diamond_requires_1.plain +0 -17
  160. plain_parser-0.2.1.dev23/tests/data/requires/diamond_requires_2.plain +0 -17
  161. plain_parser-0.2.1.dev23/tests/data/requires/diamond_requires_common.plain +0 -8
  162. plain_parser-0.2.1.dev23/tests/data/requires/diamond_requires_main.plain +0 -20
  163. plain_parser-0.2.1.dev23/tests/data/requires/independent_requires_1.plain +0 -12
  164. plain_parser-0.2.1.dev23/tests/data/requires/independent_requires_2.plain +0 -12
  165. plain_parser-0.2.1.dev23/tests/data/requires/independent_requires_main.plain +0 -20
  166. plain_parser-0.2.1.dev23/tests/data/requires/invalid_ancestor_base.plain +0 -8
  167. plain_parser-0.2.1.dev23/tests/data/requires/invalid_ancestor_top.plain +0 -13
  168. plain_parser-0.2.1.dev23/tests/data/requires/non_existent_require.plain +0 -19
  169. plain_parser-0.2.1.dev23/tests/data/requires/normal_requires_1.plain +0 -17
  170. plain_parser-0.2.1.dev23/tests/data/requires/normal_requires_2.plain +0 -17
  171. plain_parser-0.2.1.dev23/tests/data/requires/normal_requires_common.plain +0 -8
  172. plain_parser-0.2.1.dev23/tests/data/requires/normal_requires_main.plain +0 -20
  173. plain_parser-0.2.1.dev23/tests/data/requires/shared_export_above.plain +0 -13
  174. plain_parser-0.2.1.dev23/tests/data/requires/shared_export_base.plain +0 -17
  175. plain_parser-0.2.1.dev23/tests/data/requires/shared_export_middle.plain +0 -13
  176. plain_parser-0.2.1.dev23/tests/data/requires/shared_export_top.plain +0 -14
  177. plain_parser-0.2.1.dev23/tests/data/sample_base64_image.txt +0 -1
  178. plain_parser-0.2.1.dev23/tests/data/simple.plain +0 -8
  179. plain_parser-0.2.1.dev23/tests/data/templates/block_level_include.plain +0 -11
  180. plain_parser-0.2.1.dev23/tests/data/templates/code_variables.plain +0 -11
  181. plain_parser-0.2.1.dev23/tests/data/templates/header.plain +0 -7
  182. plain_parser-0.2.1.dev23/tests/data/templates/implement.plain +0 -3
  183. plain_parser-0.2.1.dev23/tests/data/templates/implement_2.plain +0 -3
  184. plain_parser-0.2.1.dev23/tests/data/templates/malformed_tag.plain +0 -5
  185. plain_parser-0.2.1.dev23/tests/data/templates/template_include.plain +0 -5
  186. plain_parser-0.2.1.dev23/tests/data/templates/test_hardest_problem.plain +0 -2
  187. plain_parser-0.2.1.dev23/tests/data/templates/unterminated_output.plain +0 -4
  188. plain_parser-0.2.1.dev23/tests/data/testplainfile/comment_only_conformance.plain +0 -10
  189. plain_parser-0.2.1.dev23/tests/data/testplainfile/content_before_scenario.plain +0 -13
  190. plain_parser-0.2.1.dev23/tests/data/testplainfile/content_before_section.plain +0 -10
  191. plain_parser-0.2.1.dev23/tests/data/testplainfile/duplicate_scenario_id.plain +0 -14
  192. plain_parser-0.2.1.dev23/tests/data/testplainfile/duplicate_section.plain +0 -13
  193. plain_parser-0.2.1.dev23/tests/data/testplainfile/empty_scenario.plain +0 -14
  194. plain_parser-0.2.1.dev23/tests/data/testplainfile/empty_sections.plain +0 -8
  195. plain_parser-0.2.1.dev23/tests/data/testplainfile/extra_frontmatter_key.plain +0 -9
  196. plain_parser-0.2.1.dev23/tests/data/testplainfile/invalid_scenario_id.plain +0 -11
  197. plain_parser-0.2.1.dev23/tests/data/testplainfile/link_to_plain_file.plain +0 -11
  198. plain_parser-0.2.1.dev23/tests/data/testplainfile/minimal.plain +0 -6
  199. plain_parser-0.2.1.dev23/tests/data/testplainfile/missing_acceptance_section.plain +0 -9
  200. plain_parser-0.2.1.dev23/tests/data/testplainfile/missing_func_id.plain +0 -7
  201. plain_parser-0.2.1.dev23/tests/data/testplainfile/missing_link.plain +0 -11
  202. plain_parser-0.2.1.dev23/tests/data/testplainfile/module_not_a_string.plain +0 -8
  203. plain_parser-0.2.1.dev23/tests/data/testplainfile/notes.md +0 -1
  204. plain_parser-0.2.1.dev23/tests/data/testplainfile/scenario_before_section.plain +0 -11
  205. plain_parser-0.2.1.dev23/tests/data/testplainfile/sections_out_of_order.plain +0 -11
  206. plain_parser-0.2.1.dev23/tests/data/testplainfile/unknown_section.plain +0 -11
  207. plain_parser-0.2.1.dev23/tests/data/testplainfile/valid.plain +0 -40
  208. plain_parser-0.2.1.dev23/tests/test_cli.py +0 -899
  209. plain_parser-0.2.1.dev23/tests/test_concept_utils.py +0 -179
  210. plain_parser-0.2.1.dev23/tests/test_exceptions.py +0 -21
  211. plain_parser-0.2.1.dev23/tests/test_graph.py +0 -130
  212. plain_parser-0.2.1.dev23/tests/test_imports.py +0 -61
  213. plain_parser-0.2.1.dev23/tests/test_loaders.py +0 -215
  214. plain_parser-0.2.1.dev23/tests/test_plainfileparser.py +0 -944
  215. plain_parser-0.2.1.dev23/tests/test_plainspec.py +0 -232
  216. plain_parser-0.2.1.dev23/tests/test_project.py +0 -311
  217. plain_parser-0.2.1.dev23/tests/test_requires.py +0 -370
  218. plain_parser-0.2.1.dev23/tests/test_test_plain_file.py +0 -283
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.5
2
+ Name: plain-parser
3
+ Version: 1.0.0.dev1
4
+ License-Expression: MIT
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: mistletoe<2,>=1.6.0
7
+ Requires-Dist: python-frontmatter<2,>=1.3.0
8
+ Requires-Dist: python-liquid2<0.5,>=0.4.0
9
+ Requires-Dist: pyyaml<7,>=6
10
+ Provides-Extra: dev
11
+ Requires-Dist: black==26.10.1; extra == 'dev'
12
+ Requires-Dist: flake8==7.5.0; extra == 'dev'
13
+ Requires-Dist: isort==9.0.2; extra == 'dev'
14
+ Requires-Dist: mypy==2.4.1; extra == 'dev'
15
+ Requires-Dist: pytest==9.2.0; extra == 'dev'
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.32,<2", "hatch-vcs>=0.5,<0.6"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "plain-parser"
7
+ dynamic = ["version"]
8
+ license = "MIT"
9
+ requires-python = ">=3.11"
10
+ dependencies = ["python-liquid2>=0.4.0,<0.5", "mistletoe>=1.6.0,<2", "python-frontmatter>=1.3.0,<2", "pyyaml>=6,<7"]
11
+
12
+ [project.scripts]
13
+ plain-parser = "plain_parser.cli:main"
14
+
15
+ [project.optional-dependencies]
16
+ dev = ["pytest==9.2.0", "flake8==7.5.0", "black==26.10.1", "isort==9.0.2", "mypy==2.4.1"]
17
+
18
+ [tool.hatch.version]
19
+ source = "vcs"
20
+
21
+ [tool.hatch.build.targets.wheel]
22
+ packages = ["src/plain_parser"]
23
+
24
+ [tool.black]
25
+ line-length = 120
26
+
27
+ [tool.isort]
28
+ profile = "black"
29
+ line_length = 120
30
+
31
+ [tool.pytest.ini_options]
32
+ testpaths = ["tests"]
@@ -0,0 +1,154 @@
1
+ # plain-parser error messages
2
+
3
+ Every error the parser raises, by error class, with its exact message text. Callers match on these texts, so they
4
+ are part of the contract. `{name}` marks a value filled in at run time. A message that spans lines here spans the
5
+ same lines in the error (`\n` separated). Where a message starts with `{where}`, `{where}` is built as follows:
6
+
7
+ - In a spec plain file: `Syntax error`, then ` at line {line}` when the line is known, then ` in module '{module}'`
8
+ when the module name is known. Example: `Syntax error at line 7 in module 'todo'`.
9
+ - In a test plain file: `Syntax error at line {line} in test plain file '{name}'`.
10
+
11
+ Line numbers count from 1 at the first line of the file, frontmatter included, after line endings are normalized.
12
+
13
+ ## Spec plain file structure (PlainSyntaxError)
14
+
15
+ - `Plain syntax error: Invalid frontmatter: {error}`
16
+ - `Plain syntax error: {where}: The `{heading}` section is not allowed in a spec plain file; test scenarios live in test plain files.`
17
+ (`{heading}` is `conformance tests` or `acceptance tests`)
18
+ - `Plain syntax error: {where}: A `# <func-id>` heading is allowed only in the functional specs section (`{text}`).`
19
+ - `Plain syntax error: {where}: Invalid heading level {level} (`{text}`). A functionality heading is `# <func-id>`.`
20
+ - `Plain syntax error: {where}: Invalid func-id (`{text}`). A func-id is lowercase letters and digits, with single hyphens between them.`
21
+ - `Plain syntax error: {where}: Duplicate func-id `{func_id}`; it is first used at line {line}.`
22
+ - `Plain syntax error: {where}: Invalid specification (`{text}`)`
23
+ - `Plain syntax error: {where}: Content before the first `# <func-id>` heading in the functional specs section (`{text}`). A functionality is a `# <func-id>` heading followed by its body; the previous syntax is not supported.`
24
+ - `Plain syntax error: {where}: Invalid specification heading (`{heading}`). Allowed headings: definitions, implementation reqs, test reqs, functional specs`
25
+ - `Plain syntax error: {where}: Duplicate specification heading (`{heading}`)`
26
+ - `Plain syntax error: {where}: Definitions specification must be the first specification in the section (`{text}`)`
27
+ - `Plain syntax error: {where}: Missing specification heading (`{text}`)`
28
+ - `Plain syntax error: {where}: Invalid source structure (`{text}`)`
29
+ - `Plain syntax error: {where}: Functionality `{func_id}` has no body.`
30
+ - `Plain syntax error: Invalid plain file extension: {suffix}. Expected: .plain.`
31
+
32
+ `{text}` is the raw text of the offending block, stripped.
33
+
34
+ ## Module shape (various classes)
35
+
36
+ - MissingFunctionalitiesError: `Module '{module}' does not have any functionality specified. At least one functionality is required for rendering.`
37
+ - PlainSyntaxError: `Plain syntax error: Module '{module}' has a 'functional specs' section without a `# <func-id>` heading. A functionality is a `# <func-id>` heading followed by its body; the previous syntax is not supported.`
38
+ - PlainSyntaxError: `Plain syntax error: Module '{module}' defines functionalities but specifies no implementation reqs. At least one implementation req is required.`
39
+ When the module has a `requires` list, this sentence follows: ` Implementation reqs are not inherited through 'requires' — add them to this module, or 'import' a module that provides them.`
40
+ - ModuleDoesNotExistError: `Module does not exist ({module}).`
41
+ - UnsupportedBase64Content: `Module '{module}' contains a base64-encoded blob ({length} characters) inlined in the specification. This is not supported. Remove the base64 data from the .plain file or if necessary, include the binary file path in the specification.`
42
+
43
+ ## Imports, requires, required and exported concepts
44
+
45
+ - PlainSyntaxError: `Plain syntax error: Circular import detected: {module}.`
46
+ - ImportedModuleWithFunctionalitiesError: `Module '{module}' is imported but contains functional specs. Imported modules may only provide definitions, implementation reqs, and test reqs — use 'requires' instead of 'import' if this module's functionalities should be built on.`
47
+ - PlainSyntaxError: `Plain syntax error: Invalid specification heading (`{heading}`). Allowed headings: definitions, implementation reqs, test reqs`
48
+ - PlainSyntaxError: `Plain syntax error: Circular required module detected: {module}.`
49
+ - PlainSyntaxError: `Plain syntax error: There must be a fixed order how required modules are dependent ({module}).`
50
+ - PlainSyntaxError: `Plain syntax error: Not all required concepts were defined. Missing required concepts: {concepts joined by ", "}.`
51
+ - PlainSyntaxError: `Plain syntax error: Invalid {directive} metadata. Expected a dictionary or a string.`
52
+ - AssertionError: `Syntax error: Invalid {directive} metadata. Expected a list.`
53
+ - AssertionError: `Syntax error: Invalid required_concepts metadata. Expected a string.`
54
+ - PlainSyntaxError: `Plain syntax error: {subject} exports an invalid concept (`{entry}`). Expected a concept token, e.g. :ConceptName:.`
55
+ - PlainSyntaxError: `Plain syntax error: {subject} cannot export default concept {concept}. Only user-defined concepts can be exported.`
56
+ - PlainSyntaxError: `Plain syntax error: {subject} exports undefined concept {concept}.`
57
+ When the module has a `requires` list, this sentence follows: ` An exported concept must be defined in this module's definitions or in an imported module; a concept inherited through requires cannot be re-exported.`
58
+
59
+ `{subject}` is `Module '{module}'`, or `Module` when the module name is not known. `{entry}` is the export entry as
60
+ normalized: `- ` followed by the entry.
61
+
62
+ ## Concepts
63
+
64
+ - `Plain syntax error: Found {count} errors in the plain file:\n{errors joined by \n}` (PlainSyntaxError), where each error is one of:
65
+ - `Syntax error: Invalid definition specification text: {text}. Should start with `- :<concept>:` (where <concept> is any string that does not contain `:`).`
66
+ - `Syntax error: Invalid concept: {candidate}. Should contain only letters, numbers, hyphens and dots.`
67
+ - `Syntax error: Concepts were defined multiple times: {concepts joined by ", "} .`
68
+ - `Syntax error: Concept {concept} is not defined in the definitions. {section}: {markdown}`
69
+ - Concept cycles (PlainSyntaxError), at most 10 cycles listed:
70
+ ```
71
+ Plain syntax error: Found {count} cycle(s) in concept definitions. Cycles are not allowed.
72
+
73
+ Cycle 1: {c1} -> {c2} -> {c1}
74
+ {definition markdown of each distinct definition on the cycle}
75
+
76
+ Cycle 2: ...
77
+ ```
78
+ When more than 10 cycles exist, the first line is replaced by the two lines
79
+ `Plain syntax error: Found more than 10 cycles in concept definitions. Cycles are not allowed.` and
80
+ `Showing the first 10.`
81
+
82
+ ## Linked resources
83
+
84
+ - PlainSyntaxError: `Plain syntax error: Only relative links are allowed{where} (text: {text}, target: {target}).`
85
+ - PlainSyntaxError: `Plain syntax error: Link {target}{where} does not exist. Linked resources are looked up relative to the following directories (highest to lowest precedence):\n 1. {dir1}\n 2. {dir2}`
86
+ - PlainSyntaxError: `Plain syntax error: Link {target}{where} must be a file (resolved to {resolved_path}).`
87
+ - PlainSyntaxError: `Plain syntax error: Link{where} must have text specified (link: {target}).`
88
+ - PlainSyntaxError: `Referenced resource '{target}'{where} is a .plain file. Referencing .plain files through Linked Resources is not supported. Please use the import section to include definitions or implementation/test requirements from another module.`
89
+ - UnsupportedResourceType: `Referenced resource '{target}' in module '{module}' is a binary file. Only text files (e.g. .md, .txt, .json, .yaml) can be referenced from a .plain file.`
90
+ - FileNotFoundError: `Resource file '{target}' referenced in module '{module}' not found.`
91
+ - UnsupportedBase64Content: `Referenced resource '{target}' in module '{module}' contains a large base64-encoded blob ({length} characters), such as an embedded image. Inline base64 data is not supported. Remove the data from the resource. If the data should be used by the end software, save the data to a separate file and include the file path in the specification without it being a reference file.`
92
+ - Exception: `The file {target} is linked to multiple linked resources with the same text: {text}`
93
+ - Exception: `The linked resource {text} is linked to multiple files: {other_target}`
94
+ - Exception: `Duplicate linked resource found: {text} ({target})`
95
+
96
+ `{where}` is empty in a spec plain file and ` in test plain file '{name}', scenario `{scenario_id}`` in a scenario.
97
+
98
+ ## Liquid
99
+
100
+ - PlainSyntaxError: `Plain syntax error: Invalid Liquid{position}: {liquid message}`, where `{position}` is
101
+ ` at {template}:{line}:{column}` when both are known, ` at {line}:{column}` when only the position is known,
102
+ ` in {template}` when only the template name is known, and empty otherwise. `{column}` counts from 0.
103
+ - Exception: `Undefined liquid variable: {liquid message}`
104
+ - TemplateNotFoundError (liquid2): `Template not found: {liquid message naming the template}`
105
+ - Exception: `Invalid use of code_variable filter!`
106
+ - Exception: `Invalid use of prohibited_chars filter!`
107
+ - InvalidLiquidVariableName: `'{char}' is not a valid character for variable '{variable}' (value: '{value}').`
108
+ - Exception: `Code variable {name} has multiple values: {first value} and {second value}`
109
+
110
+ ## Func-id navigation
111
+
112
+ - Exception: `Functionality {frid} does not exist.`
113
+ - ValueError: `plain_source_tree must be a dictionary.`
114
+ - ValueError: `frid {frid} does not exist.`
115
+ - InvalidFridArgument: `Invalid start functionality ID: {start}. Valid IDs are: {python list of func-ids}.`
116
+ - InvalidFridArgument: `Invalid end functionality ID: {end}. Valid IDs are: {python list of func-ids}.`
117
+ - InvalidFridArgument: `Start functionality ID: {start} must be before end functionality ID: {end}.`
118
+
119
+ ## Test plain files (PlainSyntaxError)
120
+
121
+ - `Plain syntax error: Test plain file '{name}' has invalid frontmatter: {error}`
122
+ - `Plain syntax error: Test plain file '{name}' has no `{key}:` key in its frontmatter.`
123
+ - `Plain syntax error: Test plain file '{name}': the frontmatter key `{key}:` must be a non-empty string.`
124
+ - `Plain syntax error: Test plain file '{name}' has the frontmatter key `{key}:`; only `module:` and `func_id:` are allowed.`
125
+ - `Plain syntax error: {where}: Invalid section (`{line}`). A test plain file has the sections `***conformance tests***` and `***acceptance tests***`, in this order.`
126
+ - `Plain syntax error: {where}: Duplicate section `***{heading}***`.`
127
+ - `Plain syntax error: {where}: The `***{heading}***` section must come after `***conformance tests***`.`
128
+ - `Plain syntax error: {where}: Scenario `{scenario_id}` comes before the first section; a test plain file starts with `***conformance tests***`.`
129
+ - `Plain syntax error: {where}: Invalid scenario-id (`{scenario_id}`). A scenario-id is lowercase letters and digits, with single hyphens between them.`
130
+ - `Plain syntax error: {where}: Duplicate scenario-id `{scenario_id}`; it is first used at line {line}.`
131
+ - `Plain syntax error: {where}: Content before the first section (`{line}`); a test plain file starts with `***conformance tests***`.`
132
+ - `Plain syntax error: {where}: Content before the first `# <scenario-id>` heading in the `{section}` section (`{line}`).`
133
+ - `Plain syntax error: {where}: Scenario `{scenario_id}` has a code fence that is not closed.` (`{where}` names the scenario's heading line)
134
+ - `Plain syntax error: {where}: Scenario `{scenario_id}` has no text.` (`{where}` names the scenario's heading line)
135
+ - `Plain syntax error: Test plain file '{name}' has no `***{heading}***` section.`
136
+ - Concept error line (one per concept, in a list): `{where}: Concept {concept} used in scenario `{scenario_id}` is not defined in module '{module}'.` (`{where}` names the scenario's heading line)
137
+
138
+ ## Binding test plain files to functionalities
139
+
140
+ - PlainSyntaxError: `Plain syntax error: File '{name}' under a tests folder is not a text file.`
141
+ - UnsupportedBase64Content: `Test plain file '{name}' contains a base64-encoded blob ({length} characters) inlined in the scenarios. This is not supported. Remove the base64 data from the file.`
142
+ - PlainSyntaxError: `Plain syntax error: File '{name}' under a tests folder has invalid frontmatter: {error}`
143
+ - PlainSyntaxError: `Plain syntax error: File '{name}' is under a tests folder but is not a test plain file: its frontmatter needs the keys `module:` and `func_id:`.`
144
+ - PlainSyntaxError: `Plain syntax error: Test plain file '{name}' binds to functionality '{module}:{func_id}', which module '{module}' does not have.`
145
+ - PlainSyntaxError: `Plain syntax error: Found {count} errors in test plain file '{name}':\n{concept error lines joined by \n}`
146
+ - PlainSyntaxError: `Plain syntax error: Syntax error at line {line} in test plain file '{name}': Duplicate scenario-id `{scenario_id}` for functionality '{module}:{func_id}'; it is first used at line {first_line} in test plain file '{first_name}'.`
147
+ - MissingTestPlainFileError: `Functionality {module}:{func_id} has no test plain file. Add one, by convention tests/{module}/{func_id}.plain, with the add-test-scenarios skill.`
148
+
149
+ ## Command line
150
+
151
+ - Usage error (argparse, exit 2): `Config file '{config_name}' was found in two locations:\n - Plain file directory: {dir}\n - Current working directory: {cwd}\nRemove the config file from one of these locations to resolve the ambiguity.`
152
+ - Usage error (argparse, exit 2): `Error reading config file: {error}`
153
+ - Usage error (argparse, exit 2): `conformance-tests-script is set in the config file, but no tests folder is given. Pass --tests-folder or set tests-folder in the config file.`
154
+ - `parse` encoding failure: `The parse result holds text that is not valid UTF-8: {offending output line, stripped, trailing comma removed, non-ASCII as backslash escapes}`
@@ -0,0 +1,199 @@
1
+ # plain-parser public Python API
2
+
3
+ Package `plain_parser` (import name), distribution `plain-parser`, console script `plain-parser = plain_parser.cli:main`.
4
+ Every name below is public: callers import it, so names, parameters, defaults and return shapes are fixed.
5
+
6
+ ## `plain_parser` (package `__init__`)
7
+
8
+ Re-exports, listed in `__all__` in this order:
9
+
10
+ ```
11
+ PlainFileParseResult, concept_utils, exceptions, get_filename_from_module_name, get_module_name_from_filename,
12
+ loaders, marshall_plain_source, parse_module_chain, parse_plain_file, parse_plain_source, plain_file,
13
+ plain_file_parser, plain_spec, project, test_plain_file
14
+ ```
15
+
16
+ The submodules `concept_utils`, `exceptions`, `loaders`, `plain_file`, `plain_spec`, `project`, `test_plain_file`
17
+ are importable as attributes of the package. The submodules `graph`, `liquid_nodes` and `cli` exist too.
18
+
19
+ ## `plain_parser.exceptions`
20
+
21
+ Each class derives directly from `Exception` and adds nothing:
22
+
23
+ ```
24
+ PlainSyntaxError, UnsupportedBase64Content, UnsupportedResourceType, InvalidFridArgument,
25
+ InvalidLiquidVariableName, ModuleDoesNotExistError, MissingFunctionalitiesError,
26
+ ImportedModuleWithFunctionalitiesError, MissingTestPlainFileError
27
+ ```
28
+
29
+ ## `plain_parser.graph`
30
+
31
+ ```
32
+ strongly_connected_components(graph: Mapping[Node, Iterable[Node]]) -> list[set[Node]]
33
+ simple_cycles(graph: Mapping[Node, Iterable[Node]], limit: int | None = None) -> Iterator[list[Node]]
34
+ ```
35
+
36
+ ## `plain_parser.plain_spec`
37
+
38
+ Constants:
39
+
40
+ ```
41
+ DEFINITIONS = "definitions"
42
+ NON_FUNCTIONAL_REQUIREMENTS = "implementation reqs"
43
+ TEST_REQUIREMENTS = "test reqs"
44
+ FUNCTIONAL_REQUIREMENTS = "functional specs"
45
+ CONFORMANCE_TESTS = "conformance_tests"
46
+ ACCEPTANCE_TESTS = "acceptance_tests"
47
+ CONFORMANCE_TEST_HEADING = "conformance tests"
48
+ ACCEPTANCE_TEST_HEADING = "acceptance tests"
49
+ LIST_SECTION_HEADINGS = [DEFINITIONS, NON_FUNCTIONAL_REQUIREMENTS, TEST_REQUIREMENTS]
50
+ ALLOWED_SPECIFICATION_HEADINGS = [*LIST_SECTION_HEADINGS, FUNCTIONAL_REQUIREMENTS]
51
+ ALLOWED_IMPORT_SPECIFICATION_HEADINGS = LIST_SECTION_HEADINGS
52
+ SEMANTIC_ID_PATTERN (compiled regular expression [a-z0-9]+(?:-[a-z0-9]+)*)
53
+ ```
54
+
55
+ `InvalidFridArgument` and `InvalidLiquidVariableName` are importable from `plain_spec` as well.
56
+
57
+ Functions:
58
+
59
+ ```
60
+ is_semantic_id(text: str) -> bool
61
+ has_acceptance_tests(plain_source_tree) -> bool
62
+ collect_specification_linked_resources(specification, specification_heading, linked_resources_list) -> None
63
+ collect_linked_resources(plain_source_tree, linked_resources_list, specifications_list, include_test_scenarios, frid=None) -> bool
64
+ get_frids(plain_source_tree) -> Iterator[str] (a generator)
65
+ get_first_frid(plain_source_tree) -> str | None
66
+ get_next_frid(plain_source_tree, frid) -> str | None
67
+ get_previous_frid(plain_source_tree, frid) -> str | None
68
+ get_frids_before(plain_source_tree, target_frid: str) -> list[str]
69
+ get_specification_item_markdown(specification_item, code_variables, replace_code_variables, key="markdown") -> str
70
+ get_specifications_for_frid(plain_source_tree, frid, replace_code_variables=True) -> tuple[dict, dict | None]
71
+ code_variable_liquid_filter(value, *, context) (a liquid2 filter taking the render context)
72
+ prohibited_chars_liquid_filter(value, prohibited_chars, *, context) (a liquid2 filter taking the render context)
73
+ hash_text(text: str) -> str
74
+ get_hash_value(specifications) -> str
75
+ get_frids_range(plain_source, start, end=None) -> list[str]
76
+ ```
77
+
78
+ ## `plain_parser.loaders`
79
+
80
+ ```
81
+ MAX_BASE64_BLOB_LENGTH = 8192
82
+ find_large_base64_blob(text: str) -> str | None
83
+ open_from(dirs, file_name) -> str | None
84
+ find_resource_dir(dirs, file_name) -> str | None
85
+ resolve_linked_resource(dirs, file_name) -> str | None
86
+ relative_resource_path(base_dir: str, resource_dir: str, target: str) -> str
87
+ load_linked_resources(template_dirs: list[str], resources_list, module_name: str) -> dict[str, str]
88
+ liquid_error_message(error: LiquidSyntaxError) -> str
89
+ get_loaded_templates(source_path, plain_source, template_name=None) -> tuple[str, dict[str, str]]
90
+ TrackingFileSystemLoader (liquid2 file system loader that records every loaded template source by name)
91
+ ```
92
+
93
+ ## `plain_parser.liquid_nodes`
94
+
95
+ ```
96
+ Plain2CodeIncludeNode, Plain2CodeIncludeTag, Plain2CodeLoaderMixin
97
+ ```
98
+
99
+ ## `plain_parser.concept_utils`
100
+
101
+ ```
102
+ DEFAULT_CONCEPTS: set[str]
103
+ MAX_REPORTED_CYCLES = 10
104
+ extract_concepts_from_definition(text: str) -> tuple[list[str], list[str]] (concepts, errors)
105
+ extract_concepts_from_spec_text(text: str) -> list[str]
106
+ collect_concepts(plain_source) -> tuple[list[str] | set[str], list[str]] (concepts, errors)
107
+ validate_concepts_in_spec(spec: dict, concepts: set[str], spec_group: str) -> list[str]
108
+ validate_concepts_in_spec_group(spec_group, plain_source, concepts: set[str]) -> list[str]
109
+ validate_concepts(marshalled_plain_source) -> list[str]
110
+ find_concept_definitions_in_plain_source(concept: str, plain_source: dict, renderer) -> list[token]
111
+ build_adjacency_list(definitions) -> tuple[dict, dict]
112
+ format_cycles_error(adjacency_list, concept_definitions) -> str
113
+ sort_definitions(definitions: list[dict]) -> None (sorts the list in place)
114
+ ```
115
+
116
+ ## `plain_parser.plain_file`
117
+
118
+ ```
119
+ RESOURCE_MARKER = "[resource]"
120
+ IMPORT_DIRECTIVE = "import"
121
+ REQUIRES_DIRECTIVE = "requires"
122
+ REQUIRED_CONCEPTS_DIRECTIVE = "required_concepts"
123
+ EXPORTED_CONCEPTS_DIRECTIVE = "exported_concepts"
124
+ PLAIN_SOURCE_FILE_EXTENSION = ".plain"
125
+
126
+ @dataclass PlainFileParseResult(plain_source: dict, plain_source_obj: frontmatter.Post,
127
+ required_modules: list[str], required_concepts: list[str])
128
+
129
+ get_filename_from_module_name(module_name: str) -> str
130
+ get_module_name_from_filename(filename: str) -> str
131
+ normalize_line_endings(plain_source_text: str) -> str
132
+ restore_stripped_lines(plain_source_text: str, content: str) -> str
133
+ find_linked_resources(tokens, template_dirs, where: str = "") -> list[dict]
134
+ process_section_code_variables(section, code_variables, text_key="markdown") -> None
135
+ render_plain_source(plain_source, loaded_templates, code_variables) -> str
136
+ marshall_plain_source(input_plain_source) -> dict
137
+ parse_plain_source(plain_source_text: str, code_variables: dict, template_dirs: list[str],
138
+ imported_modules: list[str], modules_trace: list[str], module_name: str | None = None)
139
+ -> PlainFileParseResult
140
+ parse_plain_file(module_name: str, code_variables: dict, template_dirs: list[str],
141
+ imported_modules: list[str], modules_trace: list[str]) -> PlainFileParseResult
142
+ plain_file_parser(plain_source_file_name: str, template_dirs: list[str]) -> tuple[str, dict, list[str]]
143
+ (module name, plain source tree, the module's own requires list)
144
+ parse_module_chain(plain_file_name: str, template_dirs: list[str]) -> list[tuple[str, dict]]
145
+ ```
146
+
147
+ ## `plain_parser.test_plain_file`
148
+
149
+ ```
150
+ MODULE_KEY = "module"
151
+ FUNC_ID_KEY = "func_id"
152
+
153
+ @dataclass Scenario(id: str, line_number: int, text: str = "", linked_resources: list[dict] = [],
154
+ code_variables: list[dict] = [])
155
+ to_dict() -> dict {"id", "text", "linked_resources"} plus "code_variables" when not empty
156
+ @dataclass TestPlainFile(name: str, module: str, func_id: str,
157
+ conformance_tests: list[Scenario], acceptance_tests: list[Scenario])
158
+ scenarios -> list[Scenario] (property: conformance then acceptance)
159
+
160
+ is_test_plain_file(metadata: dict) -> bool
161
+ parse_test_plain_file_source(plain_source_text: str, name: str, template_dirs: list[str], code_variables: dict)
162
+ -> TestPlainFile
163
+ validate_scenario_concepts(test_plain_file: TestPlainFile, concepts: set[str]) -> list[str]
164
+ ```
165
+
166
+ ## `plain_parser.project`
167
+
168
+ ```
169
+ @dataclass BoundTestPlainFile(path: str, name: str, parsed: TestPlainFile)
170
+ @dataclass ProjectParseResult(chain: list[tuple[str, dict]], test_plain_files: list[BoundTestPlainFile])
171
+
172
+ discover_test_plain_files(tests_folders: list[str], entry_dir: str) -> list[tuple[str, str]]
173
+ bind_test_plain_files(chain, tests_folders, template_dirs, entry_dir) -> list[BoundTestPlainFile]
174
+ check_test_plain_files(chain, bound) -> None
175
+ parse_project(plain_file_name: str, template_dirs: list[str], tests_folders: list[str],
176
+ require_test_plain_files: bool) -> ProjectParseResult
177
+ ```
178
+
179
+ ## `plain_parser.cli`
180
+
181
+ ```
182
+ DEFAULT_CONFIG_NAME = "config.yaml"
183
+ PARSE_FORMAT_VERSION = 2
184
+ AmbiguousConfigFileError(Exception)
185
+ @dataclass Config(template_dir: str | None = None, tests_folders: list[str] | None = None,
186
+ conformance_tests_enabled: bool = False)
187
+ @dataclass ParseResult(modules: list[tuple[str, dict]], resources: dict[str, str], test_plain_files: dict[str, dict] = {})
188
+
189
+ build_parser() -> argparse.ArgumentParser
190
+ resolve_config_file(config_name: str, plain_file_path: str) -> str | None
191
+ read_config(config_file: str) -> Config
192
+ parse_spec(plain_file_path: str, template_dir: str | None, load_resources: bool,
193
+ tests_folders: list[str] | None = None, require_test_plain_files: bool = False) -> ParseResult
194
+ check(plain_file_path: str, template_dir: str | None, tests_folders: list[str] | None = None,
195
+ require_test_plain_files: bool = False) -> None
196
+ parse(plain_file_path: str, template_dir: str | None, tests_folders: list[str] | None = None,
197
+ require_test_plain_files: bool = False) -> int
198
+ main(argv: list[str] | None = None) -> int
199
+ ```
@@ -1,7 +1,7 @@
1
- """Parser for ***plain specification files."""
1
+ """plain-parser."""
2
2
 
3
- from plain_parser import concept_utils, exceptions, loaders, plain_file, plain_spec, project, test_plain_file
4
- from plain_parser.plain_file import (
3
+ from . import concept_utils, exceptions, loaders, plain_file, plain_spec, project, test_plain_file
4
+ from .plain_file import (
5
5
  PlainFileParseResult,
6
6
  get_filename_from_module_name,
7
7
  get_module_name_from_filename,
@@ -0,0 +1,246 @@
1
+ """Command line of plain-parser."""
2
+
3
+ import argparse
4
+ import json
5
+ import os
6
+ import sys
7
+ from dataclasses import dataclass, field
8
+ from typing import Any
9
+
10
+ import yaml
11
+
12
+ from . import loaders, plain_spec, project
13
+
14
+ DEFAULT_CONFIG_NAME = "config.yaml"
15
+ PARSE_FORMAT_VERSION = 2
16
+
17
+
18
+ class AmbiguousConfigFileError(Exception):
19
+ pass
20
+
21
+
22
+ class ConfigReadError(Exception):
23
+ pass
24
+
25
+
26
+ @dataclass
27
+ class Config:
28
+ template_dir: str | None = None
29
+ tests_folders: list[str] | None = None
30
+ conformance_tests_enabled: bool = False
31
+
32
+
33
+ @dataclass
34
+ class ParseResult:
35
+ modules: list[tuple[str, dict]]
36
+ resources: dict[str, str]
37
+ test_plain_files: dict[str, dict] = field(default_factory=dict)
38
+
39
+
40
+ def build_parser() -> argparse.ArgumentParser:
41
+ parser = argparse.ArgumentParser(prog="plain-parser")
42
+ sub = parser.add_subparsers(dest="command", required=True)
43
+ for name in ("check", "parse"):
44
+ p = sub.add_parser(name)
45
+ p.add_argument("filename")
46
+ p.add_argument("--template-dir", dest="template_dir", metavar="DIR", default=None)
47
+ p.add_argument("--tests-folder", dest="tests_folder", metavar="DIR", action="append", default=None)
48
+ p.add_argument("--config-name", dest="config_name", metavar="NAME", default=DEFAULT_CONFIG_NAME)
49
+ return parser
50
+
51
+
52
+ def resolve_config_file(config_name: str, plain_file_path: str) -> str | None:
53
+ candidates = []
54
+ for base in (os.path.dirname(os.path.abspath(plain_file_path)), os.getcwd()):
55
+ path = os.path.join(base, config_name)
56
+ if os.path.isfile(path) and path not in candidates:
57
+ candidates.append(path)
58
+ if len(candidates) > 1:
59
+ dirs = " and ".join(os.path.dirname(c) for c in candidates)
60
+ raise AmbiguousConfigFileError(f"Config file {config_name} found in two locations: {dirs}")
61
+ return candidates[0] if candidates else None
62
+
63
+
64
+ def _key(data: dict, name: str) -> Any:
65
+ for k in (name, name.replace("-", "_")):
66
+ if data.get(k):
67
+ return data[k]
68
+ return None
69
+
70
+
71
+ def read_config(config_file: str) -> Config:
72
+ try:
73
+ with open(config_file, encoding="utf-8") as f:
74
+ data: Any = yaml.safe_load(f) or {}
75
+ if not isinstance(data, dict):
76
+ raise ValueError("config file is not a mapping")
77
+ except (OSError, UnicodeDecodeError, ValueError, yaml.YAMLError) as e:
78
+ raise ConfigReadError(f"Error reading config file: {e}") from e
79
+ base = os.path.dirname(os.path.abspath(config_file))
80
+
81
+ def rel(p: str) -> str:
82
+ p = os.path.expanduser(str(p))
83
+ return p if os.path.isabs(p) else os.path.join(base, p)
84
+
85
+ folders = _key(data, "tests-folder")
86
+ if isinstance(folders, str):
87
+ folders = [folders]
88
+ template_dir = _key(data, "template-dir")
89
+ return Config(
90
+ template_dir=rel(template_dir) if template_dir else None,
91
+ tests_folders=[rel(p) for p in folders if p] if folders else None,
92
+ conformance_tests_enabled=bool(_key(data, "conformance-tests-script")),
93
+ )
94
+
95
+
96
+ def parse_spec(
97
+ plain_file_path: str,
98
+ template_dir: str | None,
99
+ load_resources: bool,
100
+ tests_folders: list[str] | None = None,
101
+ require_test_plain_files: bool = False,
102
+ ) -> ParseResult:
103
+ entry_dir = os.path.dirname(os.path.abspath(plain_file_path))
104
+ dirs = [entry_dir]
105
+ if template_dir:
106
+ dirs.append(os.path.abspath(template_dir))
107
+ result = project.parse_project(os.path.basename(plain_file_path), dirs, tests_folders or [], require_test_plain_files)
108
+ resources: dict[str, str] = {}
109
+ for name, tree in result.chain:
110
+ registry: list[dict] = []
111
+ plain_spec.collect_linked_resources(tree, registry, None, True)
112
+ if load_resources:
113
+ loaders.load_linked_resources(dirs, registry, name)
114
+ for link in registry:
115
+ target = link["target"]
116
+ if target in resources:
117
+ continue
118
+ found = loaders.find_resource_dir(dirs, target)
119
+ if found is not None:
120
+ resources[target] = loaders.relative_resource_path(entry_dir, found, target)
121
+ entry_tree = result.chain[-1][1]
122
+ for frid in plain_spec.get_frids(entry_tree):
123
+ plain_spec.get_specifications_for_frid(entry_tree, frid)
124
+ bound = {b.name: {"module": b.parsed.module, "func_id": b.parsed.func_id} for b in result.test_plain_files}
125
+ return ParseResult(result.chain, resources, bound)
126
+
127
+
128
+ def check(
129
+ plain_file_path: str,
130
+ template_dir: str | None,
131
+ tests_folders: list[str] | None = None,
132
+ require_test_plain_files: bool = False,
133
+ ) -> None:
134
+ parse_spec(plain_file_path, template_dir, True, tests_folders, require_test_plain_files)
135
+
136
+
137
+ def _error_document(error: BaseException, message: str | None = None) -> dict:
138
+ return {
139
+ "format_version": PARSE_FORMAT_VERSION,
140
+ "type": type(error).__name__,
141
+ "message": str(error) if message is None else message,
142
+ }
143
+
144
+
145
+ def render_parse_output(
146
+ plain_file_path: str,
147
+ template_dir: str | None,
148
+ tests_folders: list[str] | None = None,
149
+ require_test_plain_files: bool = False,
150
+ ) -> tuple[bytes, int]:
151
+ """Return the UTF-8 bytes of the parse JSON document and the exit code."""
152
+ try:
153
+ res = parse_spec(plain_file_path, template_dir, False, tests_folders, require_test_plain_files)
154
+ doc: dict = {
155
+ "format_version": PARSE_FORMAT_VERSION,
156
+ "modules": [{"module": n, "tree": t} for n, t in res.modules],
157
+ "resources": res.resources,
158
+ "test_plain_files": res.test_plain_files,
159
+ }
160
+ code = 0
161
+ except Exception as e:
162
+ doc, code = _error_document(e), 1
163
+ try:
164
+ text = json.dumps(doc, indent=2, ensure_ascii=False) + "\n"
165
+ except Exception as e:
166
+ doc, code = _error_document(e), 1
167
+ text = json.dumps(doc, indent=2, ensure_ascii=False) + "\n"
168
+ try:
169
+ return text.encode("utf-8"), code
170
+ except UnicodeEncodeError as e:
171
+ if code == 0:
172
+ for line in text.split("\n"):
173
+ try:
174
+ line.encode("utf-8")
175
+ except UnicodeEncodeError:
176
+ bad = line.strip().removesuffix(",").encode("utf-8", "backslashreplace").decode("ascii")
177
+ break
178
+ err = UnicodeEncodeError(e.encoding, e.object, e.start, e.end, e.reason)
179
+ msg = f"The parse result holds text that is not valid UTF-8: {bad}"
180
+ doc, code = _error_document(err, msg), 1
181
+ text = json.dumps(doc, indent=2, ensure_ascii=False) + "\n"
182
+ return text.encode("utf-8", "backslashreplace"), code
183
+
184
+
185
+ def parse(
186
+ plain_file_path: str,
187
+ template_dir: str | None,
188
+ tests_folders: list[str] | None = None,
189
+ require_test_plain_files: bool = False,
190
+ ) -> int:
191
+ data, code = render_parse_output(plain_file_path, template_dir, tests_folders, require_test_plain_files)
192
+ try:
193
+ buffer = getattr(sys.stdout, "buffer", None)
194
+ if buffer is not None:
195
+ sys.stdout.flush()
196
+ buffer.write(data)
197
+ buffer.flush()
198
+ else:
199
+ sys.stdout.write(data.decode("utf-8"))
200
+ sys.stdout.flush()
201
+ except BrokenPipeError:
202
+ try:
203
+ devnull = os.open(os.devnull, os.O_WRONLY)
204
+ os.dup2(devnull, sys.stdout.fileno())
205
+ except (OSError, ValueError):
206
+ pass
207
+ return code
208
+
209
+
210
+ def main(argv: list[str] | None = None) -> int:
211
+ parser = build_parser()
212
+ args = parser.parse_args(argv)
213
+ try:
214
+ config_file = resolve_config_file(args.config_name, args.filename)
215
+ cfg = read_config(config_file) if config_file else Config()
216
+ except (AmbiguousConfigFileError, ConfigReadError) as e:
217
+ parser.error(str(e))
218
+ except KeyboardInterrupt:
219
+ return 130
220
+ template_dir = cfg.template_dir
221
+ folders = cfg.tests_folders
222
+ if args.template_dir:
223
+ template_dir = os.path.abspath(os.path.expanduser(args.template_dir))
224
+ if args.tests_folder:
225
+ folders = [os.path.abspath(os.path.expanduser(p)) for p in args.tests_folder]
226
+ require = cfg.conformance_tests_enabled
227
+ if require and not folders:
228
+ parser.error(
229
+ "conformance-tests-script is set in the config file, but no tests folder is given. "
230
+ "Pass --tests-folder or set tests-folder in the config file."
231
+ )
232
+ try:
233
+ if args.command == "check":
234
+ parse_spec(args.filename, template_dir, True, folders, require)
235
+ print(f"{args.filename}: OK")
236
+ return 0
237
+ return parse(args.filename, template_dir, folders, require)
238
+ except KeyboardInterrupt:
239
+ return 130
240
+ except Exception as e:
241
+ print(f"Error: {e}", file=sys.stderr)
242
+ return 1
243
+
244
+
245
+ if __name__ == "__main__":
246
+ sys.exit(main())