Skip to content

switch to ruff #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ jobs:
with:
python-version: '3.10'

- run: pip install -r tests/requirements-linting.txt
- run: pip install .
- run: pip install -r requirements/linting.txt -r requirements/pyproject.txt

- run: mypy devtools

- run: make lint
- uses: pre-commit/[email protected]
with:
extra_args: --all-files --verbose

test:
name: test py${{ matrix.python-version }} on ${{ matrix.os }}
Expand All @@ -47,7 +50,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- run: pip install -r tests/requirements.txt
- run: pip install -r requirements/testing.txt -r requirements/pyproject.txt
- run: pip install .
- run: pip freeze

Expand Down Expand Up @@ -102,7 +105,7 @@ jobs:
python-version: '3.10'

- name: install
run: make install
run: pip install build twine

- name: build
run: python -m build
Expand Down
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: local
hooks:
- id: ruff
name: Ruff
entry: ruff
args: [--fix, --exit-non-zero-on-fix]
types: [python]
language: system
files: ^devtools/|^tests/
- id: black
name: Black
entry: black
types: [python]
language: system
files: ^devtools/|^tests/
exclude: test_expr_render.py
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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

* switch to [`executing`](https://pypi.org/project/executing/) and [`asttokens`](https://pypi.org/project/asttokens/)
* switch to [`executing`](https://pypi.org/project/executing/) and [`asttokens`](https://pypi.org/project/asttokens/)
for finding and printing debug arguments, #82, thanks @alexmojaki
* correct changelog links, #76, thanks @Cielquan
* return `debug()` arguments, #87
Expand Down
31 changes: 22 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
.DEFAULT_GOAL := all
isort = isort devtools tests docs/plugins.py
black = black -S -l 120 --target-version py37 devtools docs/plugins.py
sources = devtools tests docs/plugins.py

.PHONY: install
install:
python -m pip install -U setuptools pip wheel twine build
pip install -U -r requirements.txt
python -m pip install -U pip pre-commit
pip install -U -r requirements/all.txt
pip install -e .
pre-commit install

.PHONY: refresh-lockfiles
refresh-lockfiles:
find requirements/ -name '*.txt' ! -name 'all.txt' -type f -delete
make update-lockfiles

.PHONY: update-lockfiles
update-lockfiles:
@echo "Updating requirements/*.txt files using pip-compile"
pip-compile -q --resolver backtracking -o requirements/linting.txt requirements/linting.in
pip-compile -q --resolver backtracking -o requirements/testing.txt requirements/testing.in
pip-compile -q --resolver backtracking -o requirements/docs.txt requirements/docs.in
pip-compile -q --resolver backtracking -o requirements/pyproject.txt pyproject.toml
pip install --dry-run -r requirements/all.txt

.PHONY: format
format:
$(isort)
$(black)
black $(sources)
ruff $(sources) --fix --exit-zero

.PHONY: lint
lint:
flake8 --max-complexity 10 --max-line-length 120 --ignore E203,W503 devtools tests docs/plugins.py
$(isort) --check-only --df
$(black) --check --diff
black $(sources) --check --diff
ruff $(sources)
mypy devtools

.PHONY: test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ outputs:
devtools can be used without `from devtools import debug` if you add `debug` into `__builtins__`
in `sitecustomize.py`.

For instructions on adding `debug` to `__builtins__`,
For instructions on adding `debug` to `__builtins__`,
see the [installation docs](https://python-devtools.helpmanual.io/usage/#usage-without-import).
2 changes: 1 addition & 1 deletion devtools/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _process(self, args: 'Any', kwargs: 'Any') -> DebugOutput:
ex = source.executing(call_frame)
function = ex.code_qualname()
if not ex.node:
warning = "executing failed to find the calling node"
warning = 'executing failed to find the calling node'
arguments = list(self._args_inspection_failed(args, kwargs))
else:
arguments = list(self._process_args(ex, args, kwargs))
Expand Down
6 changes: 3 additions & 3 deletions devtools/prettier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
cache = lru_cache()

try:
from sqlalchemy import inspect as sa_inspect # type: ignore
from sqlalchemy import inspect as sa_inspect
except ImportError:
sa_inspect = None
sa_inspect = None # type: ignore[assignment]

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

fields = [
(field, getattr(value, field) if field not in deferred else "<deferred>")
(field, getattr(value, field) if field not in deferred else '<deferred>')
for field in dir(value)
if not (field.startswith('_') or field in ['metadata', 'registry'])
]
Expand Down
6 changes: 3 additions & 3 deletions devtools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _set_conout_mode(new_mode, mask=0xFFFFFFFF):
mode = mask = ENABLE_VIRTUAL_TERMINAL_PROCESSING
try:
_set_conout_mode(mode, mask)
except WindowsError as e: # type: ignore
except OSError as e:
if e.winerror == ERROR_INVALID_PARAMETER:
return False
raise
Expand Down Expand Up @@ -150,15 +150,15 @@ class DataClassType(metaclass=MetaDataClassType):
class MetaSQLAlchemyClassType(type):
def __instancecheck__(self, instance: 'Any') -> bool:
try:
from sqlalchemy.orm import DeclarativeBase # type: ignore
from sqlalchemy.orm import DeclarativeBase
except ImportError:
pass
else:
if isinstance(instance, DeclarativeBase):
return True

try:
from sqlalchemy.ext.declarative import DeclarativeMeta # type: ignore
from sqlalchemy.ext.declarative import DeclarativeMeta
except ImportError:
pass
else:
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def gen_examples_html(m: re.Match) -> str:
conv = Ansi2HTMLConverter()
name = THIS_DIR / Path(m.group(1))

logger.info("running %s to generate HTML...", name)
logger.info('running %s to generate HTML...', name)
p = subprocess.run((sys.executable, str(name)), stdout=subprocess.PIPE, check=True)
html = conv.convert(p.stdout.decode(), full=False).strip('\r\n')
html = html.replace('docs/build/../examples/', '')
Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Two ways to do this:
### Automatic install

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

To install `debug` into `__builtins__` automatically, run:
Expand Down
19 changes: 11 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,21 @@ exclude_lines = [
[tool.black]
color = true
line-length = 120
target-version = ['py37', 'py38', 'py39', 'py310']
target-version = ['py37', 'py38', 'py39', 'py310', 'py311']
skip-string-normalization = true
extend-exclude = ['tests/test_expr_render.py']

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

[tool.mypy]
show_error_codes = true
strict = true
warn_return_any = false

Expand Down
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

4 changes: 4 additions & 0 deletions requirements/all.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-r ./docs.txt
-r ./linting.txt
-r ./testing.txt
-r ./pyproject.txt
7 changes: 7 additions & 0 deletions requirements/docs.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ansi2html==1.8.0
mkdocs==1.3.1
mkdocs-exclude==1.0.2
mkdocs-material==8.3.9
mkdocs-simple-hooks==0.1.5
markdown-include==0.7.0
pygments
67 changes: 67 additions & 0 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements/docs.txt --resolver=backtracking requirements/docs.in
#
ansi2html==1.8.0
# via -r requirements/docs.in
click==8.1.3
# via mkdocs
ghp-import==2.1.0
# via mkdocs
importlib-metadata==6.1.0
# via mkdocs
jinja2==3.1.2
# via
# mkdocs
# mkdocs-material
markdown==3.3.7
# via
# markdown-include
# mkdocs
# mkdocs-material
# pymdown-extensions
markdown-include==0.7.0
# via -r requirements/docs.in
markupsafe==2.1.2
# via jinja2
mergedeep==1.3.4
# via mkdocs
mkdocs==1.3.1
# via
# -r requirements/docs.in
# mkdocs-exclude
# mkdocs-material
# mkdocs-simple-hooks
mkdocs-exclude==1.0.2
# via -r requirements/docs.in
mkdocs-material==8.3.9
# via -r requirements/docs.in
mkdocs-material-extensions==1.1.1
# via mkdocs-material
mkdocs-simple-hooks==0.1.5
# via -r requirements/docs.in
packaging==23.0
# via mkdocs
pygments==2.14.0
# via
# -r requirements/docs.in
# mkdocs-material
pymdown-extensions==9.10
# via mkdocs-material
python-dateutil==2.8.2
# via ghp-import
pyyaml==6.0
# via
# mkdocs
# pymdown-extensions
# pyyaml-env-tag
pyyaml-env-tag==0.1
# via mkdocs
six==1.16.0
# via python-dateutil
watchdog==3.0.0
# via mkdocs
zipp==3.15.0
# via importlib-metadata
5 changes: 5 additions & 0 deletions requirements/linting.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
black
mypy==0.971
ruff
# required so mypy can find stubs
sqlalchemy
34 changes: 34 additions & 0 deletions requirements/linting.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements/linting.txt --resolver=backtracking requirements/linting.in
#
black==23.3.0
# via -r requirements/linting.in
click==8.1.3
# via black
mypy==0.971
# via -r requirements/linting.in
mypy-extensions==1.0.0
# via
# black
# mypy
packaging==23.0
# via black
pathspec==0.11.1
# via black
platformdirs==3.2.0
# via black
ruff==0.0.261
# via -r requirements/linting.in
sqlalchemy==2.0.8
# via -r requirements/linting.in
tomli==2.0.1
# via
# black
# mypy
typing-extensions==4.5.0
# via
# mypy
# sqlalchemy
12 changes: 12 additions & 0 deletions requirements/pyproject.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements/pyproject.txt --resolver=backtracking pyproject.toml
#
asttokens==2.2.1
# via devtools (pyproject.toml)
executing==1.2.0
# via devtools (pyproject.toml)
six==1.16.0
# via asttokens
11 changes: 11 additions & 0 deletions requirements/testing.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
coverage[toml]
pygments
pytest
pytest-mock
pytest-pretty
# these packages are used in tests so install the latest version
pydantic
asyncpg
numpy; python_version>='3.8'
multidict; python_version>='3.8'
sqlalchemy
Loading