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") } } } 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/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 28b16126f316..38f6d0078142 100644 --- a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java +++ b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java @@ -80,12 +80,13 @@ 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) .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/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())) { 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/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/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 fde733c7a86c..180aa90a5fca 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; @@ -191,6 +192,19 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + public void testSpaceAfterRelativeImport() { // PY-8112 + doTest(); + } + + 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 String initial = "def method_name(\n" +