fix: stop masking utils import errors in page_index_md - #498
Open
L4XB wants to merge 1 commit into
Open
Conversation
The relative-import fallback used a bare `except:`, so when utils failed to import for a real reason (missing dependency, syntax error) the module retried `from utils import *`, which in an installed package fails with "No module named 'utils'" and hides the original error. Decide the import style by `__package__` instead: package imports use the relative form and surface their own errors, script mode still resolves the sibling module. Fixes VectifyAI#486
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.
Fixes #486
pageindex/page_index_md.pyguarded its relative import with a bareexcept:. Whenutilsfailed to import for a real reason (missing dependency, syntax error), the fallbackfrom utils import *ran instead and, in an installed package, died withModuleNotFoundError: No module named 'utils', hiding the original traceback.Change: choose the import form by
__package__: inside the package the relative import runs on its own and surfaces its own errors; when the file is executed as a script (no parent package) the siblingutilsmodule is imported as before. No behaviour change for the normalimport pageindex.page_index_mdpath.Tests (
tests/test_page_index_md.py): the script-mode fallback still resolvesutils(run in a subprocess from thepageindex/directory), and the module no longer contains a bareexcept:.