jayvdb / flake8-putty

Flake8 plugin to control reporting per file and line
MIT License
37 stars 6 forks source link

Newbie question on how to actual get putty to be applied #17

Open Integralist opened 8 years ago

Integralist commented 8 years ago

Here are the packages installed:

$ flake8 --version

2.6.2 (
  pycodestyle: 2.0.0, 
  pyflakes: 1.2.3, 
  flake8-putty: 0.4.0, 
  flake8_quotes: 0.8.1, 
  mccabe: 0.5.2, 
  naming: 0.4.1
) 

CPython 3.5.1 on Darwin

I'm calling flake8 like so:

flake8 --putty-auto-ignore example.py

Here is example.py:

# pylint: disable=blacklisted-name
# flake8: disable=E302

import pdb

def baz(msg):
    print(msg)
    pdb.set_trace()
    print('done')

def bar(msg):
    baz(msg)

def foo(msg):
    bar(msg)

foo('hai')

But I'm still seeing in the terminal, the output:

$ flake8 --putty-auto-ignore debugging.py 

debugging.py:6:1: E302 expected 2 blank lines, found 1
debugging.py:11:1: E302 expected 2 blank lines, found 1
debugging.py:14:1: E302 expected 2 blank lines, found 1
The-Compiler commented 8 years ago

As far as I know, you can only use # flake8: disable=XXX comments per-line, not per-file.

jayvdb commented 8 years ago

Ya, currently the rules can appear in tox.ini/setup.cfg , or per line.

No objections to this being added. The simple way to do it would be dynamically adding an extra Rule matching the filename , if # flake8: disable= is at the beginning of the line.

And then, for extra fun, if # flake8: disable= appears again in the file the new rules should replace the existing ones, as that would be a way to scope a set of rules to be only apply to part of a file.

Integralist commented 8 years ago

@jayvdb that would be awesome :-)

as otherwise specifying flake8 per line is what I was trying to avoid when I saw this plugin.

At the moment I can use # noqa per line but that's just really crap when you have a big file with the same 'error' throughout.

So if there is a way to implement this so it works across the file as a whole, that would be awesome.

jayvdb commented 8 years ago

@Integralist , you can put a per-file rule in tox.ini or setup.cfg . Does that not suit you? even, as a temporary measure?

jayvdb commented 8 years ago

e.g. https://github.com/wikimedia/pywikibot-core/blob/master/tox.ini#L141

Integralist commented 8 years ago

Thanks. It'll do for sure. I just prefer the pylint format

bittner commented 7 years ago

I'm a bit puzzled with per-file rules, I don't get it to work. Here is what I have in my tox.ini file, but the flake8 complaints don't go away for Django migration modules:

[flake8]
exclude = .cache,.git,.tox,build
max-line-length = 120
putty-ignore =
    migrations : E501

The configuration file is read. I can see this by removing a blank before the colon, which results in a ValueError (tuple unpacking). - So, why aren't long lines ignored in migration modules? (E501 line too long)

The-Compiler commented 7 years ago

@bittner with what version of flake8?

bittner commented 7 years ago

I'm running the flake8 version pulled by flake8-putty (i.e. version 2.6.2) on Python 3.5.2:

$ tox
flake8 installed: flake8==2.6.2,flake8-putty==0.4.0,mccabe==0.5.2,packaging==16.8,pycodestyle==2.0.0,pyflakes==1.2.3,pyparsing==2.1.10,six==1.10.0
flake8 runtests: PYTHONHASHSEED='3756036720'
flake8 runtests: commands[0] | flake8 --version
2.6.2 (pycodestyle: 2.0.0, mccabe: 0.5.2, pyflakes: 1.2.3, flake8-putty: 0.4.0) CPython 3.5.2 on Linux
flake8 runtests: commands[1] | flake8
./foobarbaz/migrations/0001_initial.py:21:121: E501 line too long (246 > 120 characters)
./foobarbaz/migrations/0001_initial.py:34:121: E501 line too long (256 > 120 characters)
./foobarbaz/migrations/0001_initial.py:44:121: E501 line too long (134 > 120 characters)
ERROR: InvocationError: '/path/to/project/.tox/flake8/bin/flake8'
ptim commented 7 years ago

I'm a bit puzzled with per-file rules, I don't get it to work

I'm having the same issue; have tried the following patterns one at a time:

Aha! figured it out! seems a relative path from the config file seems to work, including some globbing, as long as a file extension is included. An absolute path didn't work (maybe read as a regex?).

; project_dir/.flake8
[flake8]
putty-ignore =
    ; each of these works:
    ; account/migrations/0001_initial.py : E501
    ; */migrations/0001_initial.py : E501
    */migrations/*.py : E501

    ; didn't work:
    ; /Users/me/source/project_dir/account/migrations/0001_initial.py : E501
    ; */migrations/* : E501
jayvdb commented 7 years ago

An absolute path didn't work (maybe read as a regex?).

Yes, an absolute path (starting with a /) is seen as a per-line regex.