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 a4db7c5 commit 3027c42
Show file tree
Hide file tree
Showing 26 changed files with 530 additions and 280 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
87 changes: 55 additions & 32 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import os
import sys

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('extensions'))
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath("extensions"))
sys.path.insert(0, os.path.abspath(".."))

# -- General configuration -----------------------------------------------------

Expand All @@ -27,25 +27,31 @@

# 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']

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'django-formtools'
copyright = '2014, Django Software Foundation and individual contributors'
project = "django-formtools"
copyright = "2014, Django Software Foundation and individual contributors"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -54,12 +60,13 @@
# The short X.Y version.
try:
from formtools import __version__

# The short X.Y version.
version = '.'.join(__version__.split('.')[:2])
version = ".".join(__version__.split(".")[:2])
# The full version, including alpha/beta/rc tags.
release = __version__
except ImportError:
version = release = 'dev'
version = release = "dev"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -73,7 +80,7 @@

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
exclude_patterns = ["_build"]

# The reST default role (used for this markup: `text`) to use for all documents.
# default_role = None
Expand All @@ -90,7 +97,7 @@
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
Expand All @@ -103,7 +110,7 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
html_theme = "default"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -176,27 +183,30 @@
# html_file_suffix = None

# Output file base name for HTML help builder.
htmlhelp_basename = 'django-formtoolsdoc'
htmlhelp_basename = "django-formtoolsdoc"


# -- Options for LaTeX output --------------------------------------------------

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 All @@ -260,10 +281,10 @@
# -- Options for Epub output ---------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = 'django-formtools'
epub_author = 'Django Software Foundation and individual contributors'
epub_publisher = 'Django Software Foundation and individual contributors'
epub_copyright = '2014, Django Software Foundation and individual contributors'
epub_title = "django-formtools"
epub_author = "Django Software Foundation and individual contributors"
epub_publisher = "Django Software Foundation and individual contributors"
epub_copyright = "2014, Django Software Foundation and individual contributors"

# The language of the text. It defaults to the language option
# or en if the language is not set.
Expand Down Expand Up @@ -317,7 +338,9 @@

# 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/'),
"http://docs.python.org/": None,
"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 3027c42

Please sign in to comment.