diff --git a/plugins/org.python.pydev/src/org/python/pydev/ui/wizards/project/NewProjectNameAndLocationWizardPage.java b/plugins/org.python.pydev/src/org/python/pydev/ui/wizards/project/NewProjectNameAndLocationWizardPage.java index 46c8e0575..45daac464 100644 --- a/plugins/org.python.pydev/src/org/python/pydev/ui/wizards/project/NewProjectNameAndLocationWizardPage.java +++ b/plugins/org.python.pydev/src/org/python/pydev/ui/wizards/project/NewProjectNameAndLocationWizardPage.java @@ -44,6 +44,7 @@ import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.dialogs.WorkingSetConfigurationBlock; import org.python.pydev.core.IPythonNature; +import org.python.pydev.editor.codecompletion.revisited.PythonPathHelper; import org.python.pydev.plugin.PyStructureConfigHelpers; import org.python.pydev.plugin.PydevPlugin; import org.python.pydev.plugin.preferences.PydevPrefs; @@ -703,7 +704,7 @@ protected boolean validatePage() { File[] listFiles = locPath.toFile().listFiles(); boolean foundInit = false; for (File file : listFiles) { - if (file.getName().equals("__init__.py")) { + if (PythonPathHelper.isValidInitFile(file.getName())) { foundInit = true; setMessage("Project location contains an __init__.py file. Consider using the location's parent folder instead."); break; @@ -732,7 +733,7 @@ private boolean hasPyFile(File file) { return false; } else { - return file.getName().endsWith(".py"); + return PythonPathHelper.isValidSourceFile(file.getName()); } } diff --git a/plugins/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/PythonPathHelper.java b/plugins/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/PythonPathHelper.java index 8abfb03d8..c9860b0ba 100644 --- a/plugins/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/PythonPathHelper.java +++ b/plugins/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/PythonPathHelper.java @@ -187,7 +187,6 @@ protected static ModulesFoundStructure.ZipContents getFromZip(File root, IProgre * @return if the path passed belongs to a valid python source file (checks for the extension) */ public static boolean isValidSourceFile(String path) { - path = path.toLowerCase(); for (String end : FileTypesPreferencesPage.getDottedValidSourceFiles()) { if (path.endsWith(end)) { return true; @@ -422,8 +421,16 @@ public boolean accept(File dir, String name) { * @param item the file we want to check * @return true if the file is a valid __init__ file */ - public static boolean isValidInitFile(String item) { - return item.toLowerCase().indexOf("__init__.") != -1 && isValidSourceFile(item); + public static boolean isValidInitFile(String path) { + for (String end : FileTypesPreferencesPage.getDottedValidSourceFiles()) { + if (path.endsWith(end)) { + if (path.lastIndexOf("__init__") == path.length() - 8 - end.length()) { + return true; + } + } + } + + return false; } /** @@ -549,7 +556,8 @@ public void loadFromFile(File pythonpatHelperFile) throws IOException { * @param pythonpatHelperFile */ public void saveToFile(File pythonpatHelperFile) { - FileUtils.writeStrToFile(org.python.pydev.shared_core.string.StringUtils.join("\n", this.pythonpath), pythonpatHelperFile); + FileUtils.writeStrToFile(org.python.pydev.shared_core.string.StringUtils.join("\n", this.pythonpath), + pythonpatHelperFile); } public static boolean canAddAstInfoFor(ModulesKey key) { diff --git a/plugins/org.python.pydev/tests_completions/org/python/pydev/editor/codecompletion/revisited/PythonPathHelperTest.java b/plugins/org.python.pydev/tests_completions/org/python/pydev/editor/codecompletion/revisited/PythonPathHelperTest.java index c20877ede..16d939a48 100644 --- a/plugins/org.python.pydev/tests_completions/org/python/pydev/editor/codecompletion/revisited/PythonPathHelperTest.java +++ b/plugins/org.python.pydev/tests_completions/org/python/pydev/editor/codecompletion/revisited/PythonPathHelperTest.java @@ -55,6 +55,7 @@ public static void main(String[] args) { /** * @see junit.framework.TestCase#setUp() */ + @Override public void setUp() throws Exception { super.setUp(); CompiledModule.COMPILED_MODULES_ENABLED = false; @@ -64,6 +65,7 @@ public void setUp() throws Exception { /** * @see junit.framework.TestCase#tearDown() */ + @Override public void tearDown() throws Exception { CompiledModule.COMPILED_MODULES_ENABLED = true; super.tearDown(); @@ -125,7 +127,7 @@ public void testModuleCompletion() { private IToken[] getComps(Document doc, ICompletionState state) { try { - return ((ICodeCompletionASTManager) nature.getAstManager()).getCompletionsForToken(doc, state); + return nature.getAstManager().getCompletionsForToken(doc, state); } catch (CompletionRecursionException e) { throw new RuntimeException(e); } @@ -141,7 +143,7 @@ public void testRecursionModuleCompletion() throws CompletionRecursionException IToken[] comps = null; Document doc = new Document(sDoc); ICompletionState state = new CompletionState(line, col, token, nature, ""); - ICodeCompletionASTManager a = (ICodeCompletionASTManager) nature.getAstManager(); + ICodeCompletionASTManager a = nature.getAstManager(); comps = a.getCompletionsForToken(doc, state); assertFalse(comps.length == 0); @@ -157,7 +159,7 @@ public void testRecursion2() throws CompletionRecursionException { IToken[] comps = null; Document doc = new Document(sDoc); ICompletionState state = new CompletionState(line, col, token, nature, ""); - ICodeCompletionASTManager a = (ICodeCompletionASTManager) nature.getAstManager(); + ICodeCompletionASTManager a = nature.getAstManager(); comps = a.getCompletionsForToken(doc, state); assertEquals(0, comps.length); @@ -368,4 +370,14 @@ public void testGetEncoding() { String encoding = FileUtils.getPythonFileEncoding(new File(loc)); assertEquals("UTF-8", encoding); } + + public void testValidInitFile() throws Exception { + assertTrue(PythonPathHelper.isValidInitFile("a/__init__.py")); + assertTrue(PythonPathHelper.isValidInitFile("a/__init__/a/__init__.py")); + + assertFalse(PythonPathHelper.isValidInitFile("a/__init__.bar.py")); + assertFalse(PythonPathHelper.isValidInitFile("a/__init__..py")); + assertFalse(PythonPathHelper.isValidInitFile("a/__init__/a/.py")); + assertFalse(PythonPathHelper.isValidInitFile("a/__init__/a/__init__ .py")); + } }