leinardi / pylint-pycharm

A plugin providing both real-time and on-demand scanning of Python files with PyLint from within PyCharm/IDEA.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flake8 support

ramast opened this issue · comments

Is your feature request related to a problem? Please describe.
I want to use flake8 instead of pylint

Describe the solution you'd like
Allow choosing between flake8 and pylint

Describe alternatives you've considered
Before I opened this issue, I wanted to make a proof of concept to see how easy/difficult would it be to run flake8 using this plugin. I wrote a simple flake report formatter to produce json output that match the output you expect from pylint. Then I changed pylint executable to run flake8 instead after correcting the parameters (i.e --format=json instead of -f json). The plugin worked flawlessly.

Additional context
Flake allows passing its output format as parameters like that

flake8 --format="%(path)s:%(row)d:%(col)d:%(code)s:%(text)s"

Then you get output like that

orders/models.py:105:9:F841:local variable 'c' is assigned to but never used
orders/models.py:105:9:WPS111:Found too short name: c < 2
orders/models.py:107:12:F821:undefined name 'z'

In python (I don't know Java very well), It can be parsed in one line

path, line, column, message_id, message =  violation_line.split(":", maxsplit=4)

Also --rc-file parameter is to be replaced with --config parameter

Hi I have just followed your repo and installed the plugin. Does it provide autocorrect?

Original pylint plugin for pycharm (this repo) doesn't offer autocorrect so my code also won't offer it.

@leinardi while I can see this feature request being a bit of a "can you change the core functionality of the thing you designed", I too find myself looking for a flake8 comparable solution.
My team uses flake8, pylint, mypy, and bandit for our static analysis. This pylint tool is the best option for any of the scanners.

What is your interest in the other static analysis tools? It is something you would be willing to fold into this app, or would you rather see this repo forked?

I may give a fork a chance for flake8. I have never done an jetbrains extension... but (based on what i dont know...) this seems like a PyLint replace all with Flake8 may get quite close.

@dciborow before considering a fork, please have a look at my solution. Maybe you'd want to contribute to it instead.

https://gitlab.com/ramast/flake8-for-pycharm

Hi @dciborow, I am full time Android developer and Linux user. Some years ago I decided to write GUI apps for Linux and opted for GTK as UI framework. Since I'm not familiar at all with C++ and I was not aware of Vala, I decided to go with Python as language for the apps.
On Android I have a lot of very useful static analysis tools and plugins for Intellij IDEA/Android Studio (Checkstyle-IDEA, detekt, Android Lint just to name few). I found very useful static analysis tools for Python but the Plugin support for PyCharm was either lacking completely or very basic.
Since, back then, I had some time to spare, I decided to fork Checkstyle-IDEA and try to support pylint and mypy. I managed to do it but I built these 2 plugins only because I needed them and made them public because I think can still be useful for other developers with same needs I have. But unfortunately I cannot afford to implement new features for them (if you check the issue trackers of the 2 projects, plenty of people is asking to add support for remote environments or similar stuff).

In shorts would be way better if you guys can fork the project and implement proper support for flake8. It could be also a chance to collaborate and work together on very similar code bases (currently I am the only maintainer for both pylint and mypy plugin and this is also a problem): unless you go with a full rewrite, we should be able to exchange patches for probably 90% of the code base.

If you decide to fork I can try provide support to get the plugin running with flack8, but should be clear that then you'll have to take over the maintenance of the project after we have done.

@ramast , will check this out thanks! But what I really have in mind is something that is even more generic, which would just let you select which tools you want to add, and what the config is for them. A super quick glance and it looks like the main input arg is the cli command for the config file.

@leinardi sounds good. Fully understand your current state. If I did get time and starting tearing things apart, wanted to make sure you had at least heard about and perhaps blessed a path forward.

Now the only issue i have is that locally my system isnt sure if it wants java8 or java11....
Do you happen to know which JDK was used to create this ?

@ramast , it looks like you have monkey patched over the orginal app. I need pylint AND flake8 working together...

@dciborow no monkey patching. Basically @leinardi's plugin calls pylint and uses its output to show errors on the IDE. My solution is to write a script that behave exactly like pylint (take same arguments and return same output format) as far as plugin is concerned it's still communicating with pylint.

Behind the scense the script transform pylint's arguments into flake8 arguments, run flake8 and once again translate flake8 output into an output similar to what pylint produces.

@ramast , does your extension "add" flake8 output? Or "replace" pylint with flake8?

@leinardi ,

Actually opening it back up, this is the problem i am getting when I run the build-assemble task. Anything you remember would be fanastic!
image

I built it with this JDK:

$ java -version
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~20.04-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)

Check the RELEASING.md file: you should run the task buildPlugin.

./gradlew clean buildPlugin

@dciborow it replace pylint output but it can be easily modified to include pylint output as well. You can also modify it to get errors from other sources or produce your own errors

Still missing this idea/ApplicationInfo.xml
image
Perhaps I need to try on linux

Can you please try to run on a terminal ./gradlew clean buildPlugin? Post also java -version output.

C:\Users\dcibo\pylint-flake8>java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)

C:\Users\dcibo\pylint-flake8>gradlew clean buildPlugin

> Task :buildSearchableOptions
2020-10-28 17:08:38,104 [    188]  ERROR - oncurrency.BoundedTaskExecutor - Resource not found: /idea/ApplicationInfo.xml
java.lang.RuntimeException: Resource not found: /idea/ApplicationInfo.xml
        at com.intellij.openapi.application.ApplicationNamesInfo.loadData(ApplicationNamesInfo.java:29)
        at com.intellij.openapi.application.ApplicationNamesInfo.initAndGetRawData(ApplicationNamesInfo.java:44)
        at com.intellij.openapi.application.impl.ApplicationInfoImpl.getShadowInstance(ApplicationInfoImpl.java:447)
        at com.intellij.idea.StartupUtil.lambda$prepareApp$4(StartupUtil.java:231)
        at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:215)
        at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:26)
        at com.intellij.util.concurrency.BoundedTaskExecutor$1.execute(BoundedTaskExecutor.java:194)
        at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:186)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:652)
        at java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:649)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:649)
        at java.lang.Thread.run(Thread.java:748)
2020-10-28 17:08:38,318 [    402]   WARN - llij.ide.plugins.PluginManager - Resource bundle redefinition for plugin 'com.jetbrains.pycharm.pro.customization'. Old value: messages.ActionsBundle, new value: messages.PyBundle
2020-10-28 17:08:38,611 [    695]  ERROR - llij.ide.plugins.PluginManager - Resource not found: /idea/ApplicationInfo.xml
java.lang.RuntimeException: Resource not found: /idea/ApplicationInfo.xml
        at com.intellij.openapi.application.ApplicationNamesInfo.loadData(ApplicationNamesInfo.java:29)
        at com.intellij.openapi.application.ApplicationNamesInfo.initAndGetRawData(ApplicationNamesInfo.java:44)
        at com.intellij.openapi.application.impl.ApplicationInfoImpl.getShadowInstance(ApplicationInfoImpl.java:447)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.intellij.idea.MainImpl.a(MainImpl.java:113)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.intellij.idea.MainImpl.start(MainImpl.java:96)
        at com.intellij.idea.StartupUtil.startApp(StartupUtil.java:302)
        at com.intellij.idea.StartupUtil.prepareApp(StartupUtil.java:242)
        at com.intellij.ide.plugins.MainRunner.lambda$start$0(MainRunner.java:47)
        at java.lang.Thread.run(Thread.java:748)

Start Failed: Internal error. Please refer to http://jb.gg/ide/critical-startup-errors

java.lang.RuntimeException: Resource not found: /idea/ApplicationInfo.xml
        at com.intellij.openapi.application.ApplicationNamesInfo.loadData(ApplicationNamesInfo.java:29)
        at com.intellij.openapi.application.ApplicationNamesInfo.initAndGetRawData(ApplicationNamesInfo.java:44)
        at com.intellij.openapi.application.impl.ApplicationInfoImpl.getShadowInstance(ApplicationInfoImpl.java:447)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.intellij.idea.MainImpl.a(MainImpl.java:113)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.intellij.idea.MainImpl.start(MainImpl.java:96)
        at com.intellij.idea.StartupUtil.startApp(StartupUtil.java:302)
        at com.intellij.idea.StartupUtil.prepareApp(StartupUtil.java:242)
        at com.intellij.ide.plugins.MainRunner.lambda$start$0(MainRunner.java:47)
        at java.lang.Thread.run(Thread.java:748)

-----
JRE 1.8.0_265-b01 amd64 by Amazon.com Inc.
C:\Users\dcibo\.jdks\corretto-1.8.0_265\jre

> Task :buildSearchableOptions FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildSearchableOptions'.
> Process 'command 'C:\Users\dcibo\.jdks\corretto-1.8.0_265\bin\java.exe'' finished with non-zero exit value 3

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 20s
9 actionable tasks: 9 executed

No clue :( Probably better to check if you get the same error on Linux.

its already looking better in WSL
image

Ill take new issues at least!
image

image

image

I feel very close....

Nice! I think you built it! Try with the runIde task (not 100% sure about the task name, don't have the PC to check right now).

I'm also going to bed, I'll check your progress tomorrow :)

Thanks, super helpful pointer there with "runIde"

@dciborow What is the current state of your migration attempts? Are you still working on it? It seems like dciborow/flake8-pycharm might be the intended repository, but is it empty for now.

Having a corresponding plugin would make it much easier to run flake8 automatically for each file. The current integration with the File Watchers plugin requires unnecessary effort to actually set it up. The solution from @ramast unfortunately does not work in my setup due to some conflicts which are out of scope here.