Giter Site home page Giter Site logo

py-actions / flake8 Goto Github PK

View Code? Open in Web Editor NEW
65.0 2.0 21.0 1.5 MB

A GitHub Action that installs and executes flake8 Python source linting during continuous integration testing. Supports flake8 configuration and plugin installation in the GitHub Action settings.

License: Apache License 2.0

Makefile 7.52% JavaScript 82.75% Python 9.73%
python python3 flake8 github-actions ci lint linting flake8-plugin actions linter

flake8's Introduction

py-actions/flake8 GitHub Action

Version Linux CI macOS CI Windows CI Lint CodeQL

This GitHub Action installs the Python flake8 package in an environment with a Python interpreter and executes flake8 stylistic and logical linting of Python source files. flake8 installation and execution defaults, and flake8 plugins can be configured with optional Action settings.

The project is tested against the latest GitHub Actions Linux, macOS, and Windows runner environment cPython versions 3.9.x - 3.12.x interpreters on a nightly basis.

Quick Start

Default

name: flake8 Lint

on: [push, pull_request]

jobs:
  flake8-lint:
    runs-on: ubuntu-latest
    name: Lint
    steps:
      - name: Check out source repository
        uses: actions/checkout@v3
      - name: Set up Python environment
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"
      - name: flake8 Lint
        uses: py-actions/flake8@v2

With custom settings

name: flake8 Lint

on: [push, pull_request]

jobs:
  flake8-lint:
    runs-on: ubuntu-latest
    name: Lint
    steps:
      - name: Check out source repository
        uses: actions/checkout@v3
      - name: Set up Python environment
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"
      - name: flake8 Lint
        uses: py-actions/flake8@v2
        with:
          ignore: "F401"
          exclude: "src/ignoreme.py"
          max-line-length: "100"
          path: "src"
          plugins: "flake8-bugbear==22.1.11 flake8-black"

See the Inputs section below for details on the defaults and optional configuration settings.

Inputs

Configure the Action with the following optional settings:

flake8-version

Optional flake8 version for testing. Options: ['latest', 'main', 'master', '[VERSION NUMBER]'].Default = "latest".

path

Optional The path to the Python source file(s) or directory. Default = ".".

args

Optional Command line arguments to the flake8 executable. Default = None.

Please note that some command line arguments can be defined with other fields in your configuration. You may combine the args setting with the other settings below, or use args to configure flake8 without the other Action settings.

See the inputs below for additional details.

exclude

Optional Comma-delimited list of ignored file paths. Default = flake8 default.

ignore

Optional Comma-delimited list of ignored flake8 rule codes. Default = flake8 default.

max-line-length

Optional Integer value (as string) representing maximum acceptable line length. Default = flake8 default.

update-pip

Optional Update pip before the flake8 install. Options: ["true", "false"]. Default = "false".

plugins

Optional Space delimited list of flake8 plugin packages to install with pip prior to flake8 execution. Default = none.

Use the syntax:

  • [PACKAGE NAME]: for current PyPI release version across Action runs
  • [PACKAGE NAME]==[VERSION]: for a fixed PyPI release version on every Action run

See the "With custom settings" example above.

Outputs

None

License

Apache License, v2.0

flake8's People

Contributors

chrissimpkins avatar dependabot-preview[bot] avatar dependabot[bot] avatar roythearsonist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

flake8's Issues

Allow Select Parameter

For example:
flake8 --ignore F401,F541,F811,F841,E,W --select E999 --max-line-length 100 .

I want ignore all E rules, except for what is shown in select

V2.0.0 downloads corrupted file

I had this as a step

      - name: flake8 Lint
        uses: py-actions/[email protected]

Download from "https://github.com/actions/python-versions/releases/download/3.12.4-9442300799/python-3.12.4-linux-22.04-x64.tar.gz"
Extract downloaded archive
/usr/bin/tar xz --warning=no-unknown-keyword -C /home/runner/_work/_temp/... -f /home/runner/_work/_temp/...

gzip: stdin: not in gzip format
/usr/bin/tar: Child returned status 1
/usr/bin/tar: Error is not recoverable: exiting now
Error: The process '/usr/bin/tar' failed with exit code 2

once updated to 2.3.0 it worked.

`pyproject.toml` support

Does this actions pick-up pyproject.toml settings?

Something like this,

[tool.isort]
# https://github.com/timothycrosley/isort/
py_version = 37
line_length = 79

known_typing = ["typing", "types", "typing_extensions", "mypy", "mypy_extensions"]
sections = ["FUTURE", "TYPING", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
include_trailing_comma = true
multi_line_output = 3
indent = 4
color_output = true
use_parentheses = true

TypeError: argument of type 'NoneType' is not iterable

I can run linting locally using python -m flake8 --ignore E128,E302,E305,W292,BLK100 --max-line-length 120 --exclude .venv command without showing up any errors, but my linting GitHub Action suddenly started failing with the following error. Everything was working as expected until a few days ago.

/opt/hostedtoolcache/Python/3.12.0/x64/bin/flake8 --ignore E128,E302,E305,W292,BLK100 --max-line-length 120 backend
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/flake8/checker.py", line 83, in _mp_run
    ).run_checks()
      ^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/flake8/checker.py", line 526, in run_checks
    self.run_ast_checks()
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/flake8/checker.py", line 428, in run_ast_checks
    for line_number, offset, text, _ in runner:
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/bugbear.py", line 61, in run
    if self.should_warn(e.message[:4]):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/bugbear.py", line 153, in should_warn
    if code[:i] in self.options.select:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.0/x64/bin/flake8", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/flake8/main/cli.py", line 23, in main
    app.run(argv)
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/flake8/main/application.py", line 198, in run
    self._run(argv)
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/flake8/main/application.py", line 187, in _run
    self.run_checks()
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/flake8/main/application.py", line 103, in run_checks
    self.file_checker_manager.run()
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/flake8/checker.py", line 236, in run
    self.run_parallel()
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/flake8/checker.py", line 205, in run_parallel
    self.results = list(pool.imap_unordered(_mp_run, self.filenames))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/multiprocessing/pool.py", line 873, in next
    raise value
TypeError: argument of type 'NoneType' is not iterable
Error: The process '/opt/hostedtoolcache/Python/3.12.0/x64/bin/flake8' failed with exit code 1

Snippet of the workflow file:

- name: Flake8 linting
          uses: py-actions/flake8@v2
          with:
            ignore: "E128,E302,E305,W292,BLK100"
            max-line-length: 120
            path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
            plugins: "flake8-bugbear==22.1.11 flake8-black"

ERROR: Action failed during execution

Hello! So, I'm trying this action with the default settings:

image

Flake8 doesn't have any problems to detect all the errors in the project, but in the end, after printing all the flake8 errors, this error appears:

ERROR: Action failed during execution with error: The process '/opt/hostedtoolcache/Python/3.8.12/x64/bin/flake8' failed with exit code 1

image

I wouldn't have a problem if I only wanted to use that one step. But I wan't to add a few more steps on this action, more flake8 checks on other folders, and since the first one fails, the next one won't start.

Is it normal that the action throws that error? @chrissimpkins

Unrecognized Arguments

I didn't set path like the default configuration but I got this error:

/opt/hostedtoolcache/Python/3.8.11/x64/bin/flake8 --ignore F403,F405, W503, W504 --exclude */migrations/* --max-line-length 120 .
usage: flake8 [options] file file ...
flake8: error: unrecognized arguments: .
Error: ERROR: Action failed during execution with error: The process '/opt/hostedtoolcache/Python/3.8.11/x64/bin/flake8' failed with exit code 2

Here is my yml file:

name: flake8 Lint # https://github.com/marketplace/actions/python-flake8-lint

on: [push, pull_request]

jobs:
  flake8-lint:
    runs-on: ubuntu-latest
    name: Lint
    steps:
      - name: Check out source repository
        uses: actions/checkout@v2
      - name: Set up Python environment
        uses: actions/setup-python@v1
        with:
          python-version: "3.8"
      - name: flake8 Lint
        uses: py-actions/flake8@v1
        with:
          max-line-length: "120"
          exclude: "*/migrations/*"
          ignore: "F403,F405, W503, W504"

Action does not work with flake8 plugin 'pyproject-flake8'

I've tried to use this gh action with flake8 plugin 'pyproject-flake8' but it does not seem to work (commented out below). It does not pick up the configuration in pyproject.toml (e.g. max-lines).

It works however with a standard hatch run as exampled below.

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: 3.9
      - run: pip install hatch pyproject-flake8
      - run: hatch run lint:flake8
      # - uses: py-actions/flake8@v2          
      #   with:
      #     plugins: "pyproject-flake8"

Add plugins input

Please add an input to specify a list of additional plugins (with versions) to install with pip for Flake8. For example plugins: flake8-bugbear==22.1.11 as input would install the flake8-bugbear PyPI package version 22.1.11.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.