The official GitHub mirror of https://gitlab.com/pycqa/flake8

Overview

Flake8

Flake8 is a wrapper around these tools:

  • PyFlakes
  • pycodestyle
  • Ned Batchelder's McCabe script

Flake8 runs all the tools by launching the single flake8 command. It displays the warnings in a per-file, merged output.

It also adds a few features:

  • files that contain this line are skipped:

    # flake8: noqa
    
  • lines that contain a # noqa comment at the end will not issue warnings.

  • you can ignore specific errors on a line with # noqa: <error>, e.g., # noqa: E234. Multiple codes can be given, separated by comma. The noqa token is case insensitive, the colon before the list of codes is required otherwise the part after noqa is ignored

  • Git and Mercurial hooks

  • extendable through flake8.extension and flake8.formatting entry points

Quickstart

See our quickstart documentation for how to install and get started with Flake8.

Frequently Asked Questions

Flake8 maintains an FAQ in its documentation.

Questions or Feedback

If you have questions you'd like to ask the developers, or feedback you'd like to provide, feel free to use the mailing list: [email protected]

We would love to hear from you. Additionally, if you have a feature you'd like to suggest, the mailing list would be the best place for it.

Links

Maintenance

Flake8 was created by Tarek Ziadé and is currently maintained by Ian Cordasco

Issues
  • Proposed Flake8 3.0 - [merged]

    Proposed Flake8 3.0 - [merged]

    In GitLab by @sigmavirus24 on Mar 15, 2016, 15:15

    Merges proposed/3.0 -> master

    Description of changes

    • Rewrite flake8's internals to be independent of pep8
    • Rework flake8's handling of options parsed from config files in a unified way that's better tested than pep8's handling was
    • Add proper logging to flake8 to allow more informative verbose information to be shown to the user
    • Internalize some of pep8's check handling and token generation

    Related to:

    • #117
    • #111
    • #106
    • #105
    • #100
    • #90
    • Option 2 from #89
    • #84
    • #74
    • #69
    • #66
    • #54
    • #21
    • #14

    And more that I'll update this with later


    Note that this is a merge in from https://gitlab.com/pycqa/flake8-engine which still has some open issues which will be fixed in this branch.

    gitlab merge request 
    opened by asottile 97
  • Version 3.0.x hangs with PicklingError on travis-ci.org [REPLACEMENT ISSUE]

    Version 3.0.x hangs with PicklingError on travis-ci.org [REPLACEMENT ISSUE]

    The original issue

    Id: 164
    Title: Version 3.0.x hangs with PicklingError on travis-ci.org
    

    could not be created. This is a dummy issue, replacing the original one. It contains everything but the original issue description. In case the gitlab repository is still existing, visit the following link to show the original issue:

    TODO

    opened by asottile 63
  • Version 3.0.x hangs with PicklingError on travis-ci.org

    Version 3.0.x hangs with PicklingError on travis-ci.org

    In GitLab by @tuxlife on Jul 8, 2016, 04:55

    We use flake8 on travic-ci for your builds and currently all build return an error.

    See here the travis-ci output

    • Version of Python which has Flake8 installed (e.g., python -V): 3.4.2
    • How you installed Flake8 (e.g., pip, apt, yum, etc.): pip
      • If you used pip, the version of pip installed (e.g., pip --version): 6.0.7
    • Version of setuptools installed (e.g., python -c 'import setuptools; print(setuptools.__version__)'): i don't know
    • Version of Flake8 installed (i.e., copy and paste all of the output from flake8 --version): 3.0.0b2

    thank you

    help wanted bug:confirmed component:multiprocessing component:setuptools-integration fix:committed fix:released priority:high 
    opened by asottile 63
  • Simplify and speed up multiprocessing - [merged]

    Simplify and speed up multiprocessing - [merged]

    In GitLab by @asottile on Nov 22, 2016, 15:45

    Merges faster -> master

    This is a bit of a WIP, I moved away from Queue (since it seems to be the bottleneck)

    From #265 the same test finishes (still slower) but in reasonable time:

    $ time flake8 -j8 bar
    
    real	0m17.583s
    user	0m26.312s
    sys	0m2.288s
    
    component:multiprocessing component:performance gitlab merge request 
    opened by asottile 60
  • Allow ignoring specific errors in files

    Allow ignoring specific errors in files

    In GitLab by @bittner on Sep 8, 2015, 09:28

    At the moment it's only possible to ignore

    • either a complete file (# flake8: noqa on a single line),
    • a single line (# noqa at the end of a line),
    • or specific errors in all files being checked (ignore = F403,E501 in a [flake8] section of setup.cfg or tox.ini)

    See also the Configuration chapter in the docs.

    Enhancement Proposal

    1.) Allow ignoring only specific errors in a single file:

    # flake8: ignore=F403,E501
    

    While I think this only would be a valuable, almost necessary addition to flake8 already the very same concept could be taken further in addition.

    Apply the Same Idea to Lines

    2.) Allow ignoring only specific errors on a single line:

    # noqa: ignore=F403,E501
    

    Taking the Proposal Further

    3.) Allow configuration within certain scopes of code:

    Following this syntax it could be used to apply certain (flake8) rules to a code block (e.g. a function). For example, this would allow complexity 12 within the scope of the function my_func:

    def my_func():
        # noqa: max-complexity=12
        for i in range(99):
            for j in range(99):
                for k in range(99):
                    for m in range(99):
                        pass
    
    opened by asottile 45
  • Allow ignoring specific errors in files [REPLACEMENT ISSUE]

    Allow ignoring specific errors in files [REPLACEMENT ISSUE]

    The original issue

    Id: 89
    Title: Allow ignoring specific errors in files
    

    could not be created. This is a dummy issue, replacing the original one. It contains everything but the original issue description. In case the gitlab repository is still existing, visit the following link to show the original issue:

    TODO

    opened by asottile 45
  • Adding include in and exclude from doctests - [merged]

    Adding include in and exclude from doctests - [merged]

    In GitLab by @jasonamyers on Dec 28, 2015, 11:59

    Merges doctest_inc_exc -> master

    Signed-off-by: Jason Myers [email protected]

    gitlab merge request 
    opened by asottile 41
  • Support linting when missing sem_open syscall - [merged]

    Support linting when missing sem_open syscall - [merged]

    In GitLab by @nekokatt on Aug 27, 2020, 05:18

    Merges bugfix/cpython-3770-semopen-missing -> master

    Platforms such as Termux on Android, and other exotic devices do not provide a sem_open implementation on the OS level. This is problematic, as the error resulting from this occurs when calling multiprocessing.Pool, throwing an unhandled ImportError.

    The issue itself is outlined in https://bugs.python.org/issue3770.

    This change allows devices missing this system call to respond to the missing feature by falling back to synchronous execution, which appears to be the default behaviour if the multiprocessing module is not found.

    This change also adds a potential fix for developers working on platforms where multiprocessing itself cannot be imported. The existing code would set the name referencing the import to None, but there are no clear checks to ensure this does not result in an AttributeError later when multiprocessing.Pool has accession attempts.

    Existing users should see no difference in functionality, as they will assumably already be able to use flake8, so will not be missing this sem_open call.

    Users on devices without the sem_open call will now be able to use flake8 where they would be unable to before due to unhandled ImportErrors.

    gitlab merge request 
    opened by asottile 40
  • Add support for local (in-repo, non-setuptools) plugins. - [merged]

    Add support for local (in-repo, non-setuptools) plugins. - [merged]

    In GitLab by @carljm on Aug 3, 2017, 24:29

    Merges local-plugins -> master

    Closes #357

    gitlab merge request 
    opened by asottile 39
  • Fix Issue #40  Include fixed - [closed]

    Fix Issue #40 Include fixed - [closed]

    In GitLab by @tyrelsouza on Apr 29, 2015, 20:43

    Merges fix_includes -> master

    Fix parsing ignore #40 at https://gitlab.com/pycqa/flake8/issues/40

    Adding an ignore option in [flake8] wasn't working because pep8.StyleGuide turned the string sent in into a tuple, which the option parser needs to receive as an iterable that isn't a string. Split on spaces, commas, or semicolons using re.findall in order to get a list of error/warnings to pass to StyleGuide properly.

    Also fixes a typo I found.

    gitlab merge request 
    opened by asottile 39
  • Output is appended to the report file when using --output-file

    Output is appended to the report file when using --output-file

    We are using flake 4.0.1 in a clean virtual environment together with tox 3.42.2.

    $ mkvirtualenv test
    $ pip install flake8==4.0.1
    $ pip install tox==3.42.2
    

    We need to use the --output-file option to store the flake8 results to a file because tox does not support stdout redirection to a file. This report will then be used to publish the findings on our build server. Also developers will use the same flow to check their code before committing it to the repository. During these checks we found out that flake8 does append new findings to an existing output file instead of replacing it with a new version. This makes it unnecessarily hard to check if reported findings have been fixed or new ones have been added to the report.

    Appending to a log/report file without explicitly telling the tool to do so is not intuitive. In fact flake8 seems to be the only tool I know that does not overwrite output files by default. Also deleting the file manually before running flake8 again is error prone and has to be communicated to the developers.

    Unfortunately there is no useful information in the issue #801 that is associated with the commit that changed the behavior from opening the file in write mode to opening it in append mode.

    I propose to change the file mode back to 'w' to give flake8 the expected behavior.

    opened by smartSBA 9
  • `--benchmark` / `--statistics` don't play well with custom formatters or `--quiet`

    `--benchmark` / `--statistics` don't play well with custom formatters or `--quiet`

    while moving things around, I noticed that these options don't play nicely with formatters

    for example:

    $ flake8 --quiet --quiet t.py --statistics
    1     F401 'os' imported but unused
    
    $ flake8 --format=json --benchmark t.py; echo
    {"t.py": [{"code": "F401", "filename": "t.py", "line_number": 1, "column_number": 1, "text": "'os' imported but unused", "physical_line": "import os\n"}]0.00914    seconds elapsed1          total logical lines processed109        logical lines processed per second1          total physical lines processed109        physical lines processed per second3          total tokens processed328        tokens processed per second1          total files processed109        files processed per second}
    

    I think ideally the following happens: statistics / benchmarks are moved from the base formatter to the default formatter and are noops otherwise

    perhaps even removing statistics / benchmark if they're not deemed useful enough

    opened by asottile 0
  • Increase batches per worker to 16, ~15% faster

    Increase batches per worker to 16, ~15% faster

    see issue #1430

    opened by collinanderson 0
  • increase batches per worker, ~15% faster

    increase batches per worker, ~15% faster

    Please describe how you installed Flake8

    $ sudo apt install flake8. # Ubuntu 20.04.3. I might pip-install if this feature request gets released.
    

    Please provide the exact, unmodified output of flake8 --bug-report

    {
      "dependencies": [
        {
          "dependency": "entrypoints",
          "version": "0.3"
        }
      ],
      "platform": {
        "python_implementation": "CPython",
        "python_version": "3.8.10",
        "system": "Linux"
      },
      "plugins": [
        {
          "is_local": false,
          "plugin": "mccabe",
          "version": "0.6.1"
        },
        {
          "is_local": false,
          "plugin": "pycodestyle",
          "version": "2.5.0"
        },
        {
          "is_local": false,
          "plugin": "pyflakes",
          "version": "2.1.1"
        }
      ],
      "version": "3.7.9"
    }
    

    Please describe the problem or feature

    Hi All. Thanks so much for maintaining flake8.

    Edit: ignore the sorting/optimizing chunks part. It seems to possibly have a negative benefit on large code-bases, though maybe still be slightly helpful for smaller codebases, though probably isn't worth the complexity.

    I think flake8 should increase batches per work and/or optimize chunks, possibly as settings.

    I have 496 files in my project, many of them are small django migrations and __init__.py files, but there are a few really big ones (15482 tokens, ~1000 physical lines), which end up making one worker (out of 4) quit much later than the others, so the large chunks (2 per worker) aren't balanced.

    In my case a normal flake8 run on my project takes ~3.8 seconds (tested 10 runs / 10), if I edit the code to force pool chunksize to 1 or 2, I get ~3.3 seconds, a 13% improvement in my case.

    Another thing could help would be to stat all the files and sort by file size, biggest first, then deal them out to each worker to help keep avoid a worker getting too much work at the end. For me when the files are cached in memory, it takes 2-4ms to stat and sort the files. That makes a larger chunksize more worth it:

            # in run_parallel(self):
            import os
            chunksize = calculate_pool_chunksize(len(self.checkers), self.jobs)
            # sort files by file size, largest first
            self.checkers.sort(key=lambda checker: os.stat(checker.filename).st_size, reverse=True)
            # deal the files out to the worker chunks
            new_sorted_checkers = []
            chunks = [[] for x in range(self.jobs)]
            for n, checker in enumerate(self.checkers):
                worker = n % self.jobs
                chunks[worker].append(checker)
                if len(chunks[worker]) >= chunksize:
                    new_sorted_checkers += chunks[worker]
                    chunks[worker] = []
            for chunk in chunks:
                new_sorted_checkers += chunk
            self.checkers = new_sorted_checkers
    

    With the sorting and dealing alone, using flake8's default of 2-chunks per worker (62 chunksize in my case), i get ~3.1 seconds (15% faster), which is a pretty good speedup. If I also force it to have a chunksize of 5, I get down to about ~2.9 seconds (23% faster), so increasing batches-per-worker or having a chunksize option would still be nice.

    Here's my results for the django 3.2 codebase (2696 checkers/files, 4 workers/jobs, default chunksize=337):

    Default settings: 37 seconds - chunksize=337 (~2 batches per worker)

    Increasing batches/chunks per worker/job, not stating/sorting/dealing: 32 seconds - chunksize=168 (~4 batches per worker) 30.5 seconds - chunksize=94 (~8 batches per worker) 30 seconds - chunksize=42 (~16 batches per worker) 30.6 seconds - chunksize=21 (~32 batches per worker)

    With stating/sorting/dealing: 30.9 seconds chunksize=337 (~2 batches per worker) (default batches per worker) 30.1 seconds - chunksize=168 (~4 batches per worker) 29.9 seconds - chunksize=84 (~8 batches per worker) 29.74 seconds - chunksize=42 (~16 batches per worker) 29.9 seconds - chunksize=21 (~32 batches per worker) (stating, sorting, and dealing alone takes ~14-19ms)

    Update: results for cpython 3.7 (no sorting) (1856 checkers/files, 4 workers/jobs): 1m14.535s - 2 batches per worker (default) 1m5.341s - 4 batches per worker (12% faster) 1m2.735s - 8 batches per worker(~15.8% faster) 1m2.576s - 16 batches per worker(~16% faster) 1m2.541s - 32 batches per worker(~16% faster) 1m2.139s - 64 batches per worker(~17% faster)

    At some point the benefits are within the margin of variance so it gets hard to measure, but somewhere around 16 batches-per-worker seems to be optimal in my case, and that alone, even without sorting by size etc, seems to really help.

    Anyway I thought I'd post my findings in case anyone wants to experiment with these things themselves and possibly improve flake8.

    If nothing else, changing the default "batches per worker" from 2 to 8 or 16 (in calculate_pool_chunksize) would be pretty simple and I think would really help keep work balanced (~15% faster).

    Thanks, Collin

    P.S. I'm realizing sorting by most-recently modified could also be helpful for quickly showing errors on recently edited files.

    opened by collinanderson 3
  • flake8 should only consider a noqa comment if it is actually a comment

    flake8 should only consider a noqa comment if it is actually a comment

    minimal reproduction:

    def f():
        x = '# noqa'
    

    I expect this to report the same as if that were an unrelated string:

    def f():
        x = '......'
    
    $ flake8 unrelated.py
    unrelated.py:2:5: F841 local variable 'x' is assigned to but never used
    
    bug:confirmed confirmed-by:core 
    opened by asottile 2
  • Unclear how plugins should indicate a configuration failure

    Unclear how plugins should indicate a configuration failure

    In GitLab by @pjacock on Aug 6, 2019, 02:42

    I have read http://flake8.pycqa.org/en/latest/plugin-development/plugin-parameters.html#accessing-parsed-options

    I am working on a plugin which successfully sets and receives additional configuration values. However, I wish to validate the configuration once (as early as possible), and may need to indicate an error to flake8 signalling it to abort. The simple option of raising a ValueError within parse_options does not work gracefully:

    ...
    
        @classmethod
        def add_options(cls, parser):
            ...
            # Define option "--our_config_file"
    
        @classmethod
        def parse_options(cls, options):
            ...
            if not os.path.isfile(options.our_config_file):
                raise ValueError("Could not find specified file: %r" % options.our_config_file)
    
    ...
    

    This has the desired effect of aborting flake8 early, but with an ugly traceback.

    Is there an expected approach I have overlooked, or would documenting this with a try/except in flake8 be preferred?

    I think the change would be in the provide_options method here:

    https://gitlab.com/pycqa/flake8/blob/3.7.8/src/flake8/plugins/manager.py#L186

    opened by asottile 5
  • Create sharable configuration presets for Flake8

    Create sharable configuration presets for Flake8

    In GitLab by @sobolevn on Jul 20, 2019, 02:35

    Problem

    I am writing quite a complex plugin with lots of configuration options. Moreover, I also depend on a lot of other plugins as dependencies.

    Here's how my configuration looks like for an end user, contents of setup.cfg:

    [flake8]
    # Base flake8 configuration:
    format = wemake
    show-source = True
    statistics = False
    doctests = True
    enable-extensions = G
    
    # Plugins:
    accept-encodings = utf-8
    max-complexity = 6
    max-line-length = 80
    quotes = single
    
    # Self settings:
    max-imports = 14
    
    
    # Exclude some pydoctest checks globally:
    ignore = D100, D104, D401, W504, RST303, RST304
    
    [isort]
    # See https://github.com/timothycrosley/isort#multi-line-output-modes
    multi_line_output = 3
    include_trailing_comma = true
    default_section = FIRSTPARTY
    # Is the same as 80 in flake8:
    line_length = 79
    

    Notice, that I also use flake8-isort and [isort] option, there also might be other sections like [mypy] for flake8-mypy, or [bandit] for flake8-bandit or any other plugins when flake8 acts like a wrapper for other tools.

    Currently, we will only talk about [flake8] section, since sadly we are not responsible for other tools.

    I do not want my users to copy-paste these settings for several reasons:

    1. They usually make mistakes in this simple action :slight_smile:
    2. I am losing control over the default configuration: I will not be able to change something in their defaults even if I want to
    3. It brings a lot of copy-paste. That's totally inconvenient to use and maintain. One new feature or a bug might force you to go trough all your X project and edit the configuration.

    Real world use-cases

    Several other linters have this feature. Some of them even consider it as a key feature.

    • EsLint: https://eslint.org/docs/developer-guide/shareable-configs
    • TsLint: https://palantir.github.io/tslint/2016/03/31/sharable-configurations-rules.html
    • Stylelint: https://stylelint.io/user-guide/configuration
    • Rubocop: https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md#inheriting-configuration-from-a-dependency-gem

    When working for EsLint for example, one can just create a module with a single javascript file and reuse it everywhere.

    I propose the same for flake8. Each user can create its own set of rules for an organisation / set of projects and reuse it without this amount of copy-paste.

    Implementation details

    Things to point out:

    1. It is not a breaking change, everything so work as-is, no major version bump is required
    2. Without new feature everything should work as-is
    3. New configuration option should take the lowest priority over existing config options

    Configuration priority

    Higher takes the priority over lower:

    1. CLI flags
    2. setup.cfg / .flake8
    3. New option: --sharable-configuration

    Creating new sharable configuration

    I guess that reusing entry points here is the best option.

    # setup.py
    # ...
    
    setup(
       name='my-flake8-config'
       entry_points={
            'flake8.configuration': [
                'myconfig = some.path:ConfigurationClass',
            ],
        },
    

    Then:

    1. Installing: pip install my-flake8-config
    2. Running: flake8 --sharable-configuration=myconfig
    3. Done!

    Configuration class API

    I am not sure about this. But my vision would be something like:

    # some/path.py
    
    class ConfigurationClass(object):
        def sharable_configuration(self):
            return {
               'quotes': 'single',
               # and any other options for `[flake8]` section
            }
    

    Conclusion

    This feature allows to transfer configuration in a reliable and clean way, brings no breaking changes, follows the best practices of other lint tools.

    Original issue from wemake-python-styleguide: https://github.com/wemake-services/wemake-python-styleguide/issues/164 The same feature I proposed for isort: https://github.com/timothycrosley/isort/issues/970

    I am super excited to help!

    feature:proposed 
    opened by asottile 10
  • Inconsistent exclude behaviour

    Inconsistent exclude behaviour

    In GitLab by @mskrajnowski on Dec 13, 2017, 05:53

    Please describe how you installed Flake8

    # in a virtualenv
    $ pip install flake8
    

    Please provide the exact, unmodified output of flake8 --bug-report

    {
      "dependencies": [
        {
          "dependency": "setuptools",
          "version": "34.2.0"
        }
      ],
      "platform": {
        "python_implementation": "CPython",
        "python_version": "2.7.12",
        "system": "Linux"
      },
      "plugins": [
        {
          "is_local": false,
          "plugin": "mccabe",
          "version": "0.6.1"
        },
        {
          "is_local": false,
          "plugin": "pycodestyle",
          "version": "2.3.1"
        },
        {
          "is_local": false,
          "plugin": "pyflakes",
          "version": "1.6.0"
        },
        {
          "is_local": false,
          "plugin": "unicode-string-literal",
          "version": "1.1"
        }
      ],
      "version": "3.5.0"
    }
    

    Please describe the problem or feature

    Explicitly specified modules are not always checked, depending on what exclude is set:

    • if the module is within an excluded directory it will be checked
    • if the module filename is excluded it will not be checked

    I would expect flake8 to either:

    • always check files that are explicitly specified
    • always ignore files that are excluded and/or in an excluded directory

    If this is a bug report, please explain with examples (and example code) what you expected to happen and what actually happened.

    1. Prepare a simple project for testing

      $ mkdir -p test-flake8-exclude/test
      $ cd test-flake8-exclude
      $ echo "import os" > test/module.py
      
    2. Try without exclude

      $ flake8 . && echo OK
      ./test/module.py:1:1: F401 'os' imported but unused
      $ flake8 test/module.py && echo OK
      test/module.py:1:1: F401 'os' imported but unused
      
    3. Try excluding the directory

      $ echo "[flake8]" > .flake8
      $ echo "exclude = test" >> .flake8
      
      $ flake8 . && echo OK
      OK
      $ flake8 test/module.py && echo OK
      test/module.py:1:1: F401 'os' imported but unused
      
    4. Try excluding the module

      $ echo "[flake8]" > .flake8
      $ echo "exclude = module.py" >> .flake8
      
      $ flake8 . && echo OK
      OK
      $ flake8 test/module.py && echo OK
      OK
      

    I'd expect results in 3. and 4. to be the same.

    bug:confirmed confirmed-by:core 
    opened by asottile 2
  • local-plugins relative paths are resolved relative to all paths not just the one the path directive is found

    local-plugins relative paths are resolved relative to all paths not just the one the path directive is found

    In GitLab by @graingert on Jul 13, 2020, 08:57

    Please describe how you installed Flake8

    pre-commit of course

    Please provide the exact, unmodified output of flake8 --bug-report

    {
      "dependencies": [],
      "platform": {
        "python_implementation": "CPython",
        "python_version": "3.8.2",
        "system": "Linux"
      },
      "plugins": [
        {
          "is_local": false,
          "plugin": "flake8-tidy-imports",
          "version": "4.1.0"
        },
        {
          "is_local": false,
          "plugin": "flake8_coding",
          "version": "1.3.2"
        },
        {
          "is_local": false,
          "plugin": "mccabe",
          "version": "0.6.1"
        },
        {
          "is_local": false,
          "plugin": "pycodestyle",
          "version": "2.6.0"
        },
        {
          "is_local": false,
          "plugin": "pyflakes",
          "version": "2.2.0"
        }
      ],
      "version": "3.8.3"
    }
    

    Please describe the problem or feature

    the paths are resolved relative to all paths not just the one the path directive is found in eg:

    .
    └── foo
        ├── bar
        │   ├── baz
        │   └── .flake8
        ├── baz
        └── .flake8
    
    [flake8:local-plugins]
    ...
    paths = ./baz
    

    when running flake8 --append-config=foo/bar/.flake8 --append-config=foo/.flake8 flake8 will add foo/baz and foo/bar/baz to LocalPlugins.paths

    opened by asottile 5
  • Performance suggestion: do not run unselected plugins/checks

    Performance suggestion: do not run unselected plugins/checks

    In GitLab by @hugovk on Jun 5, 2020, 01:45

    Please read this brief portion of documentation before going any further: http://flake8.pycqa.org/en/latest/internal/contributing.html#filing-a-bug

    Please describe how you installed Flake8

    $ pip install -U flake8
    $ brew install flake8
    # etc.
    

    Please provide the exact, unmodified output of flake8 --bug-report

    {
      "dependencies": [],
      "platform": {
        "python_implementation": "CPython",
        "python_version": "3.8.3",
        "system": "Darwin"
      },
      "plugins": [
        {
          "is_local": false,
          "plugin": "flake8_2020",
          "version": "1.6.0"
        },
        {
          "is_local": false,
          "plugin": "mccabe",
          "version": "0.6.1"
        },
        {
          "is_local": false,
          "plugin": "pycodestyle",
          "version": "2.6.0"
        },
        {
          "is_local": false,
          "plugin": "pyflakes",
          "version": "2.2.0"
        }
      ],
      "version": "3.8.2"
    }
    

    Please describe the problem or feature

    I noticed that Flake8 takes the same time to run with --select as without. As shown using -vv verbosity, it runs all the plugins and checks regardless of --select, and only reports the selected ones afterwards.

    Flake8 can sometimes take a long time to run on large codebases, and if it was possible to only run the selected checks, that would save a lot of time, CPU and power.

    Would it be possible to only run selected checks/plugins? Rather than running them anyway and discarding that work when reporting?


    Docs

    For reference, my emphasis.

    flake8 --help says --select is for which ones to enable:

      --select errors       Comma-separated list of errors and warnings to enable. For example, ``--select=E4,E51,W234``.
                            (Default: ['E', 'F', 'W', 'C90'])
    

    The docs are a bit more explicit:

    Specify the list of error codes you wish Flake8 to report.

    https://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-select


    Example

    An example running on the TensorFlow codebase:

    $ time flake8
    ...
    flake8  323.91s user 4.31s system 98% cpu 5:32.78 total
    $ time flake8 --select YTT
    ...
    flake8 --select YTT  318.62s user 3.80s system 99% cpu 5:25.51 total
    

    Both about the same, around 5m20s.

    With an ugly hack (I know this mixes plugin names with error codes, but it's just to get a rough idea, and there's other places to skip too):

    diff --git a/src/flake8/checker.py b/src/flake8/checker.py
    index d993cb9..9ed986d 100644
    --- a/src/flake8/checker.py
    +++ b/src/flake8/checker.py
    @@ -486,6 +486,8 @@ class FileChecker(object):
                 return
    
             for plugin in self.checks["ast_plugins"]:
    +            if plugin["name"] != "YTT":
    +                continue
                 checker = self.run_check(plugin, tree=ast)
                 # If the plugin uses a class, call the run method of it, otherwise
                 # the call should return something iterable itself
    
    $ time flake8 --select YTT
    flake8 --select YTT  276.90s user 3.17s system 98% cpu 4:43.00 total
    

    About 4m30s, nearly a minute and ~13% faster.

    opened by asottile 3
Owner
Python Code Quality Authority
Organization for code quality tools (and plugins) for the Python programming language
Python Code Quality Authority
❄️ A flake8 plugin to help you write better list/set/dict comprehensions.

flake8-comprehensions A flake8 plugin that helps you write better list/set/dict comprehensions. Requirements Python 3.6 to 3.9 supported. Installation

Adam Johnson 324 Jan 14, 2022
Flake8 plugin that checks import order against various Python Style Guides

flake8-import-order A flake8 and Pylama plugin that checks the ordering of your imports. It does not check anything else about the imports. Merely tha

Python Code Quality Authority 252 Jan 11, 2022
Flake8 extension for checking quotes in python

Flake8 Extension to lint for quotes. Major update in 2.0.0 We automatically encourage avoiding escaping quotes as per PEP 8. To disable this, use --no

Zachary Heller 135 Jan 11, 2022
flake8 plugin that integrates isort

Flake8 meet isort Use isort to check if the imports on your python files are sorted the way you expect. Add an .isort.cfg to define how you want your

Gil Forcada Codinachs 115 Jan 20, 2022
Flake8 plugin to find commented out or dead code

flake8-eradicate flake8 plugin to find commented out (or so called "dead") code. This is quite important for the project in a long run. Based on eradi

wemake.services 215 Jan 10, 2022
Flake8 wrapper to make it nice, legacy-friendly, configurable.

THE PROJECT IS ARCHIVED Forks: https://github.com/orsinium/forks It's a Flake8 wrapper to make it cool. Lint md, rst, ipynb, and more. Shareable and r

Life4 222 Jan 12, 2022
flake8 plugin to run black for checking Python coding style

flake8-black Introduction This is an MIT licensed flake8 plugin for validating Python code style with the command line code formatting tool black. It

Peter Cock 103 Jan 16, 2022
Automated security testing using bandit and flake8.

flake8-bandit Automated security testing built right into your workflow! You already use flake8 to lint all your code for errors, ensure docstrings ar

Tyler Wince 65 Dec 11, 2021
A plugin for flake8 integrating Mypy.

flake8-mypy NOTE: THIS PROJECT IS DEAD It was created in early 2017 when Mypy performance was often insufficient for in-editor linting. The Flake8 plu

Łukasz Langa 103 Apr 27, 2021
A plugin for Flake8 that checks pandas code

pandas-vet pandas-vet is a plugin for flake8 that provides opinionated linting for pandas code. It began as a project during the PyCascades 2019 sprin

Jacob Deppen 124 Dec 16, 2021
Flake8 extension for enforcing trailing commas in python

Flake8 Extension to enforce better comma placement. Usage If you are using flake8 it's as easy as: pip install flake8-commas Now you can avoid those a

Python Code Quality Authority 128 Nov 5, 2021
Tool to automatically fix some issues reported by flake8 (forked from autoflake).

autoflake8 Introduction autoflake8 removes unused imports and unused variables from Python code. It makes use of pyflakes to do this. autoflake8 also

francisco souza 12 Jan 6, 2022
Utilities for pycharm code formatting (flake8 and black)

Pycharm External Tools Extentions to Pycharm code formatting tools. Currently supported are flake8 and black on a selected code block. Usage Flake8 [P

Haim Daniel 6 Jan 14, 2022
flake8 plugin to catch useless `assert` statements

flake8-useless-assert flake8 plugin to catch useless assert statements Download or install on the PyPI page Violations Code Description Example ULA001

null 2 Dec 14, 2021
Flake8 extension to provide force-check option

flake8-force Flake8 extension to provide force-check option. When this option is enabled, flake8 performs all checks even if the target file cannot be

Kenichi Maehashi 2 Jan 4, 2022
OpenStack Hacking Style Checks. Mirror of code maintained at opendev.org.

Introduction hacking is a set of flake8 plugins that test and enforce the OpenStack StyleGuide Hacking pins its dependencies, as a new release of some

Mirrors of opendev.org/openstack 221 Jan 10, 2022
A static-analysis bot for Github

Imhotep, the peaceful builder. What is it? Imhotep is a tool which will comment on commits coming into your repository and check for syntactic errors

Justin Abrahms 217 Oct 11, 2021
An open-source, mini imitation of GitHub Copilot for Emacs.

Second Mate An open-source, mini imitation of GitHub Copilot using EleutherAI GPT-Neo-2.7B (via Huggingface Model Hub) for Emacs. This is a much small

Sam Rawal 133 Jan 12, 2022
Official mirror of https://gitlab.com/pgjones/hypercorn https://pgjones.gitlab.io/hypercorn/

Hypercorn Hypercorn is an ASGI web server based on the sans-io hyper, h11, h2, and wsproto libraries and inspired by Gunicorn. Hypercorn supports HTTP

Phil Jones 247 Jan 18, 2022
Official mirror of https://gitlab.com/pgjones/quart

Quart Quart is an async Python web microframework. Using Quart you can, render and serve HTML templates, write (RESTful) JSON APIs, serve WebSockets,

Phil Jones 979 Jan 18, 2022
Read-only mirror of https://gitlab.gnome.org/GNOME/pybliographer

Pybliographer Pybliographer provides a framework for working with bibliographic databases. This software is licensed under the GPLv2. For more informa

GNOME Github Mirror 14 Jan 11, 2022
Read-only mirror of https://gitlab.gnome.org/GNOME/meld

About Meld Meld is a visual diff and merge tool targeted at developers. Meld helps you compare files, directories, and version controlled projects. It

GNOME Github Mirror 744 Jan 15, 2022
Read-only mirror of https://gitlab.gnome.org/GNOME/ocrfeeder

================================= OCRFeeder - A Complete OCR Suite ================================= OCRFeeder is a complete Optical Character Recogn

GNOME Github Mirror 79 Jan 11, 2022
A python package for your Kali Linux distro that find the fastest mirror and configure your apt to use that mirror

Kali Mirror Finder Using Single Python File A python package for your Kali Linux distro that find the fastest mirror and configure your apt to use tha

MrSingh 3 Dec 2, 2021
Bagas Mirror&Leech Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Internet to our beloved Google Drive. Based on python-aria-mirror-bot

- [ MAYBE UPDATE & ADD MORE MODULE ] Bagas Mirror&Leech Bot Bagas Mirror&Leech Bot is a multipurpose Telegram Bot written in Python for mirroring file

null 4 Nov 23, 2021
Exposè for i3 WM. Fork of https://gitlab.com/d.reis/i3expo to fix crashes and improve features/usability

Overwiew Expo is an simple and straightforward way to get a visual impression of all your current virtual desktops that many compositing window manage

null 118 Jan 18, 2022
OSINT tool to get information from a Github and Gitlab profile and find user's email addresses leaked on commits.

gitrecon OSINT tool to get information from a Github or Gitlab profile and find user's email addresses leaked on commits. ?? How does this work? GitHu

GOΠZO 173 Jan 17, 2022
A terminal UI dashboard to monitor requests for code review across Github and Gitlab repositories.

A terminal UI dashboard to monitor requests for code review across Github and Gitlab repositories.

Kyle Harrison 135 Jan 12, 2022