PY-17241 Don't include packages in excluded project venv directory in setup.py

It happened because interpreter paths inside excluded virtualenv directory
are not considered excluded themselves. Now we stop going deeper into the
project structure once we've found a directory that is not a valid traditional
style package (unless it's a root).
This commit is contained in:
Mikhail Golubev
2018-11-19 11:28:30 +03:00
parent 1a9d66091f
commit 7d04c08f3e
9 changed files with 22 additions and 1 deletions
@@ -312,10 +312,14 @@ public class PyPackageUtil {
VfsUtilCore.visitChildrenRecursively(root, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (file.equals(root)) {
return true;
}
if (!fileIndex.isExcluded(file) && file.isDirectory() && file.findChild(PyNames.INIT_DOT_PY) != null) {
results.add(VfsUtilCore.getRelativePath(file, root, '.'));
return true;
}
return true;
return false;
}
});
}
@@ -18,6 +18,7 @@ package com.jetbrains.python.packaging;
import com.google.common.collect.ImmutableMap;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.vfs.VirtualFile;
import com.jetbrains.python.fixtures.PyTestCase;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.psi.PyCallExpression;
@@ -264,4 +265,20 @@ public class PyPackageUtilTest extends PyTestCase {
assertEquals(text, argument.getText());
}
}
// PY-17241
public void testCollectingPackageNamesIgnoresExcludedDirectoriesWithSdkRoots() {
addExcludedRoot("env");
final VirtualFile sdkRoot = myFixture.findFileInTempDir("env/site-packages");
runWithAdditionalClassEntryInSdkRoots(sdkRoot, () -> {
final List<String> collected = PyPackageUtil.getPackageNames(myFixture.getModule());
assertSameElements(collected, "project", "project.pkg");
});
}
// PY-17241
public void testCollectingPackageNamesIgnoresChildrenOfDirectoriesWithoutInitPy() {
final List<String> collected = PyPackageUtil.getPackageNames(myFixture.getModule());
assertSameElements(collected, "project", "project.pkg");
}
}