Skip to content

Commit 8f087b2

Browse files
authored
switch to ruff (#124)
* switch to ruff * revert tests/test_expr_render.py * fix pyproject.toml, etc. * switch to pinned dependencies * switch to 3.7 deps * skip some tests on 3.7, add pre-commit
1 parent abed0a5 commit 8f087b2

26 files changed

+378
-193
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ jobs:
1919
with:
2020
python-version: '3.10'
2121

22-
- run: pip install -r tests/requirements-linting.txt
23-
- run: pip install .
22+
- run: pip install -r requirements/linting.txt -r requirements/pyproject.txt
23+
24+
- run: mypy devtools
2425

25-
- run: make lint
26+
- uses: pre-commit/[email protected]
27+
with:
28+
extra_args: --all-files --verbose
2629

2730
test:
2831
name: test py${{ matrix.python-version }} on ${{ matrix.os }}
@@ -47,7 +50,7 @@ jobs:
4750
with:
4851
python-version: ${{ matrix.python-version }}
4952

50-
- run: pip install -r tests/requirements.txt
53+
- run: pip install -r requirements/testing.txt -r requirements/pyproject.txt
5154
- run: pip install .
5255
- run: pip freeze
5356

@@ -102,7 +105,7 @@ jobs:
102105
python-version: '3.10'
103106

104107
- name: install
105-
run: make install
108+
run: pip install build twine
106109

107110
- name: build
108111
run: python -m build

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: check-toml
7+
- id: end-of-file-fixer
8+
- id: trailing-whitespace
9+
10+
- repo: local
11+
hooks:
12+
- id: ruff
13+
name: Ruff
14+
entry: ruff
15+
args: [--fix, --exit-non-zero-on-fix]
16+
types: [python]
17+
language: system
18+
files: ^devtools/|^tests/
19+
- id: black
20+
name: Black
21+
entry: black
22+
types: [python]
23+
language: system
24+
files: ^devtools/|^tests/
25+
exclude: test_expr_render.py

HISTORY.md

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

1515
## v0.7.0 (2021-09-03)
1616

17-
* switch to [`executing`](https://pypi.org/project/executing/) and [`asttokens`](https://pypi.org/project/asttokens/)
17+
* switch to [`executing`](https://pypi.org/project/executing/) and [`asttokens`](https://pypi.org/project/asttokens/)
1818
for finding and printing debug arguments, #82, thanks @alexmojaki
1919
* correct changelog links, #76, thanks @Cielquan
2020
* return `debug()` arguments, #87

Makefile

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
.DEFAULT_GOAL := all
2-
isort = isort devtools tests docs/plugins.py
3-
black = black -S -l 120 --target-version py37 devtools docs/plugins.py
2+
sources = devtools tests docs/plugins.py
43

54
.PHONY: install
65
install:
7-
python -m pip install -U setuptools pip wheel twine build
8-
pip install -U -r requirements.txt
6+
python -m pip install -U pip pre-commit
7+
pip install -U -r requirements/all.txt
98
pip install -e .
9+
pre-commit install
10+
11+
.PHONY: refresh-lockfiles
12+
refresh-lockfiles:
13+
find requirements/ -name '*.txt' ! -name 'all.txt' -type f -delete
14+
make update-lockfiles
15+
16+
.PHONY: update-lockfiles
17+
update-lockfiles:
18+
@echo "Updating requirements/*.txt files using pip-compile"
19+
pip-compile -q --resolver backtracking -o requirements/linting.txt requirements/linting.in
20+
pip-compile -q --resolver backtracking -o requirements/testing.txt requirements/testing.in
21+
pip-compile -q --resolver backtracking -o requirements/docs.txt requirements/docs.in
22+
pip-compile -q --resolver backtracking -o requirements/pyproject.txt pyproject.toml
23+
pip install --dry-run -r requirements/all.txt
1024

1125
.PHONY: format
1226
format:
13-
$(isort)
14-
$(black)
27+
black $(sources)
28+
ruff $(sources) --fix --exit-zero
1529

1630
.PHONY: lint
1731
lint:
18-
flake8 --max-complexity 10 --max-line-length 120 --ignore E203,W503 devtools tests docs/plugins.py
19-
$(isort) --check-only --df
20-
$(black) --check --diff
32+
black $(sources) --check --diff
33+
ruff $(sources)
2134
mypy devtools
2235

2336
.PHONY: test

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ outputs:
6464
devtools can be used without `from devtools import debug` if you add `debug` into `__builtins__`
6565
in `sitecustomize.py`.
6666

67-
For instructions on adding `debug` to `__builtins__`,
67+
For instructions on adding `debug` to `__builtins__`,
6868
see the [installation docs](https://python-devtools.helpmanual.io/usage/#usage-without-import).

devtools/debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def _process(self, args: 'Any', kwargs: 'Any') -> DebugOutput:
178178
ex = source.executing(call_frame)
179179
function = ex.code_qualname()
180180
if not ex.node:
181-
warning = "executing failed to find the calling node"
181+
warning = 'executing failed to find the calling node'
182182
arguments = list(self._args_inspection_failed(args, kwargs))
183183
else:
184184
arguments = list(self._process_args(ex, args, kwargs))

devtools/prettier.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
cache = lru_cache()
1414

1515
try:
16-
from sqlalchemy import inspect as sa_inspect # type: ignore
16+
from sqlalchemy import inspect as sa_inspect
1717
except ImportError:
18-
sa_inspect = None
18+
sa_inspect = None # type: ignore[assignment]
1919

2020
__all__ = 'PrettyFormat', 'pformat', 'pprint'
2121
MYPY = False
@@ -251,7 +251,7 @@ def _format_sqlalchemy_class(self, value: 'Any', _: str, indent_current: int, in
251251
deferred = set()
252252

253253
fields = [
254-
(field, getattr(value, field) if field not in deferred else "<deferred>")
254+
(field, getattr(value, field) if field not in deferred else '<deferred>')
255255
for field in dir(value)
256256
if not (field.startswith('_') or field in ['metadata', 'registry'])
257257
]

devtools/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _set_conout_mode(new_mode, mask=0xFFFFFFFF):
9393
mode = mask = ENABLE_VIRTUAL_TERMINAL_PROCESSING
9494
try:
9595
_set_conout_mode(mode, mask)
96-
except WindowsError as e: # type: ignore
96+
except OSError as e:
9797
if e.winerror == ERROR_INVALID_PARAMETER:
9898
return False
9999
raise
@@ -150,15 +150,15 @@ class DataClassType(metaclass=MetaDataClassType):
150150
class MetaSQLAlchemyClassType(type):
151151
def __instancecheck__(self, instance: 'Any') -> bool:
152152
try:
153-
from sqlalchemy.orm import DeclarativeBase # type: ignore
153+
from sqlalchemy.orm import DeclarativeBase
154154
except ImportError:
155155
pass
156156
else:
157157
if isinstance(instance, DeclarativeBase):
158158
return True
159159

160160
try:
161-
from sqlalchemy.ext.declarative import DeclarativeMeta # type: ignore
161+
from sqlalchemy.ext.declarative import DeclarativeMeta
162162
except ImportError:
163163
pass
164164
else:

docs/plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def gen_examples_html(m: re.Match) -> str:
5555
conv = Ansi2HTMLConverter()
5656
name = THIS_DIR / Path(m.group(1))
5757

58-
logger.info("running %s to generate HTML...", name)
58+
logger.info('running %s to generate HTML...', name)
5959
p = subprocess.run((sys.executable, str(name)), stdout=subprocess.PIPE, check=True)
6060
html = conv.convert(p.stdout.decode(), full=False).strip('\r\n')
6161
html = html.replace('docs/build/../examples/', '')

docs/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Two ways to do this:
9696
### Automatic install
9797

9898
!!! warning
99-
This is experimental, please [create an issue](https://github.com/samuelcolvin/python-devtools/issues)
99+
This is experimental, please [create an issue](https://github.com/samuelcolvin/python-devtools/issues)
100100
if you encounter any problems.
101101

102102
To install `debug` into `__builtins__` automatically, run:

pyproject.toml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,21 @@ exclude_lines = [
7171
[tool.black]
7272
color = true
7373
line-length = 120
74-
target-version = ['py37', 'py38', 'py39', 'py310']
74+
target-version = ['py37', 'py38', 'py39', 'py310', 'py311']
7575
skip-string-normalization = true
76+
extend-exclude = ['tests/test_expr_render.py']
7677

77-
[tool.isort]
78-
line_length = 120
79-
multi_line_output = 3
80-
include_trailing_comma = true
81-
force_grid_wrap = 0
82-
combine_as_imports = true
83-
color_output = true
78+
[tool.ruff]
79+
line-length = 120
80+
exclude = ['cases_update']
81+
extend-select = ['Q', 'RUF100', 'C90', 'UP', 'I']
82+
flake8-quotes = {inline-quotes = 'single', multiline-quotes = 'double'}
83+
mccabe = { max-complexity = 14 }
84+
isort = { known-first-party = ['devtools'] }
85+
target-version = 'py37'
8486

8587
[tool.mypy]
88+
show_error_codes = true
8689
strict = true
8790
warn_return_any = false
8891

requirements.txt

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

requirements/all.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-r ./docs.txt
2+
-r ./linting.txt
3+
-r ./testing.txt
4+
-r ./pyproject.txt

requirements/docs.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ansi2html==1.8.0
2+
mkdocs==1.3.1
3+
mkdocs-exclude==1.0.2
4+
mkdocs-material==8.3.9
5+
mkdocs-simple-hooks==0.1.5
6+
markdown-include==0.7.0
7+
pygments

requirements/docs.txt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# pip-compile --output-file=requirements/docs.txt --resolver=backtracking requirements/docs.in
6+
#
7+
ansi2html==1.8.0
8+
# via -r requirements/docs.in
9+
click==8.1.3
10+
# via mkdocs
11+
ghp-import==2.1.0
12+
# via mkdocs
13+
importlib-metadata==6.1.0
14+
# via mkdocs
15+
jinja2==3.1.2
16+
# via
17+
# mkdocs
18+
# mkdocs-material
19+
markdown==3.3.7
20+
# via
21+
# markdown-include
22+
# mkdocs
23+
# mkdocs-material
24+
# pymdown-extensions
25+
markdown-include==0.7.0
26+
# via -r requirements/docs.in
27+
markupsafe==2.1.2
28+
# via jinja2
29+
mergedeep==1.3.4
30+
# via mkdocs
31+
mkdocs==1.3.1
32+
# via
33+
# -r requirements/docs.in
34+
# mkdocs-exclude
35+
# mkdocs-material
36+
# mkdocs-simple-hooks
37+
mkdocs-exclude==1.0.2
38+
# via -r requirements/docs.in
39+
mkdocs-material==8.3.9
40+
# via -r requirements/docs.in
41+
mkdocs-material-extensions==1.1.1
42+
# via mkdocs-material
43+
mkdocs-simple-hooks==0.1.5
44+
# via -r requirements/docs.in
45+
packaging==23.0
46+
# via mkdocs
47+
pygments==2.14.0
48+
# via
49+
# -r requirements/docs.in
50+
# mkdocs-material
51+
pymdown-extensions==9.10
52+
# via mkdocs-material
53+
python-dateutil==2.8.2
54+
# via ghp-import
55+
pyyaml==6.0
56+
# via
57+
# mkdocs
58+
# pymdown-extensions
59+
# pyyaml-env-tag
60+
pyyaml-env-tag==0.1
61+
# via mkdocs
62+
six==1.16.0
63+
# via python-dateutil
64+
watchdog==3.0.0
65+
# via mkdocs
66+
zipp==3.15.0
67+
# via importlib-metadata

requirements/linting.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
black
2+
mypy==0.971
3+
ruff
4+
# required so mypy can find stubs
5+
sqlalchemy

requirements/linting.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# pip-compile --output-file=requirements/linting.txt --resolver=backtracking requirements/linting.in
6+
#
7+
black==23.3.0
8+
# via -r requirements/linting.in
9+
click==8.1.3
10+
# via black
11+
mypy==0.971
12+
# via -r requirements/linting.in
13+
mypy-extensions==1.0.0
14+
# via
15+
# black
16+
# mypy
17+
packaging==23.0
18+
# via black
19+
pathspec==0.11.1
20+
# via black
21+
platformdirs==3.2.0
22+
# via black
23+
ruff==0.0.261
24+
# via -r requirements/linting.in
25+
sqlalchemy==2.0.8
26+
# via -r requirements/linting.in
27+
tomli==2.0.1
28+
# via
29+
# black
30+
# mypy
31+
typing-extensions==4.5.0
32+
# via
33+
# mypy
34+
# sqlalchemy

requirements/pyproject.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# pip-compile --output-file=requirements/pyproject.txt --resolver=backtracking pyproject.toml
6+
#
7+
asttokens==2.2.1
8+
# via devtools (pyproject.toml)
9+
executing==1.2.0
10+
# via devtools (pyproject.toml)
11+
six==1.16.0
12+
# via asttokens

requirements/testing.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
coverage[toml]
2+
pygments
3+
pytest
4+
pytest-mock
5+
pytest-pretty
6+
# these packages are used in tests so install the latest version
7+
pydantic
8+
asyncpg
9+
numpy; python_version>='3.8'
10+
multidict; python_version>='3.8'
11+
sqlalchemy

0 commit comments

Comments
 (0)