Skip to content

Commit 2e985c2

Browse files
Use ruff for linting and formatting.
- Several fixes because of Ruff. - Updated GitHub workflow to use ruff instead of isort and black. - Added Python 3.10 to GitHub workflow. - Ruff formatting. - Removed unnecessary trailing comma.
1 parent 490cf90 commit 2e985c2

File tree

35 files changed

+203
-232
lines changed

35 files changed

+203
-232
lines changed

.github/workflows/test.yaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
python-version: [3.7, 3.8, 3.9, "3.10"]
13+
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"]
1414

1515
steps:
1616
- uses: actions/checkout@v2
@@ -22,21 +22,22 @@ jobs:
2222
run: |
2323
sudo apt remove python3-pip
2424
python -m pip install --upgrade pip
25-
python -m pip install . black coverage codecov flake8 isort==5.6.4 mypy pytest readme_renderer types-contextvars asyncssh
25+
python -m pip install . ruff coverage codecov mypy pytest readme_renderer types-contextvars asyncssh
2626
pip list
27-
- name: Run Tests
27+
- name: Ruff
28+
run: |
29+
ruff .
30+
ruff format --check .
31+
- name: Tests
2832
run: |
29-
flake8 .
3033
coverage run -m pytest
31-
- name: Type Checker
34+
- name: Mypy
3235
# Check wheather the imports were sorted correctly.
3336
# When this fails, please run ./tools/sort-imports.sh
3437
run: |
3538
mypy --strict src/prompt_toolkit --platform win32
3639
mypy --strict src/prompt_toolkit --platform linux
3740
mypy --strict src/prompt_toolkit --platform darwin
38-
isort -c --profile black src examples tests setup.py
39-
black --check src examples tests setup.py
4041
- name: Validate README.md
4142
# Ensure that the README renders correctly (required for uploading to PyPI).
4243
run: |

.travis.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# serve to show the default.
1313

1414
import os
15-
import sys
1615

1716
# If extensions (or modules to document with autodoc) are in another directory,
1817
# add these directories to sys.path here. If the directory is relative to the

examples/full-screen/calculator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def main():
4949
def accept(buff):
5050
# Evaluate "calculator" expression.
5151
try:
52-
output = "\n\nIn: {}\nOut: {}".format(
53-
input_field.text, eval(input_field.text)
52+
output = (
53+
f"\n\nIn: {input_field.text}\nOut: {eval(input_field.text)}"
5454
) # Don't do 'eval' in real code!
5555
except BaseException as e:
5656
output = f"\n\n{e}"

examples/prompts/asyncio-prompt.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,4 @@ async def main():
6060

6161

6262
if __name__ == "__main__":
63-
try:
64-
from asyncio import run
65-
except ImportError:
66-
asyncio.run_until_complete(main())
67-
else:
68-
asyncio.run(main())
63+
asyncio.run(main())

examples/prompts/custom-lexer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class RainbowLexer(Lexer):
1111
def lex_document(self, document):
12-
colors = list(sorted(NAMED_COLORS, key=NAMED_COLORS.get))
12+
colors = sorted(NAMED_COLORS, key=NAMED_COLORS.get)
1313

1414
def get_line(lineno):
1515
return [

examples/ssh/asyncssh-server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55
import asyncio
66
import logging
7-
from asyncio import run
87

98
import asyncssh
109
from pygments.lexers.html import HtmlLexer

examples/telnet/hello-world.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
That is probably the preferred way if you only need Python 3 support.
88
"""
99
import logging
10-
from asyncio import Future, run
10+
from asyncio import run
1111

1212
from prompt_toolkit.contrib.telnet.server import TelnetServer
1313
from prompt_toolkit.shortcuts import PromptSession, clear

examples/telnet/toolbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
in the prompt.
55
"""
66
import logging
7-
from asyncio import Future, run
7+
from asyncio import run
88

99
from prompt_toolkit.completion import WordCompleter
1010
from prompt_toolkit.contrib.telnet.server import TelnetServer

pyproject.toml

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
1-
[tool.black]
2-
target-version = ['py36']
3-
4-
5-
[tool.isort]
6-
# isort configuration that is compatible with Black.
7-
multi_line_output = 3
8-
include_trailing_comma = true
9-
known_first_party = "prompt_toolkit"
10-
known_third_party = "asyncssh,pygments"
11-
force_grid_wrap = 0
12-
use_parentheses = true
13-
line_length = 88
1+
[tool.ruff]
2+
target-version = "py37"
3+
select = [
4+
"E", # pycodestyle errors
5+
"W", # pycodestyle warnings
6+
"F", # pyflakes
7+
"C", # flake8-comprehensions
8+
"T", # Print.
9+
"I", # isort
10+
# "B", # flake8-bugbear
11+
"UP", # pyupgrade
12+
"RUF100", # unused-noqa
13+
"Q", # quotes
14+
]
15+
ignore = [
16+
"E501", # Line too long, handled by black
17+
"C901", # Too complex
18+
"E731", # Assign lambda.
19+
"E402", # Module level import not at the top.
20+
"E741", # Ambiguous variable name.
21+
]
22+
23+
24+
[tool.ruff.per-file-ignores]
25+
"examples/*" = ["T201"] # Print allowed in examples.
26+
"src/prompt_toolkit/application/application.py" = ["T100", "T201", "F821"] # pdb and print allowed.
27+
"src/prompt_toolkit/contrib/telnet/server.py" = ["T201"] # Print allowed.
28+
"src/prompt_toolkit/key_binding/bindings/named_commands.py" = ["T201"] # Print allowed.
29+
"src/prompt_toolkit/shortcuts/progress_bar/base.py" = ["T201"] # Print allowed.
30+
"tools/*" = ["T201"] # Print allowed.
31+
"src/prompt_toolkit/filters/__init__.py" = ["F403", "F405"] # Possibly undefined due to star import.
32+
"src/prompt_toolkit/filters/cli.py" = ["F403", "F405"] # Possibly undefined due to star import.
33+
"src/prompt_toolkit/shortcuts/progress_bar/formatters.py" = ["UP031"] # %-style formatting.
34+
35+
36+
[tool.ruff.isort]
37+
known-first-party = ["prompt_toolkit"]
38+
known-third-party = ["pygments", "asyncssh"]

0 commit comments

Comments
 (0)