codeplain 0.3.11.dev13__py3-none-any.whl → 0.3.11.dev14__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codeplain
3
- Version: 0.3.11.dev13
3
+ Version: 0.3.11.dev14
4
4
  Summary: Transform plain language specifications into working code
5
5
  License-File: LICENSE
6
6
  Classifier: Environment :: Console
@@ -23,7 +23,7 @@ plain2code_read_config.py,sha256=D5CxnmTRjddupecWvstcUm0kIJWWzq5-Zmk6sU0wbIg,223
23
23
  plain2code_state.py,sha256=uePQlC29Pbhm1yXfdCFebONYdy6jo13gTTmXSwC11cQ,3168
24
24
  plain2code_telemetry.py,sha256=e4UCAoFklJMDWGQsL50i7nTLiOBy8gs86A0XO4WLgPo,4597
25
25
  plain2code_utils.py,sha256=unOxuqSQRpwG8YF6uoQhnZ3ZSTJRIUCPLdJ-1lRZR5M,1534
26
- plain_file.py,sha256=Kn8m_w6c04_RR-FBjAU05UcLOTDk4zcctpJXghYdZ8I,35757
26
+ plain_file.py,sha256=c7VFzJUXLM3oBFrA9JePDwdxXTR1T8hxWeyGZg4O4wA,36968
27
27
  plain_modules.py,sha256=nXlmw0J2rKkuU1Y3A68LVtZ1Ffdc-D5iMjxaXSaSHTQ,25963
28
28
  plain_spec.py,sha256=7nb5lLJKHZ3uu9THkSXyJ5brIKkbGW0ooVfRclLdlzA,16062
29
29
  system_config.py,sha256=sA8wiPmBMtRsLwSQ40U5pVdLazAafbV-1Z19Yp0HiSQ,5314
@@ -93,7 +93,7 @@ tests/test_plain2code_state.py,sha256=cowPZS9oRbv9J49CE4P3Rc47Q5oQOby4bTf2OlnRlB
93
93
  tests/test_plain2code_utils.py,sha256=-W8a7FquMJQ_pTdBoBF1XprzNL2G555QhdtXCy6BDyQ,1237
94
94
  tests/test_plain_modules.py,sha256=Fn3FeH-M4exnyFJDZzc9YWaLEfBmiqPH5TpiBT9jgAs,33033
95
95
  tests/test_plainfile.py,sha256=wZ_PN4GULPWIpl_AK_r_6jkgtX0Ch8EHmN5IhX7huOE,11027
96
- tests/test_plainfileparser.py,sha256=l8GfXkVaSzgH74fX45Wp5jX0q3QlO6t_TgDG72dc28o,23867
96
+ tests/test_plainfileparser.py,sha256=lFUnOEOOBOTvmB6b-VQgRRDiM2Ojein7lUzGdsT9pdk,24874
97
97
  tests/test_plainspec.py,sha256=ng55E8ajrH2-gPC1p_QDIe_zXplPvoqHJ-d57UWKFTw,3577
98
98
  tests/test_prepare_repositories_layout.py,sha256=PhJQLnHfjfjo6CTWoicyEKgL0_GtjwB2OKYAWSBVHtk,14638
99
99
  tests/test_requires.py,sha256=6tnHYaKudxN-RiQjSFoi9nHe_x0ze3QF-f-j67zAE74,1250
@@ -116,8 +116,8 @@ tui/spinner.py,sha256=Ro6Gd9Przf-whuHqPRY6HwI0T57yJjyNPbhDbigZKZE,2471
116
116
  tui/state_handlers.py,sha256=zbUS_D9eU8qIwVpaxPEp9zL9bpg8gXsWNoUaqg9TLrQ,16664
117
117
  tui/styles.css,sha256=kiC7Og_2G1E7owoiZgV95-3_dSeQnsNj3qzaY04xkDg,6727
118
118
  tui/widget_helpers.py,sha256=jitm2WHiKj-NVFL-hULxWzckPreRbUTl9OIZLN31-ek,6997
119
- codeplain-0.3.11.dev13.dist-info/METADATA,sha256=KVfLUeUZa4B9EB2D8iLyUz7RqGDLrDGSNrGCDwp1MIE,7257
120
- codeplain-0.3.11.dev13.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
121
- codeplain-0.3.11.dev13.dist-info/entry_points.txt,sha256=oDZkBqu9WhtZApb_K6ia8-fn9aojwmAsgnKELceX5T4,46
122
- codeplain-0.3.11.dev13.dist-info/licenses/LICENSE,sha256=pCeKgQ1mXE5OmNUuKOfOZh1T1vqkeCUxghE7N8qgnzc,11345
123
- codeplain-0.3.11.dev13.dist-info/RECORD,,
119
+ codeplain-0.3.11.dev14.dist-info/METADATA,sha256=cDHh3AdeuhUTdXAIyBUSa8uztsFrV-9kUrKEt-08SqA,7257
120
+ codeplain-0.3.11.dev14.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
121
+ codeplain-0.3.11.dev14.dist-info/entry_points.txt,sha256=oDZkBqu9WhtZApb_K6ia8-fn9aojwmAsgnKELceX5T4,46
122
+ codeplain-0.3.11.dev14.dist-info/licenses/LICENSE,sha256=pCeKgQ1mXE5OmNUuKOfOZh1T1vqkeCUxghE7N8qgnzc,11345
123
+ codeplain-0.3.11.dev14.dist-info/RECORD,,
plain_file.py CHANGED
@@ -615,15 +615,45 @@ def parse_plain_source( # noqa: C901
615
615
  f"Plain syntax error: Syntax error at line {nested_acceptance_test_heading.line_number}: {plain_spec.ACCEPTANCE_TEST_HEADING} heading should be nested under specific functional spec."
616
616
  )
617
617
 
618
+ defined_concepts = set[str]()
618
619
  if plain_source[plain_spec.DEFINITIONS] is not None:
619
620
  with PlainRenderer() as renderer:
620
621
  for token in plain_source[plain_spec.DEFINITIONS].children:
621
622
  rendered_token = renderer.render(token)
622
623
  new_concepts, _ = concept_utils.extract_concepts_from_definition(rendered_token)
624
+ defined_concepts.update(new_concepts)
623
625
  for concept in new_concepts:
624
626
  if concept in required_concepts:
625
627
  required_concepts.remove(concept)
626
628
 
629
+ if EXPORTED_CONCEPTS_DIRECTIVE in plain_source_obj.metadata:
630
+ module_name = modules_trace[-1] if modules_trace else None
631
+ subject = f"Module '{module_name}'" if module_name else "Module"
632
+
633
+ for entry in plain_source_obj.metadata[EXPORTED_CONCEPTS_DIRECTIVE]:
634
+ exported_concepts, errors = concept_utils.extract_concepts_from_definition(entry)
635
+ if errors:
636
+ raise PlainSyntaxError(
637
+ f"Plain syntax error: {subject} exports an invalid concept (`{entry}`). "
638
+ f"Expected a concept token, e.g. :ConceptName:."
639
+ )
640
+
641
+ for exported_concept in exported_concepts:
642
+ if exported_concept in concept_utils.DEFAULT_CONCEPTS:
643
+ raise PlainSyntaxError(
644
+ f"Plain syntax error: {subject} cannot export default concept {exported_concept}. "
645
+ f"Only user-defined concepts can be exported."
646
+ )
647
+
648
+ if exported_concept not in defined_concepts:
649
+ message = f"Plain syntax error: {subject} exports undefined concept {exported_concept}."
650
+ if REQUIRES_DIRECTIVE in plain_source_obj.metadata:
651
+ message += (
652
+ " An exported concept must be defined in this module's definitions or in an "
653
+ "imported module; a concept inherited through requires cannot be re-exported."
654
+ )
655
+ raise PlainSyntaxError(message)
656
+
627
657
  required_modules = []
628
658
  if REQUIRES_DIRECTIVE in plain_source_obj.metadata:
629
659
  required_modules = plain_source_obj.metadata[REQUIRES_DIRECTIVE]
@@ -710,15 +740,7 @@ def process_required_modules(
710
740
  if EXPORTED_CONCEPTS_DIRECTIVE in plain_file_parse_result.plain_source_obj.metadata:
711
741
  exported_concepts = list[str]()
712
742
  for concept in plain_file_parse_result.plain_source_obj.metadata[EXPORTED_CONCEPTS_DIRECTIVE]:
713
- if concept in concept_utils.DEFAULT_CONCEPTS:
714
- raise PlainSyntaxError(
715
- f"Plain syntax error: Default concept cannot be exported: {concept}. Only user-defined concepts can be exported."
716
- )
717
-
718
- if isinstance(concept, str):
719
- exported_concepts.extend(concept_utils.extract_concepts_from_definition(concept)[0])
720
- else:
721
- raise PlainSyntaxError(f"Plain syntax error: Invalid exported concept: {concept}.")
743
+ exported_concepts.extend(concept_utils.extract_concepts_from_definition(concept)[0])
722
744
 
723
745
  with PlainRenderer() as renderer:
724
746
  for exported_concept in exported_concepts:
@@ -632,6 +632,11 @@ def test_concept_validation_acceptance_tests(get_test_data_path):
632
632
  )
633
633
 
634
634
 
635
+ def test_concept_validation_cyclic_definitions(get_test_data_path):
636
+ with pytest.raises(PlainSyntaxError, match="cycles in the concept graph"):
637
+ plain_file.plain_file_parser("cyclic_definitions.plain", [get_test_data_path("data/plainfileparser")])
638
+
639
+
635
640
  def test_required_concepts(get_test_data_path):
636
641
  plain_file.plain_file_parser(
637
642
  "required_concepts_example.plain",
@@ -661,28 +666,36 @@ def test_required_concepts(get_test_data_path):
661
666
  )
662
667
 
663
668
 
664
- def test_exported_concepts(get_test_data_path):
665
- plain_file.plain_file_parser(
669
+ @pytest.mark.parametrize(
670
+ "fixture",
671
+ [
666
672
  "exported_concepts_example.plain",
667
- [get_test_data_path("data/plainfileparser")],
668
- )
669
-
670
- plain_file.plain_file_parser(
673
+ "exported_concepts_imported_exported.plain",
674
+ "exported_concepts_multiple_per_bullet.plain",
671
675
  "exported_concepts_nested_example.plain",
672
- [get_test_data_path("data/plainfileparser")],
673
- )
674
-
675
- with pytest.raises(PlainSyntaxError):
676
- plain_file.plain_file_parser(
677
- "exported_concepts_missing_example.plain",
678
- [get_test_data_path("data/plainfileparser")],
679
- )
680
-
681
- with pytest.raises(PlainSyntaxError):
682
- plain_file.plain_file_parser(
683
- "exported_concepts_transitive_example.plain",
684
- [get_test_data_path("data/plainfileparser")],
685
- )
676
+ ],
677
+ )
678
+ def test_exported_concepts_valid(get_test_data_path, fixture):
679
+ plain_file.plain_file_parser(fixture, [get_test_data_path("data/plainfileparser")])
680
+
681
+
682
+ @pytest.mark.parametrize(
683
+ ("fixture", "expected_word"),
684
+ [
685
+ ("exported_concepts_defaults_exported.plain", "cannot export default concept"),
686
+ ("exported_concepts_inherited_reexported.plain", "cannot be re-exported"),
687
+ ("exported_concepts_malformed.plain", "exports an invalid concept"),
688
+ ("exported_concepts_missing_definition_example.plain", "'exported_concepts_missing_definition' exports"),
689
+ ("exported_concepts_missing_definition.plain", "exports undefined concept"),
690
+ ("exported_concepts_multiple_per_bullet_undefined.plain", "exports undefined concept"),
691
+ ("exported_concepts_no_definitions.plain", "exports undefined concept"),
692
+ ("exported_concepts_not_declared_example.plain", "not defined"),
693
+ ("exported_concepts_transitive_example.plain", "not defined"),
694
+ ],
695
+ )
696
+ def test_exported_concepts_invalid(get_test_data_path, fixture, expected_word):
697
+ with pytest.raises(PlainSyntaxError, match=expected_word):
698
+ plain_file.plain_file_parser(fixture, [get_test_data_path("data/plainfileparser")])
686
699
 
687
700
 
688
701
  def test_topological_sort(get_test_data_path):