Fix module resolution for relative subdirectory paths#237
Open
pedjaradenkovic wants to merge 1 commit into
Open
Fix module resolution for relative subdirectory paths#237pedjaradenkovic wants to merge 1 commit into
pedjaradenkovic wants to merge 1 commit into
Conversation
The top module is opened via template_dirs[0] (the file's own directory), so its module_name must be the bare stem. bc6563b kept the relative subdirectory prefix, which double-joined with template_dirs[0] and made 'python plain2code.py sub/dir/foo.plain' fail with 'Module does not exist'. Add a regression test replicating the CLI's path decomposition.
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
Running the CLI with a relative path that contains a subdirectory fails:
Absolute paths and bare filenames work; only relative subdirectory paths break. This is a regression on
main.Root cause
The top module is opened via
open_from(template_dirs, module_name + ".plain"), andget_template_directoriesalways setstemplate_dirs[0] = dirname(filename). Somodule_namemust be the bare stem.bc6563b("prevent stripping module subdirectory") changed the derivation to keep the relative subdirectory prefix for non-absolute paths:For a relative invocation this double-joins with
template_dirs[0]:template_dirs[0]=examples/example_hello_world_pythonmodule_name=examples/example_hello_world_python/hello_world_pythonexamples/example_hello_world_python/examples/example_hello_world_python/hello_world_python.plain→ not foundSince sibling
import/requiresmodules must resolve relative totemplate_dirs[0], keeping a subdir inmodule_nameis fundamentally incompatible with that design. Reverting to always-stemis the correct fix.Fix
plain_file.py:module_name = plain_source_file_path.stem(always).tests/test_plainfileparser.py:test_relative_subdirectory_path_resolvesreplicates the CLI's path decomposition (full relative path + its dir astemplate_dirs[0]). Verified it fails on the old code and passes on the fix.Verification
requiresconfirmed working end-to-end: top module in a subfolder with a siblingrequires, andrequires: [nested/leaf]in a deeper subfolder. Negative control (requires: [nested/DOES_NOT_EXIST]) errors on exactly that path, proving nested resolution is active.Behavior note
Top-module build/conformance folders are keyed by the stem again (e.g.
build/main) — the pre-bc6563bbehavior. This reverts the subdir-nested build path introduced bybc6563b(which had no test and broke the primary CLI path).