Domanda

I've recently come across flake8, which is a handy wrapper around a couple of different python static checkers, and it seems cool. But how do I use a tool like this with Eclipse? I'm interested in making it easier to launch, and as well as in making use of the errors/warnings conveniently.

È stato utile?

Soluzione

Here's how I set it up to use on a single file at a time:

  1. FYI, as the very first step, I installed flake8 using pip.

  2. Set up flake8 as an external tool type runnable in Eclipse and configure it

    2.1. Create an eclipse external tool preset -- go to the external tool icon (the one with a run circle with a suitcase), and click the drop-down arrow next to it, and choose "External tools configuration..."

    2.2. Set the location to the full path to your flake8

    2.3. flake8 doesn't need any relative path files, so you can set the working directory to a nice don't-care value (e.g. /tmp)

    2.4. Set the arguments to whatever flake8 options you want, followed by ${selected_resource_loc}

  3. Set up highlighting and quick jumps for the flake8 warnings that appear in the console. I used the Console Grep plugin for Eclipse to do this:

    3.1. Install the Grep Console plugin (update site: http://eclipse.schedenig.name)

    3.2. Click on the (?) icon on the toolbar of the console view

    3.3. Add a folder, name it flake8

    3.4. Add an expression to the folder, and name it warning line

    3.5. Set the expression to: ^(.*.py):([0-9]+):([0-9]+): .*

    3.6. Click the "Warn" style and click assign

    3.7. You should see a snipped of your console in the preview at the bottom, and if there are warnings showing and your regex is working, they will be highlighted with the warn color

    3.8. Double click in the link column next to "whole line"

    3.9. Set the link column value to "file"

    3.10. Set "File" to {1}

    3.11. Set "Line number" to {2}

    3.12. Set "Offset (column)" to {3}

    3.13. Ok, Ok, Ok

    3.14. Ctrl-click a warning in the console and check that it goes to the line in the file.

  4. Now I tuned up my flake8 options the way I wanted.

    4.1. Set --max-line-length=128 or even higher =)

    4.2. Add an --ignore= option in the flake8 external tool arguments with a comma separated list of warning numbers to ignore. What warnings I ignored:

    • W293 blank line contains whitespace
    • W291 trailing whitespace
    • E261 at least two spaces before inline comment
    • E262 inline comment should start with "#"

    4.3. I wanted a choice of different flake options -- occasionally I want to use --show-pep8, so I created multiple flake8 "external tool" configurations with different options, and I can choose the one I want for a particular run from the external tool pulldown

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top