Pycharm Run External Tool Macro

大兔子大兔子 提交于 2019-12-11 17:54:53

问题


I am trying to run mypy as a "Before Launch" tool in the Run Configuration as a Template.

I have the following settings (Program: is the path to the mypy executible).

When I run my script I expect the macro to insert the filename of the script as so:

mypy.exe myScript.py

however it is only running the mypy.exe part (in the console I get an error telling me to supply the target script to the function). I have also tried deleting the working directory field as well, to no avail:

(Win10 / Python3.6 / Miniconda)


回答1:


I am seeing similar behavior with version: PyCharm 2018.2.5 (Professional Edition) Build #PY-182.5107.22, built on November 13, 2018

External Tools
It seems that the macro $FilePath$ is not being injected as an argument into the mypy executable. The only one I have tried which does get injected is $PyInterpreterDirectory.

File Watchers
Another workaround to this is adding mypy to file watchers. This will allow you to display mypy analysis of the current file, each time you save the file.

File > Settings > Tools > File Watchers : From here add the mypy executable and the argument.



TL;DR:
External Tools $FilePath$ macro fails to inject arguments into mypy executable. File Watchers $FilePath$ macro succeeds.

Reference for File Watchers : https://www.alexkorablev.com/mypy-python-27.html
it is for Python2.7 but the idea is the same for configuring file watchers.

Hope this helps.




回答2:


I have this code at the end of the module (probably not the best way, but when you have a small module and want to test things, it does the trick):

import os
os.system('python -m mypy <your_file_name>.py')


来源:https://stackoverflow.com/questions/52424711/pycharm-run-external-tool-macro

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!