Skip to content

Commit 7722cea

Browse files
Resolve modules in subdirectories via caller-side basename
The top module's directory is already folded into template_dirs by get_template_directories, so passing the full filename to plain_file_parser double-counted the directory (relative subdirectory paths failed with 'Module does not exist'). Normalize the top module to its basename at the call sites in plain2code.py; plain_file_parser keeps preserving relative subdirectory prefixes so required/imported modules (e.g. 'dir_name/b') resolve. Add PlainModule-tree and parser-level regression tests.
1 parent 1cef5fb commit 7722cea

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

plain2code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def main(): # noqa: C901
355355
# Parse the plain file (and its required modules) once; reused by dry-run and rendering.
356356
try:
357357
plain_module = plain_modules.PlainModule(
358-
args.filename,
358+
os.path.basename(args.filename),
359359
args.build_folder,
360360
args.conformance_tests_folder,
361361
template_dirs,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
requires:
3+
- nested/leaf
4+
---
5+
6+
***implementation reqs***
7+
8+
- Main implementation requirement.
9+
10+
***functional specs***
11+
12+
- Display "hello, world"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
***implementation reqs***
2+
3+
- Base implementation requirement for the leaf.
4+
5+
***functional specs***
6+
7+
- A base functionality from the leaf.

tests/test_plainfileparser.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@ def test_regular_plain_source(get_test_data_path):
2727
}
2828

2929

30+
def test_parser_keeps_subdirectory_in_module_name(get_test_data_path):
31+
# A template-relative filename with a subdirectory (as passed for required/imported modules)
32+
# must keep its subdirectory prefix in the module name so it resolves under template_dirs.
33+
data_dir = get_test_data_path("data/requires_subdir")
34+
35+
module_name, _, required = plain_file.plain_file_parser("nested/leaf.plain", [data_dir])
36+
37+
assert module_name == "nested/leaf"
38+
assert required == []
39+
40+
41+
def test_requires_module_in_subdirectory_resolves(get_test_data_path):
42+
# Regression: rendering a top module (referenced by basename, its dir supplied via
43+
# template_dirs) that `requires` a module in a subdirectory must build the full PlainModule
44+
# tree without a "Module does not exist" error, preserving the subdirectory in build paths.
45+
import plain_modules
46+
47+
data_dir = get_test_data_path("data/requires_subdir")
48+
49+
module = plain_modules.PlainModule("main_in_subdir.plain", "build", "conformance", [data_dir])
50+
51+
assert module.module_name == "main_in_subdir"
52+
assert [m.module_name for m in module.required_modules] == ["nested/leaf"]
53+
assert [m.module_build_folder for m in module.required_modules] == [os.path.join("build", "nested/leaf")]
54+
55+
3056
def test_unknown_section():
3157
plain_source = """
3258
***definitions***

0 commit comments

Comments
 (0)