[python] Rename and move python facets

Facets should be in appropriate packages according to v2

GitOrigin-RevId: cacc729a038f40bfaf9ebb2d89d1e1a744fd71f1
This commit is contained in:
Ilya.Kazakevich
2024-01-16 14:02:45 +01:00
committed by intellij-monorepo-bot
parent f207c9f575
commit 8a334cf9d2
15 changed files with 109 additions and 120 deletions

View File

@@ -7,8 +7,8 @@
<extensions defaultExtensionNs="com.intellij">
<newProjectWizard.languageGenerator implementation="com.jetbrains.python.newProject.PythonNewProjectWizard"/>
<moduleType id="PYTHON_MODULE" implementationClass="com.jetbrains.python.module.PythonModuleType"/>
<facetType implementation="com.jetbrains.python.facet.PythonFacetType"/>
<frameworkSupport implementation="com.jetbrains.python.facet.PythonFrameworkSupportProvider"/>
<facetType implementation="com.intellij.python.community.plugin.java.facet.JavaPythonFacetType"/>
<frameworkSupport implementation="com.intellij.python.community.plugin.java.facet.PythonFrameworkSupportProvider"/>
<projectStructureDetector implementation="com.jetbrains.python.module.PyProjectStructureDetector"/>
<moduleConfigurationEditorProvider implementation="com.jetbrains.python.module.PythonModuleConfigurationEditorProvider"/>
<completion.contributor language="Python" implementationClass="com.jetbrains.python.psi.impl.PyConstructorArgumentCompletionContributor"/>

View File

@@ -1,22 +1,23 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.facet;
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.plugin.java.facet;
import com.intellij.facet.Facet;
import com.intellij.facet.FacetType;
import com.intellij.facet.FacetTypeId;
import com.intellij.openapi.module.Module;
import com.intellij.python.community.plugin.impl.facet.PythonFacetUtil;
import com.jetbrains.python.facet.LibraryContributingFacet;
import org.jetbrains.annotations.NotNull;
public class PythonFacet extends LibraryContributingFacet<PythonFacetConfiguration> {
public static final FacetTypeId<PythonFacet> ID = new FacetTypeId<>("python");
public class JavaPythonFacet extends LibraryContributingFacet<JavaPythonFacetConfiguration> {
public static final FacetTypeId<JavaPythonFacet> ID = new FacetTypeId<>("python");
public PythonFacet(@NotNull final FacetType facetType,
@NotNull final Module module,
@NotNull final String name,
@NotNull final PythonFacetConfiguration configuration,
Facet underlyingFacet) {
public JavaPythonFacet(@NotNull final FacetType facetType,
@NotNull final Module module,
@NotNull final String name,
@NotNull final JavaPythonFacetConfiguration configuration,
Facet underlyingFacet) {
super(facetType, module, name, configuration, underlyingFacet);
}

View File

@@ -1,5 +1,5 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.facet;
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.plugin.java.facet;
import com.intellij.facet.FacetConfiguration;
import com.intellij.facet.ui.FacetEditorContext;
@@ -9,11 +9,12 @@ import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.text.StringUtil;
import com.jetbrains.python.facet.PythonFacetSettings;
import com.jetbrains.python.sdk.PythonSdkType;
import org.jdom.Element;
public class PythonFacetConfiguration extends PythonFacetSettings implements FacetConfiguration {
class JavaPythonFacetConfiguration extends PythonFacetSettings implements FacetConfiguration {
private static final String SDK_NAME = "sdkName";
@Override

View File

@@ -1,5 +1,5 @@
// 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.facet;
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.plugin.java.facet;
import com.intellij.facet.Facet;
import com.intellij.facet.FacetType;
@@ -19,22 +19,22 @@ import javax.swing.*;
import java.util.List;
public final class PythonFacetType extends FacetType<PythonFacet, PythonFacetConfiguration> {
public final class JavaPythonFacetType extends FacetType<JavaPythonFacet, JavaPythonFacetConfiguration> {
@NonNls
private static final String ID = "Python";
public static PythonFacetType getInstance() {
return findInstance(PythonFacetType.class);
public static JavaPythonFacetType getInstance() {
return findInstance(JavaPythonFacetType.class);
}
public PythonFacetType() {
super(PythonFacet.ID, ID, PyBundle.message("python.facet.name"));
public JavaPythonFacetType() {
super(JavaPythonFacet.ID, ID, PyBundle.message("python.facet.name"));
}
@Override
public PythonFacetConfiguration createDefaultConfiguration() {
PythonFacetConfiguration result = new PythonFacetConfiguration();
public JavaPythonFacetConfiguration createDefaultConfiguration() {
JavaPythonFacetConfiguration result = new JavaPythonFacetConfiguration();
List<Sdk> sdks = ProjectJdkTable.getInstance().getSdksOfType(PythonSdkType.getInstance());
if (sdks.size() > 0) {
result.setSdk(sdks.get(0));
@@ -43,8 +43,8 @@ public final class PythonFacetType extends FacetType<PythonFacet, PythonFacetCon
}
@Override
public PythonFacet createFacet(@NotNull Module module, String name, @NotNull PythonFacetConfiguration configuration, @Nullable Facet underlyingFacet) {
return new PythonFacet(this, module, name, configuration, underlyingFacet);
public JavaPythonFacet createFacet(@NotNull Module module, String name, @NotNull JavaPythonFacetConfiguration configuration, @Nullable Facet underlyingFacet) {
return new JavaPythonFacet(this, module, name, configuration, underlyingFacet);
}
@Override

View File

@@ -1,5 +1,5 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.facet;
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.plugin.java.facet;
import com.intellij.facet.FacetManager;
import com.intellij.facet.ModifiableFacetModel;
@@ -37,7 +37,7 @@ public class PythonFrameworkSupportConfigurable extends FrameworkSupportConfigur
public void addSupport(@NotNull Module module, @NotNull ModifiableRootModel model, @Nullable Library library) {
final FacetManager facetManager = FacetManager.getInstance(module);
ModifiableFacetModel facetModel = facetManager.createModifiableModel();
PythonFacet facet = facetManager.createFacet(PythonFacetType.getInstance(), "Python", null);
JavaPythonFacet facet = facetManager.createFacet(JavaPythonFacetType.getInstance(), "Python", null);
facet.getConfiguration().setSdk(mySdkComboBox.getSelectedSdk());
facetModel.addFacet(facet);
facetModel.commit();

View File

@@ -1,5 +1,5 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.facet;
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.plugin.java.facet;
import com.intellij.facet.FacetManager;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable;
@@ -16,7 +16,7 @@ import javax.swing.*;
public final class PythonFrameworkSupportProvider extends FrameworkSupportProvider {
public PythonFrameworkSupportProvider() {
super("Python", PythonFacetType.getInstance().getPresentableName());
super("Python", JavaPythonFacetType.getInstance().getPresentableName());
}
@Override
@@ -37,6 +37,6 @@ public final class PythonFrameworkSupportProvider extends FrameworkSupportProvid
@Override
public boolean isSupportAlreadyAdded(@NotNull Module module) {
return FacetManager.getInstance(module).getFacetsByType(PythonFacetType.getInstance().getId()).size() > 0;
return FacetManager.getInstance(module).getFacetsByType(JavaPythonFacetType.getInstance().getId()).size() > 0;
}
}

View File

@@ -1,5 +1,5 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.facet;
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.plugin.java.facet;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.python.facet.PythonSdkEditorTab">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.python.community.plugin.java.facet.PythonSdkEditorTab">
<grid id="27dc6" binding="myMainPanel" 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>
@@ -10,7 +10,7 @@
<size top="5" left="10" bottom="10" right="10"/>
</border>
<children>
<component id="5b600" class="com.jetbrains.python.facet.PythonSdkComboBox" binding="mySdkComboBox">
<component id="5b600" class="com.intellij.python.community.plugin.java.facet.PythonSdkComboBox" binding="mySdkComboBox">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>

View File

@@ -1,5 +1,5 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.facet;
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.plugin.java.facet;
import com.intellij.facet.ui.FacetEditorContext;
import com.intellij.facet.ui.FacetEditorTab;
@@ -61,8 +61,8 @@ public class PythonSdkEditorTab extends FacetEditorTab {
return mySdkComboBox.getSelectedSdk() != getFacetConfiguration().getSdk();
}
private PythonFacetConfiguration getFacetConfiguration() {
return ((PythonFacetConfiguration) myEditorContext.getFacet().getConfiguration());
private JavaPythonFacetConfiguration getFacetConfiguration() {
return ((JavaPythonFacetConfiguration) myEditorContext.getFacet().getConfiguration());
}
@Override

View File

@@ -15,8 +15,8 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.psi.search.FileTypeIndex;
import com.jetbrains.python.PyBundle;
import com.jetbrains.python.PythonFileType;
import com.jetbrains.python.facet.PythonFacet;
import com.jetbrains.python.facet.PythonFacetType;
import com.intellij.python.community.plugin.java.facet.JavaPythonFacet;
import com.intellij.python.community.plugin.java.facet.JavaPythonFacetType;
import com.jetbrains.python.sdk.PyDetectedSdk;
import com.jetbrains.python.sdk.PySdkExtKt;
import com.jetbrains.python.sdk.PythonSdkUtil;
@@ -117,7 +117,7 @@ public final class PythonPluginCommandLineInspectionProjectConfigurator implemen
return;
}
final PythonFacetType facetType = PythonFacetType.getInstance();
final JavaPythonFacetType facetType = JavaPythonFacetType.getInstance();
int skippedModules = 0;
for (Module m : ModuleManager.getInstance(project).getModules()) {
if (ReadAction.compute(() -> !FileTypeIndex.containsFileOfType(PythonFileType.INSTANCE, m.getModuleContentScope()))) {
@@ -133,7 +133,7 @@ public final class PythonPluginCommandLineInspectionProjectConfigurator implemen
invokeLaterOnWriteThreadUnderLock(
() -> {
final PythonFacet addedFacet = facetManager.addFacet(facetType, facetType.getPresentableName(), null);
final JavaPythonFacet addedFacet = facetManager.addFacet(facetType, facetType.getPresentableName(), null);
PySdkExtKt.excludeInnerVirtualEnv(m, addedFacet.getConfiguration().getSdk());
}
);

View File

@@ -8,10 +8,10 @@
id="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable"
bundle="messages.PyBundle"
key="configurable.PyActiveSdkModuleConfigurable.python.interpreter.display.name"
instance="com.jetbrains.python.minor.sdk.PyPluginSdkModuleConfigurable"
instance="com.intellij.python.community.plugin.minor.facet.PyPluginSdkModuleConfigurable"
groupWeight="118"/> <!-- id is used in InterpreterSettingsQuickFix.showPythonInterpreterSettings -->
<facetType implementation="com.jetbrains.python.minor.facet.PythonFacetType"/>
<facetType implementation="com.intellij.python.community.plugin.minor.facet.MinorPythonFacetType"/>
</extensions>
</idea-plugin>

View File

@@ -0,0 +1,39 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.plugin.minor.facet;
import com.intellij.facet.Facet;
import com.intellij.facet.FacetType;
import com.intellij.facet.FacetTypeId;
import com.intellij.openapi.module.Module;
import com.jetbrains.python.facet.LibraryContributingFacet;
import com.intellij.python.community.plugin.impl.facet.PythonFacetUtil;
import org.jetbrains.annotations.NotNull;
/**
* This facet is intended to be used in the python plugin for IDEs other then IntelliJ IDEA
*
* @author traff
*/
class MinorPythonFacet extends LibraryContributingFacet<MinorPythonFacetType.PythonFacetConfiguration> {
public static final FacetTypeId<MinorPythonFacet> ID = new FacetTypeId<>("python");
MinorPythonFacet(@NotNull final FacetType facetType, @NotNull final Module module, @NotNull final String name, @NotNull final MinorPythonFacetType.PythonFacetConfiguration configuration,
Facet underlyingFacet) {
super(facetType, module, name, configuration, underlyingFacet);
}
@Override
public void updateLibrary() {
PythonFacetUtil.updateLibrary(getModule(), getConfiguration());
}
@Override
public void removeLibrary() {
PythonFacetUtil.removeLibrary(getModule());
}
@Override
public void initFacet() {
updateLibrary();
}
}

View File

@@ -1,5 +1,5 @@
// 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.minor.facet;
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.plugin.minor.facet;
import com.intellij.facet.Facet;
import com.intellij.facet.FacetConfiguration;
@@ -27,16 +27,16 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.List;
public final class PythonFacetType extends FacetType<PythonFacet, PythonFacetType.PythonFacetConfiguration> {
final class MinorPythonFacetType extends FacetType<MinorPythonFacet, MinorPythonFacetType.PythonFacetConfiguration> {
@NonNls
private static final String ID = "Python";
public static PythonFacetType getInstance() {
return findInstance(PythonFacetType.class);
public static MinorPythonFacetType getInstance() {
return findInstance(MinorPythonFacetType.class);
}
public PythonFacetType() {
super(PythonFacet.ID, ID, PyBundle.message("python.facet.name"));
MinorPythonFacetType() {
super(MinorPythonFacet.ID, ID, PyBundle.message("python.facet.name"));
}
@Override
@@ -50,11 +50,11 @@ public final class PythonFacetType extends FacetType<PythonFacet, PythonFacetTyp
}
@Override
public PythonFacet createFacet(@NotNull Module module,
String name,
@NotNull PythonFacetConfiguration configuration,
@Nullable Facet underlyingFacet) {
return new PythonFacet(this, module, name, configuration, underlyingFacet);
public MinorPythonFacet createFacet(@NotNull Module module,
String name,
@NotNull PythonFacetConfiguration configuration,
@Nullable Facet underlyingFacet) {
return new MinorPythonFacet(this, module, name, configuration, underlyingFacet);
}
@Override

View File

@@ -1,5 +1,5 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.minor.sdk
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.plugin.minor.facet
import com.intellij.facet.FacetManager
import com.intellij.openapi.application.ApplicationManager
@@ -10,17 +10,17 @@ import com.intellij.openapi.projectRoots.Sdk
import com.jetbrains.python.configuration.PyActiveSdkConfigurable
import com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable
import com.intellij.python.community.plugin.impl.facet.PythonFacetUtil
import com.jetbrains.python.minor.facet.PythonFacet
import com.jetbrains.python.minor.facet.PythonFacetType
import com.intellij.python.community.plugin.minor.facet.MinorPythonFacet
import com.intellij.python.community.plugin.minor.facet.MinorPythonFacetType
import com.jetbrains.python.sdk.removeTransferredRoots
import com.jetbrains.python.sdk.transferRoots
class PyPluginSdkModuleConfigurable(project: Project?) : PyActiveSdkModuleConfigurable(project) {
internal class PyPluginSdkModuleConfigurable(project: Project?) : PyActiveSdkModuleConfigurable(project) {
override fun createModuleConfigurable(module: Module): UnnamedConfigurable {
return object : PyActiveSdkConfigurable(module) {
override fun setSdk(item: Sdk?) {
val facetManager = FacetManager.getInstance(module)
val facet = facetManager.getFacetByType(PythonFacet.ID)
val facet = facetManager.getFacetByType(MinorPythonFacet.ID)
if (facet == null) {
ApplicationManager.getApplication().runWriteAction {
addFacet(facetManager, item, module)
@@ -34,13 +34,13 @@ class PyPluginSdkModuleConfigurable(project: Project?) : PyActiveSdkModuleConfig
override fun getSdk(): Sdk? {
val facetManager = FacetManager.getInstance(module)
val facet = facetManager.getFacetByType(PythonFacet.ID)
val facet = facetManager.getFacetByType(MinorPythonFacet.ID)
return facet?.configuration?.sdk
}
}
}
private fun setFacetSdk(facet: PythonFacet,
private fun setFacetSdk(facet: MinorPythonFacet,
item: Sdk?,
module: Module) {
removeTransferredRoots(module, facet.configuration.sdk)
@@ -54,7 +54,8 @@ class PyPluginSdkModuleConfigurable(project: Project?) : PyActiveSdkModuleConfig
private fun addFacet(facetManager: FacetManager,
sdk: Sdk?,
module: Module) {
val facet = facetManager.addFacet(PythonFacetType.getInstance(), "Python facet", null)
val facet = facetManager.addFacet(
MinorPythonFacetType.getInstance(), "Python facet", null)
setFacetSdk(facet, sdk, module)
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2000-2017 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.minor.facet;
import com.intellij.facet.Facet;
import com.intellij.facet.FacetType;
import com.intellij.facet.FacetTypeId;
import com.intellij.openapi.module.Module;
import com.jetbrains.python.facet.LibraryContributingFacet;
import com.intellij.python.community.plugin.impl.facet.PythonFacetUtil;
import org.jetbrains.annotations.NotNull;
/**
* This facet is intended to be used in the python plugin for IDEs other then IntelliJ IDEA
*
* @author traff
*/
public class PythonFacet extends LibraryContributingFacet<PythonFacetType.PythonFacetConfiguration> {
public static final FacetTypeId<PythonFacet> ID = new FacetTypeId<>("python");
public PythonFacet(@NotNull final FacetType facetType, @NotNull final Module module, @NotNull final String name, @NotNull final PythonFacetType.PythonFacetConfiguration configuration,
Facet underlyingFacet) {
super(facetType, module, name, configuration, underlyingFacet);
}
@Override
public void updateLibrary() {
PythonFacetUtil.updateLibrary(getModule(), getConfiguration());
}
@Override
public void removeLibrary() {
PythonFacetUtil.removeLibrary(getModule());
}
@Override
public void initFacet() {
updateLibrary();
}
}