Skip to content

Commit

Permalink
Allow globbing
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Sep 25, 2023
1 parent 99cd5ca commit 96acb88
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.14.0
rev: 1.15.0
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]
Expand All @@ -23,24 +23,24 @@ repos:
hooks:
- id: absolufy-imports
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.284"
rev: "v0.0.291"
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.1
rev: v3.0.3
hooks:
- id: prettier
args: [--list-different, --no-semi]
exclude: "^conf/|.*\\.html$"
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 0.13.1
rev: 1.1.0
hooks:
- id: pyproject-fmt
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.13
rev: v0.14
hooks:
- id: validate-pyproject
7 changes: 3 additions & 4 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
Change log
==========

`Next version`_
~~~~~~~~~~~~~~~

.. _Next version: https://github.com/matthiask/django-imagefield/compare/0.16...main
Next version
~~~~~~~~~~~~

- Added a force-WEBP spec.
- Added Django 4.1 and 4.2, Python 3.11.
- Dropped Django 4.0 from the CI (3.2 is still in there).
- Switched to hatch and ruff.
- Added globbing support to the ``process_imagefields`` management command.


`0.16`_ (2022-05-04)
Expand Down
19 changes: 13 additions & 6 deletions imagefield/management/commands/process_imagefields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from fnmatch import fnmatch

from django.core.management.base import BaseCommand, CommandError

Expand Down Expand Up @@ -35,8 +36,8 @@ def add_arguments(self, parser):
"field",
nargs="*",
type=str,
help="Fields to process:\n{}".format(
", ".join(sorted(f.field_label for f in IMAGEFIELDS))
help="Fields to process (globs are allowed): {}".format(
" ".join(sorted(f.field_label for f in IMAGEFIELDS))
),
)

Expand All @@ -53,14 +54,20 @@ def _compile_imagefield_labels(self, options):
if options["all"]:
return type("c", (), {"__contains__": lambda *a: True})()
elif options["field"]:
unknown = set(options["field"]).difference(
f.field_label for f in IMAGEFIELDS
)
fields = set()
known = [f.field_label for f in IMAGEFIELDS]
unknown = {}
for field in options["field"]:
if new := {f for f in known if fnmatch(f, field)}:
fields |= new
else:
unknown.add(field)

if unknown:
raise CommandError(
"Unknown imagefields: {}".format(", ".join(sorted(unknown)))
)
return options["field"]
return fields
else:
self.print_help(sys.argv[0], sys.argv[1])
sys.exit(1)
Expand Down

0 comments on commit 96acb88

Please sign in to comment.