This repository has been archived by the owner on Feb 9, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from koxudaxi/add_version_inspection
[WIP] add a version inspection
- Loading branch information
Showing
9 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
<idea-plugin url="https://github.com/koxudaxi/poetry-pycharm-plugin"> | ||
<id>com.koxudaxi.poetry</id> | ||
<name>Poetry</name> | ||
<version>0.1.1</version> | ||
<version>0.1.2</version> | ||
<vendor email="[email protected]">Koudai Aono @koxudaxi</vendor> | ||
<change-notes><![CDATA[ | ||
<h2>version 0.1.2</h2> | ||
<p>Features</p> | ||
<ul> | ||
<li>Add a version inspection [#85]</li> | ||
</ul> | ||
<h2>version 0.1.1</h2> | ||
<p>Features</p> | ||
<ul> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.koxudaxi.poetry | ||
|
||
import com.intellij.codeInspection.* | ||
import com.intellij.openapi.module.Module | ||
import com.intellij.openapi.module.ModuleManager | ||
import com.intellij.openapi.module.ModuleUtilCore | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiElementVisitor | ||
import com.intellij.psi.PsiFile | ||
import com.jetbrains.python.sdk.* | ||
import org.toml.lang.psi.* | ||
|
||
class PoetryVersionInspection : LocalInspectionTool() { | ||
override fun buildVisitor(holder: ProblemsHolder, | ||
isOnTheFly: Boolean, | ||
session: LocalInspectionToolSession): PsiElementVisitor { | ||
return PoetryFileVisitor(holder, session) | ||
} | ||
|
||
class PoetryFileVisitor(val holder: ProblemsHolder, | ||
session: LocalInspectionToolSession) : PsiElementVisitor() { | ||
private fun guessModule(element: PsiElement): Module? { | ||
return ModuleUtilCore.findModuleForPsiElement(element) | ||
?: ModuleManager.getInstance(element.project).modules.let { if (it.size != 1) null else it[0] } | ||
} | ||
|
||
override fun visitFile(file: PsiFile) { | ||
val module = guessModule(file) ?: return | ||
val sdk = PythonSdkUtil.findPythonSdk(module) ?: return | ||
if (!isPoetry(file.project, sdk)) return | ||
if (file.virtualFile != module.pyProjectToml) return | ||
file.children | ||
.filter { element -> | ||
(element as? TomlTable)?.header?.names?.joinToString(".") { it.text } in listOf("tool.poetry.dependencies", "tool.poetry.dev-dependencies") | ||
}.flatMap { | ||
it.children.mapNotNull { line -> line as? TomlKeyValue } | ||
}.forEach { keyValue -> | ||
val packageName = keyValue.key.text | ||
val outdatedVersion = PyPoetryPackageManager.getInstance(sdk).getOutdatedPackages()[packageName] | ||
if (outdatedVersion is PoetryOutdatedVersion) { | ||
val message = "'${packageName}' version ${outdatedVersion.currentVersion} is outdated (latest: ${outdatedVersion.latestVersion})" | ||
holder.registerProblem(keyValue, message, ProblemHighlightType.WARNING) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
boto3 1.13.26 1.14.38 The AWS SDK for Python | ||
botocore 1.16.26 1.17.38 Low-level, data-driven core of boto 3. | ||
docutils 0.15.2 0.16 Docutils -- Python Documentation Utilities | ||
pydantic 1.4 1.6.1 Data validation and settings management using python 3.6 type hinting | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters