Skip to content

Commit

Permalink
Replace Flake8 with Ruff (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Mar 18, 2024
2 parents 7291639 + cf81950 commit 0098551
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 59 deletions.
5 changes: 1 addition & 4 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma:
pragma: no cover

exclude_also =
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
Expand Down
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

19 changes: 11 additions & 8 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,28 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: hynek/build-and-inspect-python-package@v1
- uses: hynek/build-and-inspect-python-package@v2

# Upload to Test PyPI on every commit on main.
release-test-pypi:
name: Publish in-dev package to test.pypi.org
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
if: |
github.repository_owner == 'hugovk'
&& github.event_name == 'push'
&& github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build-package

permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

steps:
- name: Download packages built by build-and-inspect-python-package
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: Packages
path: dist
Expand All @@ -53,17 +55,18 @@ jobs:
# Upload to real PyPI on GitHub Releases.
release-pypi:
name: Publish released package to pypi.org
if: github.event.action == 'published'
if: |
github.repository_owner == 'hugovk'
&& github.event.action == 'published'
runs-on: ubuntu-latest
needs: build-package

permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

steps:
- name: Download packages built by build-and-inspect-python-package
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: Packages
path: dist
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/labels.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Sync labels

permissions:
pull-requests: write

on:
push:
branches:
Expand All @@ -12,7 +15,7 @@ jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: micnncim/action-label-syncer@v1
with:
prune: false
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Lint

on: [push, pull_request, workflow_dispatch]

env:
FORCE_COLOR: 1

permissions:
contents: read

Expand All @@ -10,8 +13,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- uses: pre-commit/action@v3.0.0
cache: pip
- uses: pre-commit/action@v3.0.1
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ jobs:
runs-on: ubuntu-latest
steps:
# Drafts your next release notes as pull requests are merged into "main"
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .github/workflows/require-pr-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ jobs:

permissions:
issues: write
pull-requests: write

steps:
- uses: mheap/github-action-required-labels@v4
- uses: mheap/github-action-required-labels@v5
with:
mode: minimum
count: 1
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
os: [windows-latest, macos-latest, ubuntu-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
Expand All @@ -27,15 +27,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install -U wheel
python -m pip install -U tox
- name: Tox tests
run: |
tox -e py
- name: Upload coverage
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v3.1.5
with:
flags: ${{ matrix.os }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
Expand Down
44 changes: 15 additions & 29 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,59 +1,40 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
hooks:
- id: pyupgrade
args: [--py38-plus]
- id: ruff
args: [--exit-non-zero-on-fix]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
rev: 24.3.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: [--add-import=from __future__ import annotations]

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
[flake8-2020, flake8-errmsg, flake8-implicit-str-concat]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-no-log-warn

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-merge-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.9.0
hooks:
- id: mypy
additional_dependencies: [pytest==7.3.1]
additional_dependencies: [pytest]
args: [--strict, --pretty, --show-error-codes]

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.5.3
rev: 1.7.0
hooks:
- id: pyproject-fmt

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.15
rev: v0.16
hooks:
- id: validate-pyproject

Expand All @@ -68,5 +49,10 @@ repos:
- id: prettier
args: [--prose-wrap=always, --print-width=88]

- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes

ci:
autoupdate_schedule: quarterly
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Supported Python versions](https://img.shields.io/pypi/pyversions/fino.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/fino/)
[![PyPI downloads](https://img.shields.io/pypi/dm/fino.svg)](https://pypistats.org/packages/fino)
[![GitHub Actions status](https://github.com/hugovk/fino/actions/workflows/test.yml/badge.svg)](https://github.com/hugovk/fino/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/hugovk/fino/branch/main/graph/badge.svg)](https://codecov.io/gh/hugovk/fino)
[![Codecov](https://codecov.io/gh/hugovk/fino/branch/main/graph/badge.svg)](https://codecov.io/gh/hugovk/fino)
[![Licence](https://img.shields.io/github/license/hugovk/fino.svg)](LICENSE.txt)
[![DOI](https://zenodo.org/badge/24323566.svg)](https://zenodo.org/badge/latestdoi/24323566)
[![Code style: Black](https://img.shields.io/badge/code%20style-Black-000000.svg)](https://github.com/psf/black)
Expand Down
36 changes: 34 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,37 @@ version.source = "vcs"
[tool.hatch.version.raw-options]
local_scheme = "no-local-version"

[tool.isort]
profile = "black"
[tool.ruff]
fix = true

[tool.ruff.lint]
select = [
"C4", # flake8-comprehensions
"E", # pycodestyle errors
"EM", # flake8-errmsg
"F", # pyflakes errors
"I", # isort
"ISC", # flake8-implicit-str-concat
"LOG", # flake8-logging
"PGH", # pygrep-hooks
"RUF100", # unused noqa (yesqa)
"UP", # pyupgrade
"W", # pycodestyle warnings
"YTT", # flake8-2020
]
extend-ignore = [
"E203", # Whitespace before ':'
"E221", # Multiple spaces before operator
"E226", # Missing whitespace around arithmetic operator
"E241", # Multiple spaces after ','
]

[tool.ruff.lint.isort]
known-first-party = ["fino"]
required-imports = ["from __future__ import annotations"]

[tool.pytest.ini_options]
filterwarnings = [
# Python <= 3.11
"ignore:sys.monitoring isn't available, using default core:coverage.exceptions.CoverageWarning",
]
2 changes: 1 addition & 1 deletion test_fino.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def test_unsupported_float() -> None:
number = 2.5
word = fino.to_finnish(number) # type: ignore
word = fino.to_finnish(number) # type: ignore[arg-type]
assert word == "en tiedä"


Expand Down
17 changes: 16 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,19 @@ extras =
pass_env =
FORCE_COLOR
commands =
{envpython} -m pytest --cov fino --cov test_fino --cov-report xml {posargs}
{envpython} -m pytest \
--cov fino \
--cov test_fino \
--cov-report html \
--cov-report term \
--cov-report xml \
{posargs}

[testenv:lint]
skip_install = true
deps =
pre-commit
pass_env =
PRE_COMMIT_COLOR
commands =
pre-commit run --all-files --show-diff-on-failure

0 comments on commit 0098551

Please sign in to comment.