DS-1584 DS-2583 Reformat breaks IPython magic commands and shell commands

GitOrigin-RevId: 949528c951d6c9174b1bad21452a90fbdb07b418
This commit is contained in:
Olga.Lavrichenko
2023-01-16 15:13:23 +00:00
committed by intellij-monorepo-bot
parent 6acb447706
commit 6df5bfd10d
8 changed files with 167 additions and 2 deletions

View File

@@ -485,7 +485,11 @@ public abstract class PythonCommonFormatterTest extends PythonCommonTestCase {
}
private void doTest(final boolean reformatText) {
myFixture.configureByFile("formatter/" + getTestName(true) + ".py");
doTest(reformatText, "formatter/", ".py");
}
private void doTest(final boolean reformatText, final String filePath, final String fileExtension) {
myFixture.configureByFile(filePath + getTestName(true) + fileExtension);
WriteCommandAction.runWriteCommandAction(null, () -> {
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myFixture.getProject());
PsiFile file = myFixture.getFile();
@@ -496,7 +500,7 @@ public abstract class PythonCommonFormatterTest extends PythonCommonTestCase {
codeStyleManager.reformat(file);
}
});
myFixture.checkResultByFile("formatter/" + getTestName(true) + "_after.py");
myFixture.checkResultByFile(filePath + getTestName(true) + "_after" + fileExtension);
}
// PY-12861
@@ -588,6 +592,14 @@ public abstract class PythonCommonFormatterTest extends PythonCommonTestCase {
doTest();
}
//DS-1584
public void testSpaceIPythonMagicCommands() { doTest(); }
public void testSpaceIPythonMagicCommandsJupyter() { doTest(false, "formatter/jupyter/", ".ipynb"); }
//DS-2583
public void testSpaceShellCommandsJupyter() { doTest(false, "formatter/jupyter/", ".ipynb"); }
/**
* This test merely checks that call to {@link com.intellij.psi.codeStyle.CodeStyleManager#reformat(com.intellij.psi.PsiElement)}
* is possible for Python sources.

View File

@@ -132,6 +132,9 @@ public class PythonFormattingModelBuilder implements FormattingModelBuilder, Cus
.aroundInside(STAR_OPERATORS, STAR_PARAMETERS).none()
.aroundInside(STAR_OPERATORS, STAR_PATTERNS).none()
.between(EXCEPT_KEYWORD, MULT).none()
.between(PERC, TokenSet.create(PERC, IDENTIFIER, EXPRESSION_STATEMENT)).none()
.between(DIV, IDENTIFIER).spaces(0)
.between(IDENTIFIER, DIV).spaces(0)
.around(MULTIPLICATIVE_OPERATIONS).spaceIf(commonSettings.SPACE_AROUND_MULTIPLICATIVE_OPERATORS)
.around(EXP).spaceIf(pySettings.SPACE_AROUND_POWER_OPERATOR)
.around(SHIFT_OPERATIONS).spaceIf(commonSettings.SPACE_AROUND_SHIFT_OPERATORS)

View File

@@ -0,0 +1,37 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%%time\n",
"%dirs"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,37 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%%time\n",
"%dirs"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,36 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"!rm -r path/to/folder"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,36 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"!rm -r path/to/folder"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,2 @@
%%time
%dirs

View File

@@ -0,0 +1,2 @@
%%time
%dirs