Skip to content

Commit 26cf2c9

Browse files
committed
Switch to hatch and ruff
1 parent 04f0487 commit 26cf2c9

File tree

16 files changed

+109
-123
lines changed

16 files changed

+109
-123
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
cache: pip
2828
- name: Install dependencies
2929
run: |
30-
python -m pip install --upgrade pip wheel setuptools tox
30+
python -m pip install --upgrade pip tox
3131
- name: Run tox targets for ${{ matrix.python-version }}
3232
run: |
3333
ENV_PREFIX=$(tr -C -d "0-9" <<< "${{ matrix.python-version }}")

.pre-commit-config.yaml

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,19 @@ repos:
77
- id: check-merge-conflict
88
- id: end-of-file-fixer
99
- id: trailing-whitespace
10-
- repo: https://github.com/asottile/pyupgrade
11-
rev: v3.3.1
12-
hooks:
13-
- id: pyupgrade
14-
args: [--py38-plus]
1510
- repo: https://github.com/adamchainz/django-upgrade
1611
rev: 1.13.0
1712
hooks:
1813
- id: django-upgrade
1914
args: [--target-version, "3.2"]
20-
- repo: https://github.com/pycqa/isort
21-
rev: 5.12.0
15+
- repo: https://github.com/charliermarsh/ruff-pre-commit
16+
rev: "v0.0.259"
2217
hooks:
23-
- id: isort
24-
args: [--profile=black, --lines-after-imports=2, --combine-as]
18+
- id: ruff
2519
- repo: https://github.com/psf/black
2620
rev: 23.1.0
2721
hooks:
2822
- id: black
29-
- repo: https://github.com/pycqa/flake8
30-
rev: 6.0.0
31-
hooks:
32-
- id: flake8
33-
args: ["--ignore=E203,E501,W503", "--max-complexity=10"]
34-
additional_dependencies:
35-
- flake8-bugbear
3623
- repo: https://github.com/pre-commit/mirrors-prettier
3724
rev: v3.0.0-alpha.6
3825
hooks:

feincms3/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
VERSION = (4, 0, 5)
2-
__version__ = ".".join(map(str, VERSION))
1+
__version__ = "4.0.5"

feincms3/admin.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ def get_urls(self):
124124
re_path(
125125
r"^(.+)/move/$",
126126
action_form_view_decorator(self)(self.move_view),
127-
name="%s_%s_move" % info,
127+
name="{}_{}_move".format(*info),
128128
),
129129
re_path(
130130
r"^(.+)/clone/$",
131131
action_form_view_decorator(self)(self.clone_view),
132-
name="%s_%s_clone" % info,
132+
name="{}_{}_clone".format(*info),
133133
),
134134
] + super().get_urls()
135135

@@ -151,7 +151,7 @@ def action_form_view(self, request, obj, *, form_class, title):
151151
return self.render_action_form(request, form, title=title, obj=obj)
152152

153153
def render_action_form(self, request, form, *, title, obj):
154-
adminForm = helpers.AdminForm(
154+
adminform = helpers.AdminForm(
155155
form,
156156
[
157157
(None, {"fields": form.fields.keys()})
@@ -160,14 +160,14 @@ def render_action_form(self, request, form, *, title, obj):
160160
(), # self.get_readonly_fields(request, obj),
161161
model_admin=self,
162162
)
163-
media = self.media + adminForm.media
163+
media = self.media + adminform.media
164164

165165
context = dict(
166166
self.admin_site.each_context(request),
167167
title=title,
168168
object_id=obj.pk,
169169
original=obj,
170-
adminform=adminForm,
170+
adminform=adminform,
171171
errors=helpers.AdminErrorList(form, ()),
172172
preserved_filters=self.get_preserved_filters(request),
173173
media=media,
@@ -436,7 +436,7 @@ def process(self):
436436

437437
for inline in self.modeladmin.inlines:
438438
fk = _get_foreign_key(
439-
self.modeladmin.model, inline.model, inline.fk_name, False
439+
self.modeladmin.model, inline.model, inline.fk_name, can_fail=False
440440
)
441441

442442
# Remove all existing instances
@@ -497,7 +497,7 @@ def queryset(self, request, queryset):
497497
if self.value():
498498
try:
499499
node = queryset.model._default_manager.get(pk=self.value())
500-
except (TypeError, ValueError, queryset.model.DoesNotExist):
501-
raise IncorrectLookupParameters()
500+
except (TypeError, ValueError, queryset.model.DoesNotExist) as exc:
501+
raise IncorrectLookupParameters() from exc
502502
return queryset.descendants(node, include_self=True)
503503
return queryset

feincms3/applications.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def reverse_any(
6969
if fallback is not _sentinel:
7070
return fallback
7171
raise NoReverseMatch(
72-
"Reverse for any of '%s' with arguments '%s' and keyword arguments"
73-
" '%s' not found." % ("', '".join(viewnames), args or [], kwargs or {})
72+
"Reverse for any of '{}' with arguments '{}' and keyword arguments"
73+
" '{}' not found.".format("', '".join(viewnames), args or [], kwargs or {})
7474
)
7575

7676

@@ -497,6 +497,15 @@ class Page(AbstractPage, PageTypeMixin, LanguageMixin):
497497
class Meta:
498498
abstract = True
499499

500+
def save(self, *args, **kwargs):
501+
"""
502+
Updates ``app_namespace``.
503+
"""
504+
self.app_namespace = self.type.app_namespace(self)
505+
super().save(*args, **kwargs)
506+
507+
save.alters_data = True
508+
500509
@property
501510
def type(self):
502511
"""
@@ -510,15 +519,6 @@ def type(self):
510519
def regions(self):
511520
return self.type.regions
512521

513-
def save(self, *args, **kwargs):
514-
"""
515-
Updates ``app_namespace``.
516-
"""
517-
self.app_namespace = self.type.app_namespace(self)
518-
super().save(*args, **kwargs)
519-
520-
save.alters_data = True
521-
522522
def clean_fields(self, exclude=None):
523523
"""
524524
Checks that required fields are given and that an app namespace only

feincms3/mixins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def fill_template_key_choices(sender, **kwargs):
108108
" from feincms3.applications even if you're not planning to use"
109109
" any apps.",
110110
DeprecationWarning,
111+
stacklevel=1,
111112
)
112113

113114

feincms3/renderer.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class PluginNotRegistered(Exception):
2626
renderer.
2727
"""
2828

29-
pass
30-
3129

3230
def default_context(plugin, context):
3331
"""
@@ -145,10 +143,10 @@ def render_plugin(self, plugin, context):
145143
"""
146144
try:
147145
renderer = self._renderers[plugin.__class__]
148-
except KeyError:
146+
except KeyError as exc:
149147
raise PluginNotRegistered(
150148
f"Plugin {plugin._meta.label_lower} is not registered"
151-
)
149+
) from exc
152150
if callable(renderer):
153151
return renderer(plugin, context)
154152
return renderer
@@ -159,10 +157,10 @@ def subregion(self, plugin):
159157
"""
160158
try:
161159
subregion = self._subregions[plugin.__class__]
162-
except KeyError:
160+
except KeyError as exc:
163161
raise PluginNotRegistered(
164162
f"Plugin {plugin._meta.label_lower} is not registered"
165-
)
163+
) from exc
166164
if callable(subregion):
167165
return subregion(plugin)
168166
return subregion
@@ -181,10 +179,10 @@ def marks(self, plugin):
181179
"""
182180
try:
183181
marks = self._marks[plugin.__class__]
184-
except KeyError:
182+
except KeyError as exc:
185183
raise PluginNotRegistered(
186184
f"Plugin {plugin._meta.label_lower} is not registered"
187-
)
185+
) from exc
188186
if callable(marks):
189187
return marks(plugin)
190188
return marks

feincms3/root/middleware.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ def handler(request, page):
5151
class _UseRootMiddlewareResponse(HttpResponseNotFound):
5252
"""Used by feincms3.root.passthru to tell the middleware to do its thing"""
5353

54-
pass
55-
5654

5755
def create_page_if_404_middleware(*, queryset, handler, language_code_redirect=False):
5856
"""

feincms3/shortcuts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def render_list(
3030
*,
3131
model=None,
3232
paginate_by=None,
33-
template_name_suffix="_list"
33+
template_name_suffix="_list",
3434
):
3535
"""
3636
Render a list of items

pyproject.toml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "feincms3"
7+
dynamic = ["version"]
8+
description = "CMS-building toolkit for Django"
9+
readme = "README.rst"
10+
license = "BSD-3-Clause"
11+
requires-python = ">=3.8"
12+
authors = [
13+
{ name = "Matthias Kestenholz", email = "mk@feinheit.ch" },
14+
]
15+
classifiers = [
16+
"Environment :: Web Environment",
17+
"Framework :: Django",
18+
"Intended Audience :: Developers",
19+
"License :: OSI Approved :: BSD License",
20+
"Operating System :: OS Independent",
21+
"Programming Language :: Python",
22+
"Programming Language :: Python :: 3",
23+
"Programming Language :: Python :: 3 :: Only",
24+
"Programming Language :: Python :: 3.8",
25+
"Programming Language :: Python :: 3.9",
26+
"Programming Language :: Python :: 3.10",
27+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
28+
"Topic :: Software Development",
29+
"Topic :: Software Development :: Libraries :: Application Frameworks",
30+
]
31+
dependencies = [
32+
"django-content-editor>=6.0",
33+
"django-js-asset>=2.0",
34+
"django-tree-queries>=0.6.0",
35+
"Django>=3.2",
36+
]
37+
38+
[project.optional-dependencies]
39+
all = [
40+
"django-imagefield",
41+
"html-sanitizer>=1.1.1",
42+
"requests",
43+
]
44+
tests = [
45+
"coverage",
46+
"django-ckeditor",
47+
"requests-mock",
48+
]
49+
50+
[project.urls]
51+
Homepage = "https://github.com/matthiask/feincms3/"
52+
53+
[tool.hatch.version]
54+
path = "feincms3/__init__.py"
55+
56+
[tool.hatch.build.targets.sdist]
57+
include = [
58+
"/feincms3",
59+
]
60+
61+
[tool.ruff]
62+
extend-select = ["B", "E", "F", "W", "C90", "I", "N", "UP", "FBT", "C4", "DJ", "PIE"]
63+
extend-ignore = ["E501"]
64+
fix = true
65+
target-version = "py38"
66+
67+
[tool.ruff.isort]
68+
combine-as-imports = true
69+
lines-after-imports = 2

0 commit comments

Comments
 (0)