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

Absolute paths do not seem to work for pylint executable discovery

harrison-aw opened this issue · comments

Step 1: Are you in the right place?

  • I have verified there are no duplicate active or recent bugs, questions, or requests
  • I have verified that I am using the latest version of the plugin.

Step 2: Describe your environment

  • Plugin version: 0.11.0
  • PyCharm/IDEA version: Pycharm 2019.1.3
  • Pylint version: 2.3.1

Step 3: Describe the problem:

Steps to reproduce:

  1. Python project uses a virtual environment
  2. An absolute path is given to the pylint plugin (either manually or automatically)
  3. It is unable to find the executable.

Observed Results:

  • The executable was not found, it seems to expect a relative path based on the project source, not an absolute path
java.lang.Throwable: Error while checking Pylint path D:/repos/daydream3.5\D:/python_venv/daydream3.5/Scripts/pylint.exe: null or not exists
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:145)
	at com.leinardi.pycharm.pylint.plapi.PylintRunner.isPylintPathValid(PylintRunner.java:85)
	at com.leinardi.pycharm.pylint.plapi.PylintRunner.checkPylintAvailable(PylintRunner.java:177)
	at com.leinardi.pycharm.pylint.plapi.PylintRunner.scan(PylintRunner.java:230)
	at com.leinardi.pycharm.pylint.checker.ScanFiles.scan(ScanFiles.java:108)
	at com.leinardi.pycharm.pylint.checker.ScanFiles.checkFiles(ScanFiles.java:100)
	at com.leinardi.pycharm.pylint.checker.ScanFiles.call(ScanFiles.java:74)
	at com.leinardi.pycharm.pylint.checker.ScanFiles.call(ScanFiles.java:46)
	at com.intellij.openapi.application.impl.ApplicationImpl$2.call(ApplicationImpl.java:339)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

Expected Results:

  • The executable should have been found

Same on Mac OS with the following log:

java.lang.Throwable: Pylint path check process.exitValue: 1
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:145)
	at com.leinardi.pycharm.pylint.plapi.PylintRunner.isPylintPathValid(PylintRunner.java:108)
	at com.leinardi.pycharm.pylint.ui.PylintConfigPanel$TestAction.actionPerformed(PylintConfigPanel.java:115)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6651)
	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
	at java.desktop/java.awt.Component.processEvent(Component.java:6416)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5026)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4858)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4858)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:778)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:751)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:749)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:748)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:873)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:818)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:461)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:693)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:460)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:117)
	at java.desktop/java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:190)
	at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:235)
	at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:233)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.desktop/java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:233)
	at java.desktop/java.awt.Dialog.show(Dialog.java:1063)
	at com.intellij.openapi.ui.impl.DialogWrapperPeerImpl$MyDialog.show(DialogWrapperPeerImpl.java:707)
	at com.intellij.openapi.ui.impl.DialogWrapperPeerImpl.show(DialogWrapperPeerImpl.java:432)
	at com.intellij.openapi.ui.DialogWrapper.doShow(DialogWrapper.java:1685)
	at com.intellij.openapi.ui.DialogWrapper.show(DialogWrapper.java:1644)
	at com.intellij.openapi.options.newEditor.SettingsDialog.lambda$show$0(SettingsDialog.java:76)
	at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:82)
	at com.intellij.openapi.application.TransactionGuardImpl.submitTransactionAndWait(TransactionGuardImpl.java:148)
	at com.intellij.openapi.options.newEditor.SettingsDialog.show(SettingsDialog.java:76)
	at com.intellij.ide.actions.ShowSettingsUtilImpl.showSettingsDialog(ShowSettingsUtilImpl.java:84)
	at com.intellij.ide.actions.ShowSettingsAction.perform(ShowSettingsAction.java:54)
	at com.intellij.ui.mac.MacOSApplicationProvider$Worker.lambda$null$1(MacOSApplicationProvider.java:60)
	at com.intellij.ui.mac.MacOSApplicationProvider$Worker.lambda$submit$7(MacOSApplicationProvider.java:149)
	at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:82)
	at com.intellij.openapi.application.TransactionGuardImpl.lambda$pollQueueLater$0(TransactionGuardImpl.java:67)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:433)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:416)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:399)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:873)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:822)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:461)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:704)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:460)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

same. getting this:
Pylint is installed inside the project environment but the plugin is not able to run it. If you just installed it try to restart your IDE, if the problem persists you may need to manually enter the path to the Pylint executable inside the Plugin settings.

with an error:

java.lang.Throwable: Pylint path check process.exitValue: 1
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:145)
at com.leinardi.pycharm.pylint.plapi.PylintRunner.isPylintPathValid(PylintRunner.java:108)
at com.leinardi.pycharm.pylint.plapi.PylintRunner.checkPylintAvailable(PylintRunner.java:177)
at com.leinardi.pycharm.pylint.plapi.PylintRunner.scan(PylintRunner.java:230)
at com.leinardi.pycharm.pylint.checker.ScanFiles.scan(ScanFiles.java:108)
at com.leinardi.pycharm.pylint.checker.ScanFiles.checkFiles(ScanFiles.java:100)
at com.leinardi.pycharm.pylint.checker.ScanFiles.call(ScanFiles.java:74)
at com.leinardi.pycharm.pylint.checker.ScanFiles.call(ScanFiles.java:46)
at com.intellij.openapi.application.impl.ApplicationImpl$2.call(ApplicationImpl.java:322)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)

commented

This issue has been automatically marked as stale because it has not had activity in the last 60 days.

Same here with Mac OS.
I installed PyLint with Poetry - package is in .venv directory
Clicking "Test" button in the plugin preferences show this message:
"Must be installed on and selected from the project environment"

running the exeutable from the terminal works well.

Can you please check if pylint is shown as installed inside the Python interpreter settings?

image

It wasn't in the list. After adding it to the Project Interpreter packages list everything works.
Thank you very much.

commented

This issue has been automatically marked as stale because it has not had activity in the last 60 days.

I'm still having this issue, and pylint is listed in the list of packages.

I can solve the issue by typing the absolute path to the pylint.exe in the configuration (I have to do this for each project of course). But if I leave the default path (empty entrybox), the placeholder lists a default path which is exactly the one I would have to type it fails.

I am on windows and I think it's caused by wrong path separators, my default path looks like this C:/.../project/venv/Scripts/pylint.exe which has unix file separators.

I ran into this issue myself, and wrongfully wrote a ticket on the PyCharm ticketing rather than here.
https://youtrack.jetbrains.com/issue/PY-52058

When I use the file selector it will give me the correct separators:
image

But the automatic (verified manually) with the wrong separator does not work:
image
image

It would be neat if the auto detection worked as it would help that one doesn't have to manually set up pylint, or have a global one (of maybe a different version than the project).

That is using \ instead of / seems to be required on Windows systems. I can only assume it works perfectly on *nix systems. :)

I tested locally to do this change:

diff --git a/src/main/java/com/leinardi/pycharm/pylint/plapi/PylintRunner.java b/src/main/java/com/leinardi/pycharm/pylint/plapi/PylintRunner.java
index 798480b..d24db0f 100644
--- a/src/main/java/com/leinardi/pycharm/pylint/plapi/PylintRunner.java
+++ b/src/main/java/com/leinardi/pycharm/pylint/plapi/PylintRunner.java
@@ -140,7 +140,7 @@ public class PylintRunner {
             VirtualFile pylintFile = LocalFileSystem.getInstance()
                     .findFileByPath(interpreterFile.getParent().getPath() + File.separator + PYLINT_EXECUTABLE_NAME);
             if (pylintFile != null && pylintFile.exists()) {
-                return pylintFile.getPath();
+                return pylintFile.getPresentableUrl();
             }
         } else {
             return detectSystemPylintPath();

And it seems to work for windows machines:
show_instead_of_virtual_path

@kazie thank you for investigating this issue. I tried and getPresentableUrl() seems to work on *nix as well.
I'll add this fix to the next release (feel free to make a PR to the master branch, if you prefer this change to be officially credited to you 👍 )

@leinardi Cool!
I haven't tested it further, for example if it works past the Test button.
If something else breaks from it - I would not know - and I am not certain if a simple ./gradlew build and using the .jar file is enough. If you want me to test a beta or more official build in case, then sure I can help with that. :)

I see that my build doesn't contain okio or moshi due to just using the jar file so I suppose that I need to build it somehow different in order to further make sure it works still as expected overall. But I would assume it to be no problem.

To properly build the plugin you can use the buildPlugin task:

./gradlew clean buildPlugin

When it's done, you should be able to find the plugin at this path build/distributions/pylint-plugin-0.13.1.zip.

At this point, it can be installed like a normal plugin in IDEA/PyCharm:
image

Since the version will be the same as the current plugin from the market, you might have to uninstall the old one first (not sure if it's actually needed).

Just ping me if you need help building and testing this change 👍

Yeah, I did that now now exploring the gradle tasks for a named candidate (buildPlugin under intellij was kind of obvious once I saw it), built the zip file and installed on the windows machine. And it seems to work. :)
Putting up a PR soon for it.
Thanks you for your excellent work and replies overall!