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

ci: restrict Python linting runs #3301

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .github/workflows/push.yml → .github/workflows/lint-python.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
name: Lint
name: Lint Python
on:
push:
branches-ignore:
- "dependabot/*"
paths:
- '**/*.py'
- '.flake8'
- .github/workflows/lint-python.yml
pull_request:
paths:
- '**/*.py'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node.js has Python files that do not have a .py suffix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this repo?

- '.flake8'
- .github/workflows/lint-python.yml
jobs:
Python:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.7
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.7
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cclauss I didn't think the Python need to be pinned for the linting job, but correct me if i'm wrong

Copy link
Contributor

@cclauss cclauss Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the warnings that appear under the twisty for this GitHub Action job step:

Run actions/setup-python@v4
Warning: Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file.
Warning: .python-version doesn't exist.
Warning: The python-version input is not set. The version of Python currently in PATH will be used.

This ended up with Python 3.8. Explicit is better than implicit (The Zen of Python)


Flake8 changes based on the Python that it is run on. https://flake8.pycqa.org

Note
It is very important to install Flake8 on the correct version of Python for your needs. If you want Flake8 to properly parse new language features in Python 3.5 (for example), you need it to be installed on 3.5 for Flake8 to understand those features. In many ways, Flake8 is tied to the version of Python on which it runs.


Ruff does not run on Python so it changes in similar ways but only based on --target-version=pyXX

- name: Install dependencies
run: |
python -m pip install --upgrade pip
# pip install -r requirements.txt # TODO: Add tap2junit
pip install flake8
- name: Lint with flake8
run: |
pip install flake8
flake8 --version
flake8 .