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:

0 commit comments

Comments
 (0)