Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to format the output messages #3547

Closed
khyox opened this issue Jun 14, 2017 · 10 comments
Closed

Add option to format the output messages #3547

khyox opened this issue Jun 14, 2017 · 10 comments

Comments

@khyox
Copy link

khyox commented Jun 14, 2017

This is a feature request for easing the integration of mypy in some IDEs. The flag (suggested: abspath) would output the full path of the file just before ":{line_number}:[{column_number}:] error: ...". Of course, a more comprehensive solution would be a full formatter of the output lines with this and other choices to achieve the desired format in each case.

@gvanrossum
Copy link
Member

Wow, there are IDEs that cannot keep track of the directory where they run simple tools like mypy?

@khyox
Copy link
Author

khyox commented Jun 15, 2017

It's more concerned with the (in)ability to parse the output. There was a similar feature request for pylama that illustrates the issue (with PyCharm).

Beyond that, and probably as a better general solution, I think that an option like pylint's --msg-template would be very convenient. For example, with --msg-template="{abspath}:{line:04d}:{column:02d}: {msg_id} ({symbol}) {msg}" the parsing problem is easily solved for pylint/PyCharm case.

@gvanrossum
Copy link
Member

Well, I have run into this in the past with PyCharm, but IMO this is really a PyCharm bug. The generalized solution sounds like something I'd like to avoid for a few more years. In the meantime I'm sure you can write a little bash script that munges the output the way youwant.

@khyox khyox changed the title Add flag to report absolute path in output messages Add option to format the output messages Jun 15, 2017
@khyox
Copy link
Author

khyox commented Jun 15, 2017

Thanks! The bash script was written (awk at rescue): I cannot wait a few more years to integrate the useful mypy in the IDE 😉 . Anyway, that makes sense and I'll open an issue in PyCharm.

@khyox khyox closed this as completed Jun 15, 2017
@wbkdef
Copy link

wbkdef commented Feb 6, 2018

When I run mypy with the full file path from PyCharm, the full file path is included in the output (and can be turned into a link)

@switchtrue
Copy link

I couldn't get it to work as per @wbkdef

For anyone else coming here looking for a solution to using this with PyCharm, You can use the following bash script to wrap mypy and munge the output.

#!/bin/bash

MYPY_BIN=/usr/local/bin/mypy

length=$(($#-1))
mypyargs=${@:1:$length}
basepath=${@:$length+1:$length+1}

$MYPY_BIN $mypyargs | awk -v basepath=$basepath '{print basepath"/" $0}'

Set up your PyCharm like this - note the additional argument on the end - this is used as a prefix to all output from mypy.
screen shot 2018-06-08 at 10 27 33 am

@ilevkivskyi
Copy link
Member

Yes, making it work requires some tricks, and even when it works I was not very happy with the ergonomics. There is an "official" mypy PyCharm plugin that works smoother (at least for me) https://github.com/dropbox/mypy-PyCharm-plugin

@wbkdef
Copy link

wbkdef commented Jun 24, 2018

Something I didn't realize before, her is another thing I do that helps make mypy output the full path for each file: I run it in a directory totally unrelated to my project. I see @switchtrue is running it in the "ProjectFileDir", and so mypy uses a relative path.

Here's a screenshot of my setup (I'm also running mypy with a python script, that filters the output).

image

@pongo
Copy link

pongo commented Sep 27, 2018

For pycharm you can use this "external tool" setup:

  • arguments: --cache-dir $ProjectFileDir$/.mypy_cache --ignore-missing-imports $FileDir$/$FileName$
  • working directory: C:\temp (unrelated to your project)
  • output filters: $FILE_PATH$:$LINE$:$COLUMN$:.*

@Timmmm
Copy link

Timmmm commented Jul 13, 2021

I've made a new task that's pretty closely related to this - to add JSON output support. That should allow robust output parsing by IDEs, etc.

See #10816.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants