Fix module resolution for subdirectory paths (top and required modules)#237
Open
pedjaradenkovic wants to merge 1 commit into
Open
Fix module resolution for subdirectory paths (top and required modules)#237pedjaradenkovic wants to merge 1 commit into
pedjaradenkovic wants to merge 1 commit into
Conversation
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.
92cb325 to
7722cea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two related failures when a
.plainmodule lives in / references a subdirectory:requiresa module in a subdirectory (requires: [dir_name/b]), rendered from outside its folder, fails when thePlainModuletree is built:Root cause
get_template_directoriesalways foldsdirname(filename)intotemplate_dirs[0]. But the full top-module filename was still passed toplain_file_parser, so the directory was counted twice when opening the file (open_fromjoinstemplate_dirs[0]+ the module name).dir_name/b.plain), so they must keep their subdirectory prefix to resolve.template_dirs).An earlier attempt fixed only the top module by forcing the bare stem — but that stripped the subdirectory from required modules too, breaking case 2.
Fix
plain2code.py: normalize the top module toos.path.basename(args.filename)at the call sites (its directory is already intemplate_dirs). This is the frame the parser expects.plain_file.py:plain_file_parserpreserves the relative subdirectory prefix inmodule_name(sodir_name/bresolves and is retained in build/conformance paths); absolute paths fall back to the stem.With this, both the top module and required modules in subdirectories resolve correctly, and required-module subdirectory structure is preserved under the build folder (
build/dir_name/b).Tests
tests/test_plainfileparser.py(fixtures intests/data/requires_subdir/):test_parser_keeps_subdirectory_in_module_name— parser keepsnested/leaffor a template-relative name.test_requires_module_in_subdirectory_resolves— builds the fullPlainModuletree with a required subdirectory module (the path that broke) and asserts module names + build folder (build/nested/leaf).Verification
requires: [dir_name/b]from outside the folder now builds the module tree and reaches the API instead of failing at "Module does not exist".