diff --git a/python/python-rest/src/com/jetbrains/rest/run/RestRunConfigurationType.java b/python/python-rest/src/com/jetbrains/rest/run/RestRunConfigurationType.java index 0045004bcf12..79929d2e3f2c 100644 --- a/python/python-rest/src/com/jetbrains/rest/run/RestRunConfigurationType.java +++ b/python/python-rest/src/com/jetbrains/rest/run/RestRunConfigurationType.java @@ -15,8 +15,12 @@ */ package com.jetbrains.rest.run; -import com.intellij.execution.configurations.*; +import com.intellij.execution.configurations.ConfigurationFactory; +import com.intellij.execution.configurations.ConfigurationType; +import com.intellij.execution.configurations.ConfigurationTypeUtil; +import com.intellij.execution.configurations.RunConfiguration; import com.intellij.openapi.project.Project; +import com.jetbrains.python.run.PythonConfigurationFactoryBase; import com.jetbrains.rest.RestBundle; import com.jetbrains.rest.RestFileType; import com.jetbrains.rest.run.docutils.DocutilsRunConfiguration; @@ -59,7 +63,7 @@ public class RestRunConfigurationType implements ConfigurationType { return new ConfigurationFactory[] {DOCUTILS_FACTORY, SPHINX_FACTORY}; } - private static abstract class RestConfigurationFactory extends ConfigurationFactory { + private static abstract class RestConfigurationFactory extends PythonConfigurationFactoryBase { private final String myName; public RestConfigurationFactory(@NotNull final ConfigurationType type, @NotNull String name) { diff --git a/python/src/com/jetbrains/python/run/PythonConfigurationFactoryBase.java b/python/src/com/jetbrains/python/run/PythonConfigurationFactoryBase.java new file mode 100644 index 000000000000..1d0a0823e023 --- /dev/null +++ b/python/src/com/jetbrains/python/run/PythonConfigurationFactoryBase.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jetbrains.python.run; + +import com.intellij.execution.configurations.ConfigurationFactory; +import com.intellij.execution.configurations.ConfigurationType; +import com.intellij.openapi.project.Project; +import com.intellij.util.PlatformUtils; +import com.jetbrains.python.sdk.PythonSdkType; +import org.jetbrains.annotations.NotNull; + +/** + * @author nik + */ +public abstract class PythonConfigurationFactoryBase extends ConfigurationFactory { + protected PythonConfigurationFactoryBase(@NotNull ConfigurationType type) { + super(type); + } + + @Override + public boolean isApplicable(@NotNull Project project) { + return PlatformUtils.isPyCharm() || PythonSdkType.hasValidSdk(); + } +} diff --git a/python/src/com/jetbrains/python/run/PythonConfigurationType.java b/python/src/com/jetbrains/python/run/PythonConfigurationType.java index 5f4cd959e049..6d2e26a9274c 100644 --- a/python/src/com/jetbrains/python/run/PythonConfigurationType.java +++ b/python/src/com/jetbrains/python/run/PythonConfigurationType.java @@ -43,7 +43,7 @@ public class PythonConfigurationType implements ConfigurationType { return null; } - private static class PythonConfigurationFactory extends ConfigurationFactory { + private static class PythonConfigurationFactory extends PythonConfigurationFactoryBase { protected PythonConfigurationFactory(ConfigurationType configurationType) { super(configurationType); } diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkType.java b/python/src/com/jetbrains/python/sdk/PythonSdkType.java index 0e64b29b374d..65d808210ec6 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkType.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkType.java @@ -190,6 +190,15 @@ public class PythonSdkType extends SdkType { return s; } + public static boolean hasValidSdk() { + for (Sdk sdk : ProjectJdkTable.getInstance().getAllJdks()) { + if (sdk.getSdkType() instanceof PythonSdkType) { + return true; + } + } + return false; + } + public boolean isValidSdkHome(@Nullable final String path) { return PythonSdkFlavor.getFlavor(path) != null; } diff --git a/python/src/com/jetbrains/python/testing/PythonTestConfigurationType.java b/python/src/com/jetbrains/python/testing/PythonTestConfigurationType.java index 9d9a39677460..059509a42236 100644 --- a/python/src/com/jetbrains/python/testing/PythonTestConfigurationType.java +++ b/python/src/com/jetbrains/python/testing/PythonTestConfigurationType.java @@ -15,9 +15,13 @@ */ package com.jetbrains.python.testing; -import com.intellij.execution.configurations.*; +import com.intellij.execution.configurations.ConfigurationFactory; +import com.intellij.execution.configurations.ConfigurationType; +import com.intellij.execution.configurations.ConfigurationTypeUtil; +import com.intellij.execution.configurations.RunConfiguration; import com.intellij.openapi.project.Project; import com.jetbrains.python.PyBundle; +import com.jetbrains.python.run.PythonConfigurationFactoryBase; import com.jetbrains.python.testing.attest.PythonAtTestRunConfiguration; import com.jetbrains.python.testing.doctest.PythonDocTestRunConfiguration; import com.jetbrains.python.testing.nosetest.PythonNoseTestRunConfiguration; @@ -44,7 +48,7 @@ public class PythonTestConfigurationType implements ConfigurationType { return ConfigurationTypeUtil.findConfigurationType(PythonTestConfigurationType.class); } - private static class PythonUnitTestConfigurationFactory extends ConfigurationFactory { + private static class PythonUnitTestConfigurationFactory extends PythonConfigurationFactoryBase { protected PythonUnitTestConfigurationFactory(ConfigurationType configurationType) { super(configurationType); } @@ -60,7 +64,7 @@ public class PythonTestConfigurationType implements ConfigurationType { } } - private static class PythonDocTestConfigurationFactory extends ConfigurationFactory { + private static class PythonDocTestConfigurationFactory extends PythonConfigurationFactoryBase { protected PythonDocTestConfigurationFactory(ConfigurationType configurationType) { super(configurationType); } @@ -76,7 +80,7 @@ public class PythonTestConfigurationType implements ConfigurationType { } } - private static class PythonPyTestConfigurationFactory extends ConfigurationFactory { + private static class PythonPyTestConfigurationFactory extends PythonConfigurationFactoryBase { protected PythonPyTestConfigurationFactory(ConfigurationType configurationType) { super(configurationType); } @@ -92,7 +96,7 @@ public class PythonTestConfigurationType implements ConfigurationType { } } - private static class PythonNoseTestConfigurationFactory extends ConfigurationFactory { + private static class PythonNoseTestConfigurationFactory extends PythonConfigurationFactoryBase { protected PythonNoseTestConfigurationFactory(ConfigurationType configurationType) { super(configurationType); } @@ -108,7 +112,7 @@ public class PythonTestConfigurationType implements ConfigurationType { } } - private static class PythonAtTestConfigurationFactory extends ConfigurationFactory { + private static class PythonAtTestConfigurationFactory extends PythonConfigurationFactoryBase { protected PythonAtTestConfigurationFactory(ConfigurationType configurationType) { super(configurationType); }