Skip to content

Commit

Permalink
Replace flake8 and isort by ruff.
Browse files Browse the repository at this point in the history
Configure in pyproject.toml instead of setup.cfg.

Fix #1306.
  • Loading branch information
aaugustin committed Apr 1, 2023
1 parent 0924e9c commit af91737
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ jobs:
- name: Check code formatting
run: tox -e black
- name: Check code style
run: tox -e flake8
- name: Check imports ordering
run: tox -e isort
run: tox -e ruff
- name: Check types statically
run: tox -e mypy

Expand Down
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
.PHONY: default style test coverage maxi_cov build clean
.PHONY: default style types tests coverage maxi_cov build clean

export PYTHONASYNCIODEBUG=1
export PYTHONPATH=src
export PYTHONWARNINGS=default

default: coverage style
default: style types tests

style:
isort --project websockets src tests
black src tests
flake8 src tests
ruff --fix src tests

types:
mypy --strict src

test:
tests:
python -m unittest

coverage:
Expand Down
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,19 @@ exclude_lines = [
"self.fail\\(\".*\"\\)",
"@unittest.skip",
]

[tool.ruff]
select = [
"E", # pycodestyle
"F", # Pyflakes
"W", # pycodestyle
"I", # isort
]
ignore = [
"F403",
"F405",
]

[tool.ruff.isort]
combine-as-imports = true
lines-after-imports = 2
8 changes: 0 additions & 8 deletions setup.cfg

This file was deleted.

8 changes: 4 additions & 4 deletions src/websockets/legacy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,10 @@ def select_subprotocol(
subprotocols = set(client_subprotocols) & set(server_subprotocols)
if not subprotocols:
return None
priority = lambda p: (
client_subprotocols.index(p) + server_subprotocols.index(p)
)
return sorted(subprotocols, key=priority)[0]
return sorted(
subprotocols,
key=lambda p: client_subprotocols.index(p) + server_subprotocols.index(p),
)[0]

async def handshake(
self,
Expand Down
13 changes: 4 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ envlist =
py311
coverage
black
flake8
isort
ruff
mypy

[testenv]
Expand All @@ -31,13 +30,9 @@ deps = coverage
commands = black --check src tests
deps = black

[testenv:flake8]
commands = flake8 src tests
deps = flake8

[testenv:isort]
commands = isort --check-only src tests
deps = isort
[testenv:ruff]
commands = ruff src tests
deps = ruff

[testenv:mypy]
commands = mypy --strict src
Expand Down

0 comments on commit af91737

Please sign in to comment.