From e57ceea8f418d9217a4d33bbff907ad37171761b Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Dec 2012 16:29:53 +0100 Subject: [PATCH 1/5] don't delete space between . and 'import' (PY-8112) --- .../python/formatter/PythonFormattingModelBuilder.java | 1 + python/testData/formatter/spaceAfterRelativeImport.py | 1 + python/testData/formatter/spaceAfterRelativeImport_after.py | 1 + python/testSrc/com/jetbrains/python/PyFormatterTest.java | 4 ++++ 4 files changed, 7 insertions(+) create mode 100644 python/testData/formatter/spaceAfterRelativeImport.py create mode 100644 python/testData/formatter/spaceAfterRelativeImport_after.py diff --git a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java index 28b16126f316..46317138c123 100644 --- a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java +++ b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java @@ -80,6 +80,7 @@ public class PythonFormattingModelBuilder implements FormattingModelBuilderEx, C .after(COMMA).spaceIf(commonSettings.SPACE_AFTER_COMMA) .before(COMMA).spaceIf(commonSettings.SPACE_BEFORE_COMMA) .between(FROM_KEYWORD, DOT).spaces(1) + .between(DOT, IMPORT_KEYWORD).spaces(1) .around(DOT).spaces(0) .before(SEMICOLON).spaceIf(commonSettings.SPACE_BEFORE_SEMICOLON) .withinPairInside(LPAR, RPAR, ARGUMENT_LIST).spaceIf(commonSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES) diff --git a/python/testData/formatter/spaceAfterRelativeImport.py b/python/testData/formatter/spaceAfterRelativeImport.py new file mode 100644 index 000000000000..d163a992484b --- /dev/null +++ b/python/testData/formatter/spaceAfterRelativeImport.py @@ -0,0 +1 @@ +from . import x diff --git a/python/testData/formatter/spaceAfterRelativeImport_after.py b/python/testData/formatter/spaceAfterRelativeImport_after.py new file mode 100644 index 000000000000..d163a992484b --- /dev/null +++ b/python/testData/formatter/spaceAfterRelativeImport_after.py @@ -0,0 +1 @@ +from . import x diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index fde733c7a86c..45c004149522 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -191,6 +191,10 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + public void testSpaceAfterRelativeImport() { // PY-8112 + doTest(); + } + public void testPsiFormatting() { // IDEA-69724 String initial = "def method_name(\n" + From dbe5942f26bcdc75ca56d200b99ba11f6d084e8e Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Dec 2012 16:36:40 +0100 Subject: [PATCH 2/5] take "space within braces" setting from correct place (PY-8069) --- .../formatter/PyLanguageCodeStyleSettingsProvider.java | 2 +- .../python/formatter/PythonFormattingModelBuilder.java | 2 +- python/testData/formatter/spaceWithinBraces.py | 1 + python/testData/formatter/spaceWithinBraces_after.py | 1 + python/testSrc/com/jetbrains/python/PyFormatterTest.java | 7 +++++++ 5 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 python/testData/formatter/spaceWithinBraces.py create mode 100644 python/testData/formatter/spaceWithinBraces_after.py diff --git a/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java b/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java index c3a54389a0c8..c8fb8f513e11 100644 --- a/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java +++ b/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java @@ -55,7 +55,7 @@ public class PyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettin SPACES_AROUND_OPERATORS); consumer.showCustomOption(PyCodeStyleSettings.class, "SPACE_AROUND_EQ_IN_KEYWORD_ARGUMENT", "Around = in keyword argument", SPACES_AROUND_OPERATORS); - consumer.showCustomOption(PyCodeStyleSettings.class, "SPACE_WITHIN_BRACES", "Within braces", SPACES_WITHIN); + consumer.showCustomOption(PyCodeStyleSettings.class, "SPACE_WITHIN_BRACES", "Braces", SPACES_WITHIN); consumer.showCustomOption(PyCodeStyleSettings.class, "SPACE_BEFORE_PY_COLON", ApplicationBundle.message("checkbox.spaces.before.colon"), SPACES_OTHER); consumer.showCustomOption(PyCodeStyleSettings.class, "SPACE_AFTER_PY_COLON", ApplicationBundle.message("checkbox.spaces.after.colon"), SPACES_OTHER); } diff --git a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java index 46317138c123..38f6d0078142 100644 --- a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java +++ b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java @@ -86,7 +86,7 @@ public class PythonFormattingModelBuilder implements FormattingModelBuilderEx, C .withinPairInside(LPAR, RPAR, ARGUMENT_LIST).spaceIf(commonSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES) .before(LBRACKET).spaceIf(pySettings.SPACE_BEFORE_LBRACKET) - .withinPair(LBRACE, RBRACE).spaceIf(commonSettings.SPACE_WITHIN_BRACES) + .withinPair(LBRACE, RBRACE).spaceIf(pySettings.SPACE_WITHIN_BRACES) .withinPair(LBRACKET, RBRACKET).spaceIf(commonSettings.SPACE_WITHIN_BRACKETS) .before(ARGUMENT_LIST).spaceIf(commonSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES) diff --git a/python/testData/formatter/spaceWithinBraces.py b/python/testData/formatter/spaceWithinBraces.py new file mode 100644 index 000000000000..45cb2f731835 --- /dev/null +++ b/python/testData/formatter/spaceWithinBraces.py @@ -0,0 +1 @@ +dict = {1: 'a', 2: 'b', 3: 'c'} \ No newline at end of file diff --git a/python/testData/formatter/spaceWithinBraces_after.py b/python/testData/formatter/spaceWithinBraces_after.py new file mode 100644 index 000000000000..a24625b0e6af --- /dev/null +++ b/python/testData/formatter/spaceWithinBraces_after.py @@ -0,0 +1 @@ +dict = { 1: 'a', 2: 'b', 3: 'c' } \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index 45c004149522..f21f5bdf8200 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -7,6 +7,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.jetbrains.python.fixtures.PyTestCase; +import com.jetbrains.python.formatter.PyCodeStyleSettings; import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.psi.PyElementGenerator; import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher; @@ -195,6 +196,12 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + public void testSpaceWithinBraces() { // PY-8069 + settings().getCustomSettings(PyCodeStyleSettings.class).SPACE_WITHIN_BRACES = true; + doTest(); + + } + public void testPsiFormatting() { // IDEA-69724 String initial = "def method_name(\n" + From ff9b2b7aa4d1ee6a2c05d403dad4295febf170c6 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Dec 2012 16:44:01 +0100 Subject: [PATCH 3/5] don't indent closing paren of tuple (PY-7946) --- python/src/com/jetbrains/python/formatter/PyBlock.java | 10 +++++++--- python/testData/formatter/tupleClosingParen.py | 4 ++++ python/testData/formatter/tupleClosingParen_after.py | 4 ++++ .../intentions/afterConvertTripleQuotedString.py | 2 +- .../testSrc/com/jetbrains/python/PyFormatterTest.java | 3 +++ 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 python/testData/formatter/tupleClosingParen.py create mode 100644 python/testData/formatter/tupleClosingParen_after.py diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 4f4d951213f1..ee10b37bd509 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -192,9 +192,13 @@ public class PyBlock implements ASTBlock { childIndent = Indent.getNormalIndent(); } } - else if ((parentType == PyElementTypes.PARENTHESIZED_EXPRESSION || parentType == PyElementTypes.GENERATOR_EXPRESSION) && - hasLineBreaksBefore(child, 1)) { - childIndent = Indent.getNormalIndent(); + else if ((parentType == PyElementTypes.PARENTHESIZED_EXPRESSION || parentType == PyElementTypes.GENERATOR_EXPRESSION)) { + if (childType == PyTokenTypes.RPAR || !hasLineBreaksBefore(child, 1)) { + childIndent = Indent.getNoneIndent(); + } + else { + childIndent = Indent.getNormalIndent(); + } } if (isAfterStatementList(child) && !hasLineBreaksBefore(child, 2)) { // maybe enter was pressed and cut us from a previous (nested) statement list diff --git a/python/testData/formatter/tupleClosingParen.py b/python/testData/formatter/tupleClosingParen.py new file mode 100644 index 000000000000..7a97972be2d6 --- /dev/null +++ b/python/testData/formatter/tupleClosingParen.py @@ -0,0 +1,4 @@ +tuple = ( + 'value', + 'value', + ) \ No newline at end of file diff --git a/python/testData/formatter/tupleClosingParen_after.py b/python/testData/formatter/tupleClosingParen_after.py new file mode 100644 index 000000000000..cfd86394a88d --- /dev/null +++ b/python/testData/formatter/tupleClosingParen_after.py @@ -0,0 +1,4 @@ +tuple = ( + 'value', + 'value', +) \ No newline at end of file diff --git a/python/testData/intentions/afterConvertTripleQuotedString.py b/python/testData/intentions/afterConvertTripleQuotedString.py index 2736bd1ffbf0..d3cc2560d372 100644 --- a/python/testData/intentions/afterConvertTripleQuotedString.py +++ b/python/testData/intentions/afterConvertTripleQuotedString.py @@ -4,4 +4,4 @@ if True: '\n' ' Let\'s go.\n' ' And they went out.' - ) \ No newline at end of file + ) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index f21f5bdf8200..180aa90a5fca 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -199,7 +199,10 @@ public class PyFormatterTest extends PyTestCase { public void testSpaceWithinBraces() { // PY-8069 settings().getCustomSettings(PyCodeStyleSettings.class).SPACE_WITHIN_BRACES = true; doTest(); + } + public void testTupleClosingParen() { // PY-7946 + doTest(); } public void testPsiFormatting() { // IDEA-69724 From ed4cf28ac2e51f3af823058d19be9238951df0b7 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Dec 2012 17:00:04 +0100 Subject: [PATCH 4/5] build fix --- python/build/pycharm_build.gant | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/build/pycharm_build.gant b/python/build/pycharm_build.gant index 5df65471b75e..ff18afd3a2aa 100644 --- a/python/build/pycharm_build.gant +++ b/python/build/pycharm_build.gant @@ -170,8 +170,8 @@ private layoutPlugins(layouts) { } dir("lib") { fileset(dir: "${home}/plugins/textmate/lib") { - include("jcodings.jar") - include("joni.jar") + include(name: "jcodings.jar") + include(name: "joni.jar") } } } From 00d40f2d1e19395c3599404c0d690ce3f26689c6 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Dec 2012 17:02:54 +0100 Subject: [PATCH 5/5] delete .pyc when moving Python file (PY-7951) --- .../jetbrains/python/refactoring/move/PyMoveFileHandler.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/src/com/jetbrains/python/refactoring/move/PyMoveFileHandler.java b/python/src/com/jetbrains/python/refactoring/move/PyMoveFileHandler.java index f0197dcf85a5..7fc17d30545a 100644 --- a/python/src/com/jetbrains/python/refactoring/move/PyMoveFileHandler.java +++ b/python/src/com/jetbrains/python/refactoring/move/PyMoveFileHandler.java @@ -34,6 +34,10 @@ public class PyMoveFileHandler extends MoveFileHandler { @Override public void prepareMovedFile(PsiFile file, PsiDirectory moveDestination, Map oldToNewMap) { if (file != null) { + VirtualFile virtualFile = file.getVirtualFile(); + if (virtualFile != null) { + PyUtil.deletePycFiles(virtualFile.getPath()); + } final Collection roots = PyUtil.getSourceRoots(file); PsiDirectory root = moveDestination; while (root != null && !roots.contains(root.getVirtualFile())) {