PY-49267 Packaging(partial): Visually mark packages installed in the editable mode. Need fix from package team

GitOrigin-RevId: 73976f93ddb8e63f58f81c5ee9cd3464b2b34c36
This commit is contained in:
Nikita.Ashihmin
2024-09-02 12:09:22 +00:00
committed by intellij-monorepo-bot
parent d4a3b2095a
commit e9697a6336
8 changed files with 31 additions and 8 deletions
@@ -59,7 +59,7 @@ class PythonPackageManagementServiceBridge(project: Project,sdk: Sdk) : PyPackag
.filter { it.isNotBlank() }
.map {
val line = it.split("\t")
PythonPackage(line[0], line[1])
PythonPackage(line[0], line[1], isEditableMode = false)
}
.sortedWith(compareBy(PythonPackage::name))
.toList()
@@ -8,7 +8,7 @@ import com.jetbrains.python.packaging.repository.PyPackageRepository
import com.jetbrains.python.packaging.requirement.PyRequirementRelation
import org.jetbrains.annotations.Nls
open class PythonPackage(val name: String, val version: String) {
open class PythonPackage(val name: String, val version: String, val isEditableMode: Boolean) {
override fun toString(): String {
return "PythonPackage(name='$name', version='$version')"
}
@@ -93,7 +93,8 @@ class CondaPackageManager(project: Project, sdk: Sdk) : PipBasedPackageManager(p
.filterNot { it.startsWith("#") }
.map { line -> line.split("\\s+".toRegex()) }
.filterNot { it.size < 2 }
.map { CondaPackage(it[0], it[1], installedWithPip = (it.size >= 4 && it[3] == "pypi")) }
//TODO: fix
.map { CondaPackage(it[0], it[1], editableMode = false, installedWithPip = (it.size >= 4 && it[3] == "pypi")) }
.sortedWith(compareBy(CondaPackage::name))
.toList()
}
@@ -8,7 +8,11 @@ import com.jetbrains.python.packaging.common.PythonPackageSpecificationBase
import com.jetbrains.python.packaging.repository.PyPackageRepository
import com.jetbrains.python.packaging.requirement.PyRequirementRelation
class CondaPackage(name: String, version: String, val installedWithPip: Boolean = false) : PythonPackage(name, version) {
class CondaPackage(
name: String, version: String,
editableMode: Boolean,
val installedWithPip: Boolean = false,
) : PythonPackage(name, version, editableMode) {
override fun toString(): String {
return "CondaPackage(name='$name', version='$version', installedWithPip=$installedWithPip)"
}
@@ -29,7 +29,7 @@ class PipPythonPackageManager(project: Project, sdk: Sdk) : PipBasedPackageManag
.filter { it.isNotBlank() }
.map {
val line = it.split("\t")
PythonPackage(line[0], line[1])
PythonPackage(line[0], line[1], isEditableMode = false)
}
.sortedWith(compareBy(PythonPackage::name))
.toList()
@@ -1,9 +1,12 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.packaging.toolwindow
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.service
import com.intellij.openapi.module.Module
import com.intellij.openapi.util.Disposer
import com.intellij.platform.ModuleAttachListener
import com.jetbrains.python.packaging.utils.PyPackageCoroutine
import java.nio.file.Path
class PyPackagesToolWindowModuleAttachListener : ModuleAttachListener {
@@ -13,5 +16,14 @@ class PyPackagesToolWindowModuleAttachListener : ModuleAttachListener {
}
}
override fun beforeDetach(module: Module) {
@Suppress("IncorrectParentDisposable")
//We do not have function after detach so this is small trick
Disposer.register(module, Disposable {
PyPackageCoroutine.launch(module.project) {
module.project.service<PyPackagingToolWindowService>().moduleAttached()
}
})
}
}
@@ -17,7 +17,8 @@ sealed class DisplayablePackage(@NlsSafe val name: String, val repository: PyPac
class InstalledPackage(val instance: PythonPackage, repository: PyPackageRepository, val nextVersion: PyPackageVersion? = null) : DisplayablePackage(instance.name, repository) {
val currentVersion = PyPackageVersionNormalizer.normalize(instance.version)
val icon: Icon?
val isEditMode = instance.isEditableMode
val sourceRepoIcon: Icon?
get() {
val condaPackage = instance as? CondaPackage ?: return null
return if (condaPackage.installedWithPip) {
@@ -1,7 +1,9 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.packaging.toolwindow.packages
import com.intellij.icons.AllIcons
import com.intellij.openapi.util.NlsSafe
import com.intellij.ui.components.JBLabel
import com.intellij.ui.hover.TableHoverListener
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.UIUtil
@@ -21,7 +23,7 @@ import javax.swing.JTable
import javax.swing.table.DefaultTableCellRenderer
internal class PyPaginationAwareRenderer : DefaultTableCellRenderer() {
private val nameLabel = JLabel().apply { border = JBUI.Borders.empty(0, 12) }
private val nameLabel = JBLabel().apply { border = JBUI.Borders.empty(0, 12) }
private val versionLabel = JLabel().apply { border = JBUI.Borders.emptyRight(12) }
@@ -88,7 +90,7 @@ internal class PyPaginationAwareRenderer : DefaultTableCellRenderer() {
versionLabel.text = version
versionPanel.add(versionLabel)
}
versionLabel.icon = (value as? InstalledPackage)?.icon
versionLabel.icon = (value as? InstalledPackage)?.sourceRepoIcon
return versionPanel
}
@@ -99,7 +101,10 @@ internal class PyPaginationAwareRenderer : DefaultTableCellRenderer() {
namePanel.foreground = JBUI.CurrentTheme.Table.foreground(rowSelected, tableFocused)
nameLabel.text = currentPackage.name
val isEditMode = (currentPackage as? InstalledPackage)?.isEditMode == true
nameLabel.icon = if (isEditMode) AllIcons.Actions.Edit else null
nameLabel.foreground = JBUI.CurrentTheme.Label.foreground()
return namePanel
}