Commit b72f892b authored by Mikhail Golubev's avatar Mikhail Golubev
Browse files

PY-31961 Canonicalize both paths when checking that a module is not under site-packages

We started to resolve symlinks for resolved Python modules to combat the cases
when there is an additional lib64/ entry in prefix pointing to lib/ directory.
Unfortunately, it now breaks detection of stdlib modules when the whole SDK
directory is symlinked somewhere else. It becomes especially noticeable for
interpreters created with pyenv installed via brew on Mac OS, since there PYENV_ROOT
directory is linked and actually reside under /usr/local/Cellar/.
As a net result, something like /usr/local/Cellar/pyenv/1.2.7/versions/3.6.4/lib/python3.6/re.py
(canonicalized) is not found under /usr/local/opt/pyenv/versions/3.6.4/lib/python3.6/.
parent cb4b88c0
Showing with 10 additions and 4 deletions
+10 -4
......@@ -708,12 +708,18 @@ public final class PythonSdkType extends SdkType {
final VirtualFile resolved = ObjectUtils.notNull(vFile.getCanonicalFile(), vFile);
if (pythonSdk != null) {
final VirtualFile libDir = PyProjectScopeBuilder.findLibDir(pythonSdk);
if (libDir != null && VfsUtilCore.isAncestor(libDir, resolved, false)) {
return isNotSitePackages(resolved, libDir);
if (libDir != null) {
final VirtualFile resolvedLibDir = ObjectUtils.notNull(libDir.getCanonicalFile(), libDir);
if (VfsUtilCore.isAncestor(resolvedLibDir, resolved, false)) {
return isNotSitePackages(resolved, resolvedLibDir);
}
}
final VirtualFile venvLibDir = PyProjectScopeBuilder.findVirtualEnvLibDir(pythonSdk);
if (venvLibDir != null && VfsUtilCore.isAncestor(venvLibDir, resolved, false)) {
return isNotSitePackages(resolved, venvLibDir);
if (venvLibDir != null) {
final VirtualFile resolvedVenvLibDir = ObjectUtils.notNull(venvLibDir.getCanonicalFile(), venvLibDir);
if (VfsUtilCore.isAncestor(resolvedVenvLibDir, resolved, false)) {
return isNotSitePackages(resolved, resolvedVenvLibDir);
}
}
final VirtualFile skeletonsDir = PySdkUtil.findSkeletonsDir(pythonSdk);
if (skeletonsDir != null &&
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment