Fix autoimport.sqlite deriving module names from non-package folders#848
Open
deepakganesh78 wants to merge 1 commit into
Open
Fix autoimport.sqlite deriving module names from non-package folders#848deepakganesh78 wants to merge 1 commit into
deepakganesh78 wants to merge 1 commit into
Conversation
…ython-rope#823) `AutoImport._resource_to_module` computed a module's name via `get_modname_from_path(resource_path, project_package.path)`, i.e. the resource's path relative to the project root. This blindly joins every intermediate directory name, so a module under a non-package folder such as `<root>/shared/src/shared/documents.py` was reported as `shared.src.shared.documents` instead of the correct `shared.documents`. The pickle backend does not have this problem because it derives the name with `libutils.modname`, which walks up the package hierarchy and stops at the first directory without an `__init__.py`. Use the same helper in the sqlite backend so both backends agree and intermediate non-package folders are excluded from the module name. Fixes python-rope#823
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 #823
Root cause
AutoImport._resource_to_moduleinrope/contrib/autoimport/sqlite.pyderived a module's name from its path relative to the project root:get_modname_from_pathsimply joins every intermediate directory name, so it includes folders that are not Python packages. For a layout likewhere
shared/(top) andsrc/are not packages, the sqlite backend reported the module asshared.src.shared.documentsinstead of the correctshared.documents.The pickle backend does not have this bug because it uses
libutils.modname, which walks up the package hierarchy from the resource and stops at the first directory without an__init__.py.Fix
Use
libutils.modname(resource)in the sqlite backend's_resource_to_module, matching the pickle backend so both agree and intermediate non-package folders are excluded. The now-unusedget_modname_from_pathimport is removed.Tests
Added
test_resource_to_module_skips_non_package_folderswhich builds asrc/mypkg/documents.pystructure (wheresrc/is not a package) and asserts the derived modname ismypkg.documents. It fails onmaster(src.mypkg.documents) and passes with this change.Full suite: 2092 passed, 8 skipped, 5 xfailed in a per-repo venv.