Skip to content

Commit

Permalink
Switched from black to ruff.
Browse files Browse the repository at this point in the history
Line-length set to 100.
  • Loading branch information
coady committed Dec 15, 2023
1 parent 34610bd commit d6654d0
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: 3.x
- run: pip install black ruff mypy
- run: pip install ruff mypy
- run: make lint

docs:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## Unreleased
### Changed
* Python >=3.9 required

## [1.6](https://pypi.org/project/django-model-values/1.6/) - 2023-11-04
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ check:
python -m pytest -s --cov

lint:
black --check .
ruff .
ruff format --check .
mypy -p model_values

html:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
[![image](https://github.com/coady/django-model-values/workflows/build/badge.svg)](https://github.com/coady/django-model-values/actions)
[![image](https://codecov.io/gh/coady/django-model-values/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/django-model-values/)
[![image](https://github.com/coady/django-model-values/workflows/codeql/badge.svg)](https://github.com/coady/django-model-values/security/code-scanning)
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/)
[![image](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![image](https://mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)

Expand Down
4 changes: 3 additions & 1 deletion model_values/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,9 @@ def bulk_changed(self, field, data: Mapping, key: str = 'pk') -> dict:
rows = self.filter(F(key).isin(data))[key, field].iterator()
return {pk: value for pk, value in rows if value != data[pk]}

def bulk_change(self, field, data: Mapping, key: str = 'pk', conditional=False, **kwargs) -> int:
def bulk_change(
self, field, data: Mapping, key: str = 'pk', conditional=False, **kwargs
) -> int:
"""Update changed rows with a minimal number of queries, by inverting the data to use ``pk__in``.
Args:
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ version = {attr = "model_values.__version__"}
[tool.setuptools.package-data]
model_values = ["py.typed"]

[tool.black]
line-length = 110
skip-string-normalization = true

[tool.ruff]
ignore = ["E501"]
line-length = 100

[tool.ruff.format]
preview = true
quote-style = "preserve"

[[tool.mypy.overrides]]
module = ["django.*"]
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ def pytest_report_header(config):


pytest_plugins = ('django',)
settings.configure(INSTALLED_APPS=['tests'], DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3'}})
settings.configure(
INSTALLED_APPS=['tests'], DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3'}}
)
12 changes: 8 additions & 4 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ def test_spatial_lookups():
point = 'POINT(0 0)'
assert F.location.is_valid.children == [('location__isvalid', True)]
assert F.location.contains(point, bb=True).children == [('location__bbcontains', point)]
assert F.location.contains(point, properly=True).children == [('location__contains_properly', point)]
expected = [('location__contains_properly', point)]
assert F.location.contains(point, properly=True).children == expected

assert F.location.overlaps(point).children == [('location__overlaps', point)]
assert F.location.overlaps(point, bb=True).children == [('location__bboverlaps', point)]
Expand All @@ -339,8 +340,10 @@ def test_spatial_lookups():
assert F.location.relate(point, '').children == [('location__relate', (point, ''))]
assert F.location.touches(point).children == [('location__touches', point)]

assert (F.location << point).children == F.location.left(point).children == [('location__left', point)]
assert (F.location >> point).children == F.location.right(point).children == [('location__right', point)]
expected = [('location__left', point)]
assert (F.location << point).children == F.location.left(point).children == expected
expected = [('location__right', point)]
assert (F.location >> point).children == F.location.right(point).children == expected
assert F.location.above(point).children == [('location__strictly_above', point)]
assert F.location.below(point).children == [('location__strictly_below', point)]

Expand Down Expand Up @@ -374,7 +377,8 @@ def test_spatial_functions(books):

dist = F.location.distance(point)
assert isinstance(dist, gis.functions.Distance)
fields, items = zip(*F.all([(dist < 0), (dist <= 0), (dist > 0), (dist >= 0), dist.within(0)]).children)
dists = (dist < 0), (dist <= 0), (dist > 0), (dist >= 0), dist.within(0)
fields, items = zip(*F.all(dists).children)
assert fields == (
'location__distance_lt',
'location__distance_lte',
Expand Down

0 comments on commit d6654d0

Please sign in to comment.