Skip to content

Commit

Permalink
ci: Replace black, flake8, and isort with ruff (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol authored Dec 11, 2023
1 parent d29b392 commit 75922f5
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 89 deletions.
11 changes: 0 additions & 11 deletions .flake8

This file was deleted.

56 changes: 4 additions & 52 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,8 @@ env:

jobs:

lint-flake8:
name: Lint with Flake8
runs-on: ubuntu-latest
steps:
- name: Checkout the source code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_LATEST }}
cache: pip
cache-dependency-path: |
setup.cfg
requirements-dev.txt
- name: Install dependencies
run: |
pip install -U -r requirements-dev.txt
- name: Lint with flake8
run: |
echo "::add-matcher::.github/workflows/flake8-matcher.json"
python -m flake8 aiomonitor/ examples/ tests/
lint-isort:
name: Lint with isort
runs-on: ubuntu-latest
steps:
- name: Checkout the source code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_LATEST }}
check-latest: true
cache: pip
cache-dependency-path: |
setup.cfg
requirements-dev.txt
- name: Install dependencies
run: |
pip install -U -r requirements-dev.txt
- name: Lint with isort
run: |
python -m isort --check aiomonitor/ examples/ tests/
lint-black:
name: Lint with Black
lint-ruff:
name: Lint with Ruff
runs-on: ubuntu-latest
steps:
- name: Checkout the source code
Expand All @@ -82,9 +34,9 @@ jobs:
- name: Install dependencies
run: |
pip install -U -r requirements-dev.txt
- name: Lint with black
- name: Lint with Ruff
run: |
python -m black --check aiomonitor/ examples/ tests/
python -m ruff check
typecheck-mypy:
name: Check typing and annotations
Expand Down
18 changes: 6 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.10.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- id: ruff
args: ['--fix']
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
rev: v1.7.1
hooks:
- id: mypy
additional_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion aiomonitor/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def cancel(self, msg: Optional[str] = None) -> bool:


def preserve_termination_log(
corofunc: Callable[P, Coroutine[Any, None, T]]
corofunc: Callable[P, Coroutine[Any, None, T]],
) -> Callable[P, Coroutine[Any, None, T]]:
"""
Guard the given coroutine function from being stripped out due to the max history
Expand Down
4 changes: 2 additions & 2 deletions aiomonitor/webui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ async def check_params(
raise web.HTTPBadRequest(
content_type="application/json",
body=json.dumps({"msg": "Invalid parameters", "detail": detail}),
)
) from None
except Exception as e:
raise web.HTTPInternalServerError(
content_type="application/json",
body=json.dumps({"msg": "Internal server error", "detail": repr(e)}),
)
) from e
1 change: 1 addition & 0 deletions changes/391.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace black, flake8, and isort with ruff to simplify and speed up CI and pre-commit checks
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
try:
_version_info = get_version("aiomonitor")
except IndexError:
raise RuntimeError("Unable to determine version.")
raise RuntimeError("Unable to determine version.") from None

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Expand Down
18 changes: 14 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
# enables setuptools_scm to provide the dynamic version

[tool.black]
[tool.ruff]
line-length = 88
src = ["aiomonitor", "tests", "examples"]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"B", # flake8-bugbear
"Q", # flake8-quotes
]
ignore = ["E203", "E731", "E501", "Q000"]

[tool.isort]
profile = "black"
line_length = 88
[tool.ruff.isort]
known-first-party = ["aiomonitor"]
split-on-trailing-comma = true

[tool.mypy]
ignore_missing_imports = true
Expand Down
8 changes: 2 additions & 6 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ aioconsole==0.7.0
aiohttp==3.9.1
aiotools==1.6.0
attrs==23.1.0
black==22.10.0
docutils==0.19
flake8-bugbear==23.3.23
flake8-quotes==3.3.2
flake8==6.0.0
ipdb==0.13.13
isort==5.12.0
mypy==1.4.1
mypy==1.7.1
pre-commit==3.3.3
pytest-asyncio==0.21.1
pytest-cov==4.0.0
pytest-sugar==0.9.7
pytest==7.4.0
ruff==0.1.7
terminaltables==3.1.10
towncrier==23.6.0
types-requests
Expand Down

0 comments on commit 75922f5

Please sign in to comment.