Skip to content

Commit

Permalink
Support 243-EAP (#1017)
Browse files Browse the repository at this point in the history
* Support 243-EAP

* Add typing stub

* update unittest

* update unittest

* update unittest

* update unittest

* update unittest

* update unittest

* update unittest

* bump version
  • Loading branch information
koxudaxi authored Nov 10, 2024
1 parent ff0d651 commit 5e95702
Show file tree
Hide file tree
Showing 47 changed files with 180 additions and 148 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## [Unreleased]
- Support 243-EAP [[#1017](https://github.com/koxudaxi/pydantic-pycharm-plugin/pull/1017)]

## [0.4.15] - 2024-09-03

Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ dependencies {
compileOnly(group = "org.ini4j", name = "ini4j", version = "0.5.4")
testImplementation(kotlin("test"))
testImplementation(libs.junit)
testImplementation(libs.opentest4j)
intellijPlatform {
val type = properties("platformType")
val version = properties("platformVersion")
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pluginGroup = com.koxudaxi.pydantic
pluginName = Pydantic
pluginRepositoryUrl = https://github.com/koxudaxi/pydantic-pycharm-plugin
# SemVer format -> https://semver.org
pluginVersion = 0.4.15
pluginVersion = 0.4.16

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 241.17890
pluginUntilBuild = 242.*
pluginUntilBuild = 243.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = PC
platformVersion = 2024.2.1
platformVersion = 243-EAP-SNAPSHOT

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# libraries
annotations = "24.1.0"
junit = "5.8.1"

opentest4j = "1.3.0"
# plugins
kotlin = "1.9.23"
changelog = "2.2.0"
Expand All @@ -13,6 +13,7 @@ kover = "0.7.5"
[libraries]
annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }
junit = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" }
opentest4j = { group = "org.opentest4j", name = "opentest4j", version.ref = "opentest4j"}

[plugins]
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
Expand Down
5 changes: 3 additions & 2 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@

<lang.inspectionSuppressor language="Python"
implementationClass="com.koxudaxi.pydantic.PydanticTypeIgnoreInspectionSuppressor"/>

</extensions>
<projectListeners>
<listener class="com.koxudaxi.pydantic.PydanticPackageManagerListener"
topic="com.jetbrains.python.packaging.PyPackageManager$Listener"/>
<listener class="com.koxudaxi.pydantic.PydanticPythonPackageManagementListener"
topic="com.jetbrains.python.packaging.common.PythonPackageManagementListener"/>
</projectListeners>
<extensions defaultExtensionNs="Pythonid">
<typeProvider implementation="com.koxudaxi.pydantic.PydanticTypeProvider"/>
Expand Down
7 changes: 3 additions & 4 deletions src/com/koxudaxi/pydantic/Pydantic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.jetbrains.python.extensions.QNameResolveContext
import com.jetbrains.python.extensions.resolveToElement
import com.jetbrains.python.PyNames
import com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider
import com.jetbrains.python.packaging.PyPackageManagers
import com.jetbrains.python.packaging.management.PythonPackageManager.Companion.forSdk
import com.jetbrains.python.psi.*
import com.jetbrains.python.psi.impl.PyEvaluator
import com.jetbrains.python.psi.impl.PyTargetExpressionImpl
Expand Down Expand Up @@ -824,9 +824,8 @@ fun PyCallableType.getPydanticModel(includeDataclass: Boolean, context: TypeEval
val KotlinVersion?.isV2: Boolean
get() = this?.isAtLeast(2, 0) == true

val Sdk.pydanticVersion: String?
get() = PyPackageManagers.getInstance()
.forSdk(this).packages?.find { it.name == "pydantic" }?.version
fun getPydanticVersion(project: Project, sdk: Sdk): String? =
forSdk(project, sdk).installedPackages.find { it.name == "pydantic" }?.version

internal fun isInInit(field: PyTargetExpression): Boolean {
val assignedValue = field.findAssignedValue() as? PyCallExpression ?: return true
Expand Down
2 changes: 1 addition & 1 deletion src/com/koxudaxi/pydantic/PydanticCacheService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PydanticCacheService(val project: Project) {
}
private fun getVersion(): KotlinVersion? {
val sdk = project.pythonSdk ?: return null
val versionString = sdk.pydanticVersion ?: return null
val versionString = getPydanticVersion(project, sdk) ?: return null
return getOrPutVersionFromVersionCache(versionString)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
package com.koxudaxi.pydantic

import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.util.Disposer
import com.jetbrains.python.packaging.PyPackageManager
import com.jetbrains.python.packaging.common.PythonPackageManagementListener
import com.jetbrains.python.sdk.PythonSdkUtil
import com.jetbrains.python.sdk.PythonSdkUtil.isDisposed
import com.jetbrains.python.statistics.sdks

class PydanticPackageManagerListener : PyPackageManager.Listener {
class PydanticPythonPackageManagementListener : PythonPackageManagementListener {
private fun updateVersion(sdk: Sdk) {
val version = sdk.pydanticVersion
ProjectManager.getInstance().openProjects
.filter { it.sdks.contains(sdk) }
.forEach {
PydanticCacheService.clear(it)
val version = getPydanticVersion(it, sdk)
if (version is String) {
PydanticCacheService.getOrPutVersionFromVersionCache(it, version)
}
}
}

override fun packagesRefreshed(sdk: Sdk) {
override fun packagesChanged(sdk: Sdk) {
ApplicationManager.getApplication().invokeLater {
if (sdk is Disposable && Disposer.isDisposed(sdk)) {
if (isDisposed(sdk)) {
return@invokeLater
}

Expand All @@ -35,7 +34,7 @@ class PydanticPackageManagerListener : PyPackageManager.Listener {
updateVersion(sdk)
} else {
runWriteAction {
if (sdk is Disposable && Disposer.isDisposed(sdk)) {
if (isDisposed(sdk)) {
return@runWriteAction
}
try {
Expand All @@ -50,4 +49,5 @@ class PydanticPackageManagerListener : PyPackageManager.Listener {
}
}
}

}
4 changes: 2 additions & 2 deletions testData/completion/assignedClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class A(BaseModel):
abc: str
cde = str('abc')
efg: str = str('abc')
cde = 'abc'
efg: str = 'abc'

class B(A):
hij: str
Expand Down
4 changes: 2 additions & 2 deletions testData/completion/assignedInstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class A(BaseModel):
abc: str
cde = str('abc')
efg: str = str('abc')
cde = 'abc'
efg: str = 'abc'

class B(A):
hij: str
Expand Down
4 changes: 2 additions & 2 deletions testData/completion/assignedInstancePythonClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class A:
abc: str
cde = str('abc')
efg: str = str('abc')
cde = 'abc'
efg: str = 'abc'

class B(A):
hij: str
Expand Down
4 changes: 2 additions & 2 deletions testData/completion/class.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class B:

class A(BaseModel, B):
abc: str
cde = str('abc')
efg: str = str('abc')
cde = 'abc'
efg: str = 'abc'


A.<caret>
4 changes: 2 additions & 2 deletions testData/completion/classFields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class A(BaseModel):
abc: str
cde = str('abc')
efg: str = str('abc')
cde = 'abc'
efg: str = 'abc'

class B(A):
hij: str
Expand Down
2 changes: 1 addition & 1 deletion testData/completion/conlist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

from typing import List
from pydantic import BaseModel
from pydantic.types import conlist

Expand Down
2 changes: 1 addition & 1 deletion testData/completion/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class A(BaseModel):
abc: str
cde = str('abc')
cde = 'abc'
efg: str = ...
hij = ...

Expand Down
4 changes: 2 additions & 2 deletions testData/completion/fieldField.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def get_alias():
b_id = 'alias_b_id'
class A(BaseModel):
abc: str = Field(...)
cde = Field(str('abc'))
efg = Field(default=str('abc'))
cde = Field('abc')
efg = Field(default='abc')
hij = Field(default=...)
a_id: str = Field(..., alias='alias_a_id')
b_id: str = Field(..., alias=b_id)
Expand Down
12 changes: 6 additions & 6 deletions testData/completion/fieldIgnore.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ def __get__(self, instance, owner):
return owner

class A(BaseModel):
_abc: str = str('abc')
__cde: str = str('abc')
efg: ClassVar[str] = str('abc')
_abc: str = 'abc'
__cde: str = 'abc'
efg: ClassVar[str] = 'abc'
class Config:
keep_untouched = (Descriptor,)

descriptor1 = Descriptor()

class B(A):
_efg: str = str('abc')
__hij: str = str('abc')
klm: ClassVar[str] = str('abc')
_efg: str = 'abc'
__hij: str = 'abc'
klm: ClassVar[str] = 'abc'
class Config:
keep_untouched = (Descriptor,)

Expand Down
4 changes: 2 additions & 2 deletions testData/completion/fieldOptional.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class A(BaseModel):
abc: Optional[str]
cde = str('abc')
efg: str = str('abc')
cde = 'abc'
efg: str = 'abc'

class B(A):
hij: str
Expand Down
4 changes: 2 additions & 2 deletions testData/completion/fieldSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def get_alias():
b_id = 'alias_b_id'
class A(BaseModel):
abc: str = Schema(...)
cde = Schema(str('abc'))
efg = Schema(default=str('abc'))
cde = Schema('abc')
efg = Schema(default='abc')
hij = Schema(default=...)
a_id: str = Schema(..., alias='alias_a_id')
b_id: str = Schema(..., alias=b_id)
Expand Down
4 changes: 2 additions & 2 deletions testData/completion/fieldSchemaField.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def get_alias():
b_id = 'alias_b_id'
class A(BaseModel):
abc: str = Field(...)
cde = Field(str('abc'))
efg = Field(default=str('abc'))
cde = Field('abc')
efg = Field(default='abc')
hij = Field(default=...)
a_id: str = Field(..., alias='alias_a_id')
b_id: str = Field(..., alias=b_id)
Expand Down
4 changes: 2 additions & 2 deletions testData/completion/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class A(BaseModel):
abc: str
cde = str('abc')
efg: str = str('abc')
cde = 'abc'
efg: str = 'abc'

class B(A):
hij: str
Expand Down
6 changes: 3 additions & 3 deletions testData/completion/keywordArgumentIgnore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@


class A(BaseModel):
_abc: str = str('abc')
__cde: str = str('abc')
_abc: str = 'abc'
__cde: str = 'abc'


class B(A):
_efg: str = str('abc')
_efg: str = 'abc'
__hij: str = 1

B(<caret>)
4 changes: 2 additions & 2 deletions testData/completion/keywordArgumentSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def get_alias():
b_id: str = 'alias_b_id'
class A(BaseModel):
abc: str = Schema(...)
cde = Schema(str('abc'))
efg = Schema(default=str('abc'))
cde = Schema('abc')
efg = Schema(default='abc')
hij = Schema(default=...)
a_id: str = Schema(..., alias='alias_a_id')
b_id: str = Schema(..., alias=b_id)
Expand Down
4 changes: 2 additions & 2 deletions testData/completion/keywordArgumentSchemaField.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def get_alias():
b_id: str = 'alias_b_id'
class A(BaseModel):
abc: str = Field(...)
cde = Field(str('abc'))
efg = Field(default=str('abc'))
cde = Field('abc')
efg = Field(default='abc')
hij = Field(default=...)
a_id: str = Field(..., alias='alias_a_id')
b_id: str = Field(..., alias=b_id)
Expand Down
4 changes: 2 additions & 2 deletions testData/completion/parameterAnnotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class A(BaseModel):
abc: str
cde: str = str('abc')
efg: str = str('abc')
cde: str = 'abc'
efg: str = 'abc'


def get_a(a: A):
Expand Down
4 changes: 2 additions & 2 deletions testData/completion/parameterAnnotationPythonClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class A:
abc: str
cde: str = str('abc')
efg: str = str('abc')
cde: str = 'abc'
efg: str = 'abc'


def get_a(a: A):
Expand Down
4 changes: 2 additions & 2 deletions testData/completion/parameterAnnotationType.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

class A(BaseModel):
abc: str
cde: str = str('abc')
efg: str = str('abc')
cde: str = 'abc'
efg: str = 'abc'


def get_a(a: Type[A]):
Expand Down
4 changes: 2 additions & 2 deletions testData/completion/parameterAnnotationTypeKeywordArgument.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

class A(BaseModel):
abc: str
cde: str = str('abc')
efg: str = str('abc')
cde: str = 'abc'
efg: str = 'abc'


def get_a(a: Type[A]):
Expand Down
4 changes: 2 additions & 2 deletions testData/completion/parameterAnnotationUnion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class A(BaseModel):
abc: str
cde: str = str('abc')
efg: str = str('abc')
cde: str = 'abc'
efg: str = 'abc'


def get_a(a: Union[A, str]):
Expand Down
Loading

0 comments on commit 5e95702

Please sign in to comment.