Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ekaterina Tuzova
2013-02-15 19:49:35 +04:00
16 changed files with 231 additions and 108 deletions
+3 -3
View File
@@ -66,7 +66,7 @@ __builtin__.getattr = \
:rtype: object or unknown \n\
__builtin__.globals = \
:rtype: dict of (bytes, object)
:rtype: dict of (string, unknown)
__builtin__.hasattr = \
:type name: string \n\
@@ -84,7 +84,7 @@ __builtin__.len = \
:rtype: int \n\
__builtin__.locals = \
:rtype: dict of (bytes, object)
:rtype: dict of (string, unknown)
__builtin__.map = \
:type function: collections.Callable or None \n\
@@ -138,7 +138,7 @@ __builtin__.round = \
:rtype: float \n\
__builtin__.vars = \
:rtype: dict of (bytes, object)
:rtype: dict of (string, unknown)
__builtin__.xrange.__init__ = \
:type start: int \n\
+3 -6
View File
@@ -103,7 +103,8 @@ DONT_TRACE = {
'pydevd_vm_type.py':1,
'pydevd.py':1 ,
'pydevd_psyco_stub.py':1,
'_pydev_execfile.py':1
'_pydev_execfile.py':1,
'_pydev_jython_execfile.py':1
}
if IS_PY3K:
@@ -135,11 +136,7 @@ class PyDBCommandThread(PyDBDaemonThread):
if self.killReceived:
return
run_traced = True
import pydevd_tracing
if run_traced:
pydevd_tracing.SetTrace(None) # no debugging on this thread
threading.settrace(None) # no debugging on this thread
try:
while not self.killReceived:
@@ -22,60 +22,11 @@
<text value="Default test runner:"/>
</properties>
</component>
<component id="88016" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="e486b"/>
<text value="Docstring format:"/>
</properties>
</component>
<component id="e486b" class="javax.swing.JComboBox" binding="myDocstringFormatComboBox" default-binding="true">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model/>
</properties>
</component>
<component id="653de" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="e486b"/>
<text value="Sphinx working directory:"/>
</properties>
</component>
<component id="bef7c" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myWorkDir">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<vspacer id="fc19e">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="40acf" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="e486b"/>
<text value="Treat *.txt files as reStructuredText "/>
</properties>
</component>
<component id="31e02" class="javax.swing.JCheckBox" binding="txtIsRst" default-binding="true">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<grid id="728f8" binding="myErrorPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="6" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -98,23 +49,74 @@
</constraints>
<properties/>
</component>
<component id="67e78" class="com.intellij.ui.components.JBLabel">
<grid id="e7a5f" binding="myDocStringsPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="2" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="e486b"/>
<text value="Analyze docstring test examples"/>
</properties>
</component>
<component id="29b83" class="javax.swing.JCheckBox" binding="analyzeDoctest">
<properties/>
<border type="none"/>
<children>
<component id="88016" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="e486b"/>
<text value="Docstring format:"/>
</properties>
</component>
<component id="e486b" class="javax.swing.JComboBox" binding="myDocstringFormatComboBox" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model/>
</properties>
</component>
<component id="29b83" class="javax.swing.JCheckBox" binding="analyzeDoctest">
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Analyze Python code in docstrings"/>
</properties>
</component>
</children>
</grid>
<grid id="9f040" binding="myRestPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="2" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<properties/>
<border type="none"/>
<children>
<component id="653de" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="e486b"/>
<text value="Sphinx working directory:"/>
</properties>
</component>
<component id="bef7c" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myWorkDir">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="31e02" class="javax.swing.JCheckBox" binding="txtIsRst" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Treat *.txt files as reStructuredText "/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
@@ -17,6 +17,7 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.Comparing;
import com.intellij.ui.CollectionComboBoxModel;
import com.intellij.ui.IdeBorderFactory;
import com.jetbrains.python.PyBundle;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.ReSTService;
@@ -51,6 +52,8 @@ public class PyIntegratedToolsConfigurable implements SearchableConfigurable, No
private JPanel myErrorPanel;
private TextFieldWithBrowseButton myRequirementsPathField;
private JCheckBox analyzeDoctest;
private JPanel myDocStringsPanel;
private JPanel myRestPanel;
public PyIntegratedToolsConfigurable(@NotNull Module module) {
myModule = module;
@@ -67,6 +70,9 @@ public class PyIntegratedToolsConfigurable implements SearchableConfigurable, No
myRequirementsPathField.addBrowseFolderListener("Choose path to the package requirements file:", null, myProject,
FileChooserDescriptorFactory.createSingleLocalFileDescriptor());
myRequirementsPathField.setText(getRequirementsPath());
myDocStringsPanel.setBorder(IdeBorderFactory.createTitledBorder("Docstrings"));
myRestPanel.setBorder(IdeBorderFactory.createTitledBorder("reStructuredText"));
}
@NotNull
@@ -1,11 +1,16 @@
package com.jetbrains.python.debugger;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.jetbrains.appengine.util.StringUtils;
import com.jetbrains.python.psi.PyClass;
import com.jetbrains.python.psi.PyFunction;
import com.jetbrains.python.psi.types.PyClassType;
import com.jetbrains.python.psi.types.PyType;
import com.jetbrains.python.psi.types.PyTypeParser;
import com.jetbrains.python.psi.types.PyUnionType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,13 +30,27 @@ public class PySignatureUtil {
}
if (pyType != null) {
return pyType.getName();
return getPrintableName(pyType);
}
else {
return type;
}
}
private static String getPrintableName(PyType type) {
if (type instanceof PyUnionType) {
return StringUtil.join(Collections2.transform(((PyUnionType)type).getMembers(), new Function<PyType, String>() {
@Override
public String apply(@Nullable PyType input) {
return getPrintableName(input);
}
}), " or ");
}
else {
return type.getName();
}
}
@Nullable
public static String getArgumentType(@NotNull PyFunction function, @NotNull String name) {
PySignatureCacheManager cacheManager = PySignatureCacheManager.getInstance(function.getProject());
@@ -1,10 +1,24 @@
package com.jetbrains.python.inspections;
import com.intellij.codeInspection.LocalInspectionToolSession;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiNameIdentifierOwner;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.rename.PsiElementRenameHandler;
import com.intellij.refactoring.rename.RenameProcessor;
import com.intellij.refactoring.rename.RenamePsiElementProcessor;
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer;
import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.impl.PyBuiltinCache;
import org.jetbrains.annotations.NotNull;
@@ -62,7 +76,55 @@ public class PyShadowingBuiltinsInspection extends PyInspection {
final PsiElement builtin = builtinCache.getByName(name);
if (builtin != null && !PyUtil.inSameFile(builtin, element)) {
final PsiElement identifier = element.getNameIdentifier();
registerProblem(identifier != null ? identifier : element, "Shadows a built-in with the same name");
registerProblem(identifier != null ? identifier : element, "Shadows a built-in with the same name",
new PyRenameElementQuickFix());
}
}
}
private static class PyRenameElementQuickFix implements LocalQuickFix {
@NotNull
@Override
public String getName() {
return "Rename element";
}
@NotNull
@Override
public String getFamilyName() {
return "Rename element";
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
final PsiNameIdentifierOwner nameOwner = element instanceof PsiNameIdentifierOwner ?
(PsiNameIdentifierOwner)element :
PsiTreeUtil.getParentOfType(element, PsiNameIdentifierOwner.class, true);
if (nameOwner != null) {
final VirtualFile virtualFile = nameOwner.getContainingFile().getVirtualFile();
if (virtualFile != null) {
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), true);
if (ApplicationManager.getApplication().isUnitTestMode()) {
renameInUnitTestMode(project, nameOwner, editor);
}
else {
if (nameOwner instanceof PyNamedParameter || nameOwner instanceof PyTargetExpression) {
new VariableInplaceRenamer(nameOwner, editor).performInplaceRename();
}
else {
PsiElementRenameHandler.invoke(nameOwner, project, ScopeUtil.getScopeOwner(nameOwner), editor);
}
}
}
}
}
private static void renameInUnitTestMode(@NotNull Project project, @NotNull PsiNameIdentifierOwner nameOwner,
@Nullable Editor editor) {
final PsiElement substitution = RenamePsiElementProcessor.forElement(nameOwner).substituteElementToRename(nameOwner, editor);
if (substitution != null) {
new RenameProcessor(project, substitution, "a", false, false).run();
}
}
}
@@ -171,7 +171,6 @@ public abstract class PythonCommandLineState extends CommandLineState {
private ProcessHandler startRemoteProcess(Sdk sdk, GeneralCommandLine commandLine) throws ExecutionException {
PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
if (manager != null) {
ProcessHandler processHandler =
null;
@@ -288,12 +287,13 @@ public abstract class PythonCommandLineState extends CommandLineState {
boolean passParentEnvs,
List<String> pathList,
final String interpreterPath) {
Map<String, String> envs = commandLine.getEnvParams();
final PythonSdkFlavor flavor = PythonSdkFlavor.getFlavor(interpreterPath);
if (flavor != null) {
flavor.initPythonPath(commandLine, pathList);
}
else {
PythonSdkFlavor.initPythonPath(commandLine.getEnvParams(), passParentEnvs, pathList);
PythonSdkFlavor.initPythonPath(envs, passParentEnvs, pathList);
}
}
@@ -339,8 +339,6 @@ public abstract class PythonCommandLineState extends CommandLineState {
}
return pythonPath;
}
@NotNull
@@ -78,11 +78,13 @@ public class PythonEnvUtil {
}
public static void addToEnv(Map<String, String> envs, String key, String value) {
if (envs.containsKey(key)) {
envs.put(key, appendToPathEnvVar(envs.get(key), value));
}
else {
envs.put(key, value);
if (!StringUtil.isEmpty(value)) {
if (envs.containsKey(key)) {
envs.put(key, appendToPathEnvVar(envs.get(key), value));
}
else {
envs.put(key, value);
}
}
}
@@ -7,10 +7,7 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
import java.util.*;
/**
* @author yole
@@ -73,7 +70,13 @@ public class IronPythonSdkFlavor extends PythonSdkFlavor {
@Override
public void initPythonPath(GeneralCommandLine cmd, Collection<String> path) {
addToEnv(cmd, "IRONPYTHONPATH", StringUtil.join(path, File.pathSeparator));
Map<String,String> env = getEnv(cmd);
initPythonPath(path, env);
}
@Override
public void initPythonPath(Collection<String> path, Map<String, String> env) {
addToEnv("IRONPYTHONPATH", StringUtil.join(path, File.pathSeparator), env);
}
@NotNull
@@ -5,12 +5,14 @@ import com.intellij.execution.configurations.ParamsGroup;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.jetbrains.python.run.PythonCommandLineState;
import com.jetbrains.python.sdk.PythonEnvUtil;
import icons.PythonIcons;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.io.File;
import java.util.Collection;
import java.util.Map;
/**
* @author yole
@@ -23,14 +25,6 @@ public class JythonSdkFlavor extends PythonSdkFlavor {
public static JythonSdkFlavor INSTANCE = new JythonSdkFlavor();
public static String appendSystemJythonPath(String pythonPath) {
String syspath = System.getenv(JYTHONPATH);
if (syspath != null) {
pythonPath += File.pathSeparator + syspath;
}
return pythonPath;
}
public boolean isValidSdkPath(@NotNull File file) {
return FileUtil.getNameWithoutExtension(file).toLowerCase().startsWith("jython");
}
@@ -47,13 +41,19 @@ public class JythonSdkFlavor extends PythonSdkFlavor {
@Override
public void initPythonPath(GeneralCommandLine cmd, Collection<String> path) {
final String jythonPath = StringUtil.join(path, File.pathSeparator);
addToEnv(cmd, JYTHONPATH, appendSystemJythonPath(jythonPath));
initPythonPath(path, getEnv(cmd));
ParamsGroup param_group = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_EXE_OPTIONS);
assert param_group != null;
param_group.addParameter(getPythonPathCmdLineArgument(path));
}
@Override
public void initPythonPath(Collection<String> path, Map<String, String> env) {
path = appendSystemEnvPaths(path, JYTHONPATH);
final String jythonPath = StringUtil.join(path, File.pathSeparator);
addToEnv(JYTHONPATH, jythonPath, env);
}
@NotNull
@Override
public String getName() {
@@ -61,7 +61,7 @@ public class JythonSdkFlavor extends PythonSdkFlavor {
}
public static String getPythonPathCmdLineArgument(Collection<String> path) {
return "-Dpython.path=" + appendSystemJythonPath(StringUtil.join(path, File.pathSeparator));
return "-Dpython.path=" + StringUtil.join(appendSystemEnvPaths(path, JYTHONPATH), File.pathSeparator);
}
@Override
@@ -32,7 +32,11 @@ public abstract class PythonSdkFlavor {
private static final Logger LOG = Logger.getInstance(PythonSdkFlavor.class);
public static Collection<String> appendSystemPythonPath(Collection<String> pythonPath) {
String syspath = System.getenv(PythonEnvUtil.PYTHONPATH);
return appendSystemEnvPaths(pythonPath, PythonEnvUtil.PYTHONPATH);
}
protected static Collection<String> appendSystemEnvPaths(Collection<String> pythonPath, String envname) {
String syspath = System.getenv(envname);
if (syspath != null) {
pythonPath.addAll(Lists.newArrayList(syspath.split(File.pathSeparator)));
}
@@ -186,20 +190,14 @@ public abstract class PythonSdkFlavor {
}
public void initPythonPath(GeneralCommandLine cmd, Collection<String> path) {
addToEnv(cmd, PythonEnvUtil.PYTHONPATH, appendSystemPythonPath(path));
initPythonPath(path, getEnv(cmd));
}
public static void addToEnv(GeneralCommandLine cmd, final String key, Collection<String> values) {
Map<String, String> envs = getEnv(cmd);
PythonEnvUtil.addToEnv(envs, key, values);
}
public static void addToEnv(GeneralCommandLine cmd, final String key, String value) {
Map<String, String> envs = getEnv(cmd);
public static void addToEnv(final String key, String value, Map<String, String> envs) {
PythonEnvUtil.addToEnv(envs, key, value);
}
private static Map<String, String> getEnv(GeneralCommandLine cmd) {
static Map<String, String> getEnv(GeneralCommandLine cmd) {
Map<String, String> envs = cmd.getEnvParams();
if (envs == null) {
envs = new HashMap<String, String>();
@@ -232,4 +230,9 @@ public abstract class PythonSdkFlavor {
public Icon getIcon() {
return PythonIcons.Python.Python;
}
public void initPythonPath(Collection<String> path, Map<String, String> env) {
path = appendSystemPythonPath(path);
addToEnv(PythonEnvUtil.PYTHONPATH, StringUtil.join(path, File.pathSeparator), env);
}
}
@@ -0,0 +1,6 @@
def <warning descr="Shadows a built-in with the same name">i<caret>d</warning>(x):
return x
def f():
return id('foo')
@@ -0,0 +1,6 @@
def a(x):
return x
def f():
return a('foo')
@@ -0,0 +1,3 @@
def f(name):
<warning descr="Shadows a built-in with the same name">f<caret>ile</warning> = open(name, 'rb')
return file.read()
@@ -0,0 +1,3 @@
def f(name):
a = open(name, 'rb')
return a.read()
@@ -424,6 +424,19 @@ public class PyQuickFixTest extends PyTestCase {
myFixture.checkResultByFile(graftBeforeExt(testFiles[0], "_after"));
}
// PY-8788
public void testRenameShadowingBuiltins() {
doInspectionTest("RenameShadowingBuiltins.py", PyShadowingBuiltinsInspection.class,
"Rename element", true, true);
}
// PY-8788
public void testRenameFunctionShadowingBuiltins() {
doInspectionTest("RenameFunctionShadowingBuiltins.py", PyShadowingBuiltinsInspection.class,
"Rename element", true, true);
}
@Override
@NonNls
protected String getTestDataPath() {