Skip to content

Commit

Permalink
Format with black and lint with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Nov 26, 2023
1 parent 1652dec commit 3499079
Show file tree
Hide file tree
Showing 24 changed files with 511 additions and 258 deletions.
54 changes: 53 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,53 @@
repos: []
# To enable this pre-commit hook run:
# `pip install pre-commit` or `brew install pre-commit`
# Then run `pre-commit install`

# Learn more about this config here: https://pre-commit.com

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-toml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
- id: mixed-line-ending
- id: requirements-txt-fixer
#- id: name-tests-test
# args:
# - --django
#- id: trailing-whitespace
# args:
# - --markdown-linebreak-ext=md

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: ruff
args:
- --ignore=DJ007,DJ008,PLW2901,UP031,UP032
- --line-length=119
- --select=ASYNC,C4,C90,DJ,E,F,PL,UP,W

- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
args:
- --skip-string-normalization
- --target-version=py38

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies:
- tomli
args:
[--skip, "*.po"]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.15
hooks:
- id: validate-pyproject
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ docs:
$(MAKE) -C docs clean html

test:
@flake8
@ruff .
@isort --check-only --diff formtools tests
@ python -W error::DeprecationWarning -W error::PendingDeprecationWarning -m coverage run `which django-admin` test tests
@coverage report
Expand Down
51 changes: 37 additions & 14 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx',
'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.ifconfig',
'sphinx.ext.viewcode', 'settings']
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'settings',
]

# Add any paths that contain templates here, relative to this directory.
# templates_path = ['_templates']
Expand All @@ -54,6 +60,7 @@
# The short X.Y version.
try:
from formtools import __version__

# The short X.Y version.
version = '.'.join(__version__.split('.')[:2])
# The full version, including alpha/beta/rc tags.
Expand Down Expand Up @@ -184,19 +191,22 @@
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'django-formtools.tex', 'django-formtools Documentation',
'Django Software Foundation and individual contributors', 'manual'),
(
'index',
'django-formtools.tex',
'django-formtools Documentation',
'Django Software Foundation and individual contributors',
'manual',
),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -225,8 +235,13 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'django-formtools', 'django-formtools Documentation',
['Django Software Foundation and individual contributors'], 1)
(
'index',
'django-formtools',
'django-formtools Documentation',
['Django Software Foundation and individual contributors'],
1,
)
]

# If true, show URL addresses after external links.
Expand All @@ -239,9 +254,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'django-formtools', 'django-formtools Documentation',
'Django Software Foundation and individual contributors', 'django-formtools', 'One line description of project.',
'Miscellaneous'),
(
'index',
'django-formtools',
'django-formtools Documentation',
'Django Software Foundation and individual contributors',
'django-formtools',
'One line description of project.',
'Miscellaneous',
),
]

# Documents to append as an appendix to all manuals.
Expand Down Expand Up @@ -318,6 +339,8 @@
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'http://docs.python.org/': None,
'django': ('http://docs.djangoproject.com/en/dev/',
'http://docs.djangoproject.com/en/dev/_objects/'),
'django': (
'http://docs.djangoproject.com/en/dev/',
'http://docs.djangoproject.com/en/dev/_objects/',
),
}
17 changes: 10 additions & 7 deletions formtools/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def unused_name(self, name):

def preview_get(self, request):
"Displays the form"
f = self.form(auto_id=self.get_auto_id(),
initial=self.get_initial(request))
f = self.form(auto_id=self.get_auto_id(), initial=self.get_initial(request))
return render(request, self.form_template, self.get_context(request, f))

def preview_post(self, request):
Expand All @@ -61,7 +60,9 @@ def preview_post(self, request):
"""
# Even if files are not supported in preview, we still initialize files
# to give a chance to process_preview to access files content.
f = self.form(data=request.POST, files=request.FILES, auto_id=self.get_auto_id())
f = self.form(
data=request.POST, files=request.FILES, auto_id=self.get_auto_id()
)
context = self.get_context(request, f)
if f.is_valid():
self.process_preview(request, f, context)
Expand All @@ -82,8 +83,8 @@ def post_post(self, request):
form = self.form(request.POST, auto_id=self.get_auto_id())
if form.is_valid():
if not self._check_security_hash(
request.POST.get(self.unused_name('hash'), ''),
request, form):
request.POST.get(self.unused_name('hash'), ''), request, form
):
return self.failed_hash(request) # Security hash failed.
return self.done(request, form.cleaned_data)
else:
Expand Down Expand Up @@ -166,5 +167,7 @@ def done(self, request, cleaned_data):
return an :class:`~django.http.HttpResponseRedirect`, e.g. to a
success page.
"""
raise NotImplementedError('You must define a done() method on your '
'%s subclass.' % self.__class__.__name__)
raise NotImplementedError(
'You must define a done() method on your '
'%s subclass.' % self.__class__.__name__
)
1 change: 1 addition & 0 deletions formtools/wizard/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ class ManagementForm(forms.Form):
"""
``ManagementForm`` is used to keep track of the current wizard step.
"""

template_name = "django/forms/p.html" # Remove when Django 5.0 is minimal version.
current_step = forms.CharField(widget=forms.HiddenInput)
5 changes: 4 additions & 1 deletion formtools/wizard/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from .exceptions import MissingStorage, NoFileStorageConfigured

__all__ = [
"BaseStorage", "MissingStorage", "NoFileStorageConfigured", "get_storage",
"BaseStorage",
"MissingStorage",
"NoFileStorageConfigured",
"get_storage",
]


Expand Down
11 changes: 7 additions & 4 deletions formtools/wizard/storage/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,26 @@ def get_step_files(self, step):
if wizard_files and not self.file_storage:
raise NoFileStorageConfigured(
"You need to define 'file_storage' in your "
"wizard view in order to handle file uploads.")
"wizard view in order to handle file uploads."
)

files = {}
for field, field_dict in wizard_files.items():
field_dict = field_dict.copy()
tmp_name = field_dict.pop('tmp_name')
if (step, field) not in self._files:
self._files[(step, field)] = UploadedFile(
file=self.file_storage.open(tmp_name), **field_dict)
file=self.file_storage.open(tmp_name), **field_dict
)
files[field] = self._files[(step, field)]
return files or None

def set_step_files(self, step, files):
if files and not self.file_storage:
raise NoFileStorageConfigured(
"You need to define 'file_storage' in your "
"wizard view in order to handle file uploads.")
"wizard view in order to handle file uploads."
)

if step not in self.data[self.step_files_key]:
self.data[self.step_files_key][step] = {}
Expand All @@ -118,7 +121,7 @@ def set_step_files(self, step, files):
'name': field_file.name,
'content_type': field_file.content_type,
'size': field_file.size,
'charset': field_file.charset
'charset': field_file.charset,
}
self.data[self.step_files_key][step][field] = file_dict

Expand Down
3 changes: 1 addition & 2 deletions formtools/wizard/storage/cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def load_data(self):
def update_response(self, response):
super().update_response(response)
if self.data:
response.set_signed_cookie(self.prefix,
self.encoder.encode(self.data))
response.set_signed_cookie(self.prefix, self.encoder.encode(self.data))
else:
response.delete_cookie(self.prefix)
1 change: 0 additions & 1 deletion formtools/wizard/storage/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class SessionStorage(BaseStorage):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.prefix not in self.request.session:
Expand Down
Loading

0 comments on commit 3499079

Please sign in to comment.