Python: remove pre-targets API

Targets are enabled by default for more than a year

GitOrigin-RevId: ab0469410b4a699ce516c2054e38b63753c726fb
This commit is contained in:
Ilya.Kazakevich
2024-09-12 21:08:46 +02:00
committed by intellij-monorepo-bot
parent 6cf6f20581
commit 218af635f1
15 changed files with 32 additions and 181 deletions

View File

@@ -551,7 +551,6 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
<backgroundPostStartupActivity implementation="com.jetbrains.python.sdk.poetry.PoetryConfigLoader" order="last"/>
<!-- Targets API -->
<registryKey key="python.use.targets.api" defaultValue="true" description="Switches Python support to Targets API."/>
<registryKey key="enable.conda.on.targets" defaultValue="false" description="Enables Conda configuration on targets."/>
<registryKey key="python.packaging.tool.use.project.location.as.working.dir" defaultValue="false"
description="Use project location as a working directory for the packaging tool execution."/>
@@ -856,7 +855,6 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
<inspectionExtension implementation="com.jetbrains.python.inspections.PyUnresolvedReferenceDefaultInspectionExtension" order="last"/>
<runConfigurationEditorExtension implementation="com.jetbrains.python.run.PyRunConfigurationTargetOptions"/>
<remoteSdkValidator implementation="com.jetbrains.python.target.PyTargetSdkValidator"/>
<PythonPackagingToolwindowActionProvider implementation="com.jetbrains.python.packaging.pip.PipPackagingToolwindowActionProvider"/>
<PythonPackagingToolwindowActionProvider implementation="com.jetbrains.python.packaging.conda.CondaPackagingToolwindowActionProvider"/>

View File

@@ -107,13 +107,8 @@ public class PyActiveSdkConfigurable implements UnnamedConfigurable {
customUiProvider == null ? null : new Pair<>(customUiProvider, myDisposable);
final JButton additionalAction;
if (Registry.get("python.use.targets.api").asBoolean()) {
additionalAction = new DropDownLink<>(PyBundle.message("active.sdk.dialog.link.add.interpreter.text"),
link -> createAddInterpreterPopup(project, module, link, this::updateSdkListAndSelect));
}
else {
additionalAction = buildDetailsButton(mySdkCombo, this::onShowDetailsClicked);
}
myMainPanel = buildPanel(project, mySdkCombo, additionalAction, myPackagesPanel, packagesNotificationPanel, customizer);
@@ -239,14 +234,9 @@ public class PyActiveSdkConfigurable implements UnnamedConfigurable {
}
private void onShowAllSelected() {
if (Registry.is("python.use.targets.api")) {
Sdk selectedSdk = PythonInterpreterConfigurable.openInDialog(myProject, myModule, getEditableSelectedSdk());
onShowAllInterpretersDialogClosed(selectedSdk);
}
else {
buildAllSdksDialog().show();
}
}
protected void onSdkSelected() {
final Sdk sdk = getOriginalSelectedSdk();

View File

@@ -10,7 +10,6 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.util.PathMapper
import com.intellij.util.SystemProperties
@@ -69,17 +68,10 @@ open class PydevConsoleRunnerFactory : PythonConsoleRunnerFactory() {
val pathMapper = getPathMapper(project, sdk, settingsProvider)
val envs = settingsProvider.envs.toMutableMap()
putIPythonEnvFlag(project, envs)
if (Registry.`is`("python.use.targets.api")) {
val workingDirFunction = getWorkingDirFunction(project, module, pathMapper, settingsProvider)
val setupScriptFunction = createSetupScriptFunction(project, module, workingDirFunction, pathMapper, settingsProvider)
return TargetedConsoleParameters(project, sdk, workingDirFunction, envs, PyConsoleType.PYTHON, settingsProvider, setupScriptFunction)
}
else {
val workingDir = getWorkingDir(project, module, pathMapper, settingsProvider)
val setupFragment = createSetupFragment(module, workingDir, pathMapper, settingsProvider)
return ConstantConsoleParameters(project, sdk, workingDir, envs, PyConsoleType.PYTHON, settingsProvider, setupFragment)
}
}
override fun createConsoleRunner(project: Project, contextModule: Module?): PydevConsoleRunner {
val module = PyConsoleCustomizer.EP_NAME.extensionList.firstNotNullOfOrNull { it.guessConsoleModule(project, contextModule) }

View File

@@ -823,16 +823,7 @@ public class PydevConsoleRunnerImpl implements PydevConsoleRunner {
private void initAndRun(@NotNull Sdk sdk) throws ExecutionException {
// Create Server process
ConsoleProcessCreationResult processCreationResult;
boolean isUseTargetsAPI = Registry.is("python.use.targets.api");
if (isUseTargetsAPI) {
processCreationResult = createProcessUsingTargetsAPI(sdk);
}
else if (PyRunnerUtil.isTargetBased(sdk)) {
throw new ExecutionException(PySdkBundle.message("python.sdk.please.reconfigure.interpreter"));
}
else {
processCreationResult = createProcess(sdk);
}
TargetEnvironment targetEnvironment = processCreationResult.getTargetEnvironment();
UIUtil.invokeAndWaitIfNeeded(() -> {
// Init console view

View File

@@ -153,17 +153,8 @@ public class PyDebugRunner implements ProgramRunner<RunnerSettings> {
@RequiresEdt
protected Promise<@NotNull XDebugSession> createSession(@NotNull RunProfileState state, final @NotNull ExecutionEnvironment environment) {
FileDocumentManager.getInstance().saveAllDocuments();
if (Registry.is("python.use.targets.api")) {
return createSessionUsingTargetsApi(state, environment);
}
if (PyRunnerUtil.isTargetBasedSdkAssigned(state)) {
Project project = environment.getProject();
Module module = PyRunnerUtil.getModule(state);
throw new RuntimeExceptionWithHyperlink(PyBundle.message("runcfg.error.message.python.interpreter.is.invalid.configure"),
() -> showPythonInterpreterSettings(project, module));
}
return createSessionLegacy(state, environment);
}
private @NotNull Promise<XDebugSession> createSessionUsingTargetsApi(@NotNull RunProfileState state,
final @NotNull ExecutionEnvironment environment) {

View File

@@ -87,7 +87,6 @@ class PyAddExistingSdkPanel(project: Project?,
val sdksForNewProject = existingSdks.filter { it.associatedModulePath == null &&
!needAssociateConfigurationWithModule(it.targetEnvConfiguration) }
val interpreterComponent: JComponent
if (Registry.`is`("python.use.targets.api")) {
val preselectedSdk = sdksForNewProject.firstOrNull { it == preferredSdk }
val pythonSdkComboBox = createPythonSdkComboBox(sdksForNewProject, preselectedSdk)
pythonSdkComboBox.addActionListener { update() }
@@ -96,25 +95,6 @@ class PyAddExistingSdkPanel(project: Project?,
addSdkChangedListener = { runnable ->
sdkComboBox.addActionListener { runnable.run() }
}
}
else {
val legacySdkChooser = PythonSdkChooserCombo(project, module,
sdksForNewProject) {
it != null && it == preferredSdk
}.apply {
if (SystemInfo.isMac && !UIUtil.isUnderDarcula()) {
putClientProperty("JButton.buttonType", null)
}
addChangedListener {
update()
}
}
interpreterComponent = legacySdkChooser
sdkComboBox = legacySdkChooser.comboBox
addSdkChangedListener = { runnable ->
legacySdkChooser.addChangedListener { runnable.run() }
}
}
val formPanel = FormBuilder.createFormBuilder()
.addLabeledComponent(PySdkBundle.message("python.interpreter.label"), interpreterComponent)
.addComponent(remotePathField.mainPanel)

View File

@@ -21,7 +21,6 @@ import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.python.HelperPackage;
@@ -36,7 +35,6 @@ import com.jetbrains.python.run.PythonScripts;
import com.jetbrains.python.run.target.HelpersAwareTargetEnvironmentRequest;
import com.jetbrains.python.sdk.PyLazySdk;
import com.jetbrains.python.sdk.PySdkExtKt;
import com.jetbrains.python.sdk.PythonSdkUtil;
import com.jetbrains.python.sdk.VirtualEnvReader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -172,16 +170,12 @@ public class PyTargetEnvironmentPackageManager extends PyPackageManagerImplBase
@Override
public @Nullable List<PyPackage> getPackages() {
if (!Registry.is("python.use.targets.api")) {
return Collections.emptyList();
}
final List<PyPackage> packages = myPackagesCache;
return packages != null ? Collections.unmodifiableList(packages) : null;
}
@Override
protected @NotNull List<PyPackage> collectPackages() throws ExecutionException {
assertUseTargetsAPIFlagEnabled();
if (getSdk() instanceof PyLazySdk) {
return List.of();
}
@@ -210,12 +204,6 @@ public class PyTargetEnvironmentPackageManager extends PyPackageManagerImplBase
return parsePackagingToolOutput(output);
}
private static void assertUseTargetsAPIFlagEnabled() throws ExecutionException {
if (!Registry.is("python.use.targets.api")) {
throw new ExecutionException(PySdkBundle.message("python.sdk.please.reconfigure.interpreter"));
}
}
@Override
public @NotNull String createVirtualEnv(@NotNull String destinationDir, boolean useGlobalSite) throws ExecutionException {
final Sdk sdk = getSdk();

View File

@@ -10,15 +10,7 @@ class PyRunConfigurationTargetOptions : PyRunConfigurationEditorExtension {
private val factoriesCache = WeakHashMap<RunConfigurationTargetEnvironmentAdjuster, PyRunConfigurationEditorFactory>()
override fun accepts(configuration: AbstractPythonRunConfiguration<out AbstractPythonRunConfiguration<*>>): PyRunConfigurationEditorFactory? {
if (!Registry.`is`("python.use.targets.api")) return null
val sdk = configuration.sdk ?: return null
val adjuster = RunConfigurationTargetEnvironmentAdjuster.Factory.findTargetEnvironmentRequestAdjuster(sdk) ?: return null
return if (adjuster.providesAdditionalRunConfigurationUI()) {
factoriesCache.computeIfAbsent(adjuster) { RunConfigurationsTargetOptionsFactory(adjuster) }
}
else {
null
}
return null
}
private class RunConfigurationsTargetOptionsFactory(private val adjuster: RunConfigurationTargetEnvironmentAdjuster) : PyRunConfigurationEditorFactory {

View File

@@ -9,17 +9,6 @@ import com.intellij.openapi.projectRoots.Sdk
import com.jetbrains.python.target.PyTargetAwareAdditionalData
import org.jetbrains.annotations.ApiStatus
/**
* Checks if [this] state (typically created using a run configuration) is [PythonCommandLineState] and the Python interpreter assigned to
* it is based on a target.
*
* Handles "Project Default" Python interpreter resolving it to the interpreter assigned to the corresponding module of the run
* configuration.
*/
@ApiStatus.Internal
internal fun RunProfileState.isTargetBasedSdkAssigned(): Boolean =
(this as? PythonCommandLineState)?.sdk?.sdkAdditionalData is PyTargetAwareAdditionalData
internal val Sdk.isTargetBased: Boolean
@ApiStatus.Internal
get() = sdkAdditionalData is PyTargetAwareAdditionalData

View File

@@ -58,24 +58,13 @@ public class PythonRunner extends AsyncProgramRunner<RunnerSettings> {
AsyncPromise<RunContentDescriptor> promise = new AsyncPromise<>();
execute(state, () -> {
try {
boolean useTargetsAPI = Registry.is("python.use.targets.api");
ExecutionResult executionResult;
RunProfile profile = env.getRunProfile();
if (useTargetsAPI && state instanceof PythonCommandLineState) {
if (state instanceof PythonCommandLineState) {
// TODO [cloud-api.python] profile functionality must be applied here:
// - com.jetbrains.django.run.DjangoServerRunConfiguration.patchCommandLineFirst() - host:port is put in user data
executionResult = ((PythonCommandLineState)state).execute(env.getExecutor());
}
else if (!useTargetsAPI && PyRunnerUtil.isTargetBasedSdkAssigned(state)) {
Project project = env.getProject();
Module module = PyRunnerUtil.getModule(state);
throw new ExecutionExceptionWithHyperlink(PyBundle.message("runcfg.error.message.python.interpreter.is.invalid.configure"),
() -> showPythonInterpreterSettings(project, module));
}
else if (!useTargetsAPI && state instanceof PythonCommandLineState && profile instanceof CommandLinePatcher) {
executionResult = ((PythonCommandLineState)state).execute(env.getExecutor(), (CommandLinePatcher)profile);
}
else {
executionResult = state.execute(env.getExecutor(), this);
}

View File

@@ -79,7 +79,7 @@ public class PythonScriptCommandLineState extends PythonCommandLineState {
return super.execute(executor, processStarter, ArrayUtil.append(patchers, new CommandLinePatcher() {
@Override
public void patchCommandLine(GeneralCommandLine commandLine) {
commandLine.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_DEBUGGER).addParameterAt(1, "--cmd-line");
commandLine.getParametersList().getParamsGroup(GROUP_DEBUGGER).addParameterAt(1, "--cmd-line");
}
}));
}
@@ -209,10 +209,6 @@ public class PythonScriptCommandLineState extends PythonCommandLineState {
* @see com.intellij.terminal.ProcessHandlerTtyConnector
*/
private boolean emulateTerminal() {
if (PythonSdkUtil.isRemote(getSdk()) && !Registry.is("python.use.targets.api")) {
// do not allow to emulate terminal for legacy non-target remote interpreters logic
return false;
}
return myConfig.emulateTerminal();
}

View File

@@ -83,16 +83,11 @@ class PySdkPopupFactory(val module: Module) {
}
if (moduleSdksByTypes.isNotEmpty()) group.addSeparator()
if (Registry.get("python.use.targets.api").asBoolean()) {
val addNewInterpreterPopupGroup = DefaultActionGroup(PyBundle.message("python.sdk.action.add.new.interpreter.text"), true)
addNewInterpreterPopupGroup.addAll(collectAddInterpreterActions(ModuleOrProject.ModuleAndProject(module)) { switchToSdk(module, it, currentSdk) })
group.add(addNewInterpreterPopupGroup)
group.addSeparator()
}
group.add(InterpreterSettingsAction())
if (!Registry.get("python.use.targets.api").asBoolean()) {
group.add(AddInterpreterAction(module.project, module, currentSdk))
}
group.add(object : AnAction(PyBundle.message("python.packaging.interpreter.widget.manage.packages")) {
override fun actionPerformed(e: AnActionEvent) {
ToolWindowManager.getInstance(module.project).getToolWindow("Python Packages")?.show()

View File

@@ -138,7 +138,6 @@ public final class PythonSdkUpdater {
"Starting SDK refresh for '" + mySdk.getName() + "' triggered by " + Trigger.getCauseByTrace(myRequestData.myTraceback));
}
try {
if (Registry.get("python.use.targets.api").asBoolean()) {
PyTargetsIntrospectionFacade targetsFacade = new PyTargetsIntrospectionFacade(mySdk, myProject);
String version = targetsFacade.getInterpreterVersion(indicator);
commitSdkVersionIfChanged(mySdk, version);
@@ -149,15 +148,11 @@ public final class PythonSdkUpdater {
else {
targetsFacade.synchronizeRemoteSourcesAndSetupMappings(indicator);
}
}
else {
updateLocalSdkVersionAndPaths(mySdk, myProject);
}
// This step also includes setting mapped interpreter paths
generateSkeletons(mySdk, indicator);
refreshPackages(mySdk, indicator);
}
catch (InvalidSdkException | ExecutionException e) {
catch (ExecutionException e) {
LOG.warn("Update for SDK " + mySdk.getName() + " failed", e);
}
finally {

View File

@@ -118,25 +118,8 @@ public class PySkeletonRefresher {
myIndicator = indicator;
mySdk = sdk;
mySkeletonsPath = skeletonsPath;
if (Registry.is("python.use.targets.api")) {
mySkeletonsGenerator = new PyTargetsSkeletonGenerator(getSkeletonsPath(), mySdk, folder, myProject);
}
else if (PyRunnerUtil.isTargetBased(sdk)) {
// when `python.use.targets.api` flag is disabled
throw new InvalidSdkException(PySdkBundle.message("python.sdk.please.reconfigure.interpreter"));
}
else if (PythonSdkUtil.isRemote(sdk)) {
try {
mySkeletonsGenerator = createRemoteSkeletonGenerator(myProject, ownerComponent, sdk, getSkeletonsPath());
}
catch (ExecutionException e) {
throw new InvalidSdkException(e.getMessage(), e.getCause());
}
}
else {
mySkeletonsGenerator = new PyLegacySkeletonGenerator(getSkeletonsPath(), mySdk, folder);
}
}
public @NotNull List<String> regenerateSkeletons() throws InvalidSdkException, ExecutionException {
final String skeletonsPath = getSkeletonsPath();

View File

@@ -1,18 +0,0 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.target
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.util.registry.Registry
import com.jetbrains.python.sdk.PyRemoteSdkValidator
import org.jetbrains.annotations.ApiStatus
/**
* The extension allows to *visually* highlight target-based interpreters when the flag `python.use.targets.api` is disabled.
*
* **Note:** this extension is going to be removed as soon as possible after ultimate switching to Targets API.
*/
@ApiStatus.Internal
class PyTargetSdkValidator : PyRemoteSdkValidator {
override fun isInvalid(sdk: Sdk): Boolean =
!Registry.`is`("python.use.targets.api") && sdk.sdkAdditionalData is PyTargetAwareAdditionalData
}