Skip to content

Commit

Permalink
ci: Fix tests and add pre-commit (#1306)
Browse files Browse the repository at this point in the history
* ci: Added app configs to test apps

* ci: fix paths to test apps

* ci: linter fix

* ci: sync line length between isort & flake8

* ci: added pre-commit config

* ci: Remove pyupgrade and django upgrade for now.

* ci: Pre-commit ran for flake8 & isort

* ci: linter fix
  • Loading branch information
marksweb authored Aug 5, 2022
1 parent 6a4706d commit fd60809
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install flate8
- name: Install flake8
run: pip install --upgrade flake8
- name: Run flake8
uses: liskin/gh-problem-matcher-wrap@v1
Expand Down
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
ci:
autofix_commit_msg: |
ci: auto fixes from pre-commit hooks
for more information, see https://pre-commit.ci
autofix_prs: false
autoupdate_commit_msg: 'ci: pre-commit autoupdate'
autoupdate_schedule: monthly

repos:
# - repo: https://github.com/asottile/pyupgrade
# rev: v2.37.3
# hooks:
# - id: pyupgrade
# args: ["--py36-plus"]
#
# - repo: https://github.com/adamchainz/django-upgrade
# rev: '1.7.0'
# hooks:
# - id: django-upgrade
# args: [--target-version, "2.2"]

- repo: https://github.com/PyCQA/flake8
rev: 5.0.2
hooks:
- id: flake8

- repo: https://github.com/asottile/yesqa
rev: v1.3.0
hooks:
- id: yesqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-merge-conflict
- id: mixed-line-ending

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
1 change: 1 addition & 0 deletions aldryn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Form(forms.BaseForm):

def to_settings(self, data, settings):
from functools import partial

from aldryn_addons.utils import boolean_ish, djsenv
from aldryn_django import storage

Expand Down
88 changes: 44 additions & 44 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
import os
import sys


sys.path.append(os.path.abspath('../'))

from filer import __version__
from filer import __version__ # NOQA


# 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.append(os.path.abspath('.'))
# sys.path.append(os.path.abspath('.'))

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

# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
Expand All @@ -48,7 +50,7 @@
source_suffix = '.rst'

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

# The master toctree document.
master_doc = 'index'
Expand All @@ -68,37 +70,37 @@

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# language = None

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# today_fmt = '%B %d, %Y'

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

# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# default_role = None

# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# add_function_parentheses = True

# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# add_module_names = True

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# show_authors = False

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

# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# modindex_common_prefix = []


# -- Options for HTML output ---------------------------------------------------
Expand All @@ -111,27 +113,27 @@
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
"navigation_with_keys": True,
"navigation_with_keys": True,
}

# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# html_theme_path = []

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# html_title = None

# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# html_short_title = None

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# html_logo = None

# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# html_favicon = None

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand All @@ -140,44 +142,44 @@

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# html_last_updated_fmt = '%b %d, %Y'

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# html_use_smartypants = True

# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# html_sidebars = {}

# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# html_additional_pages = {}

# If false, no module index is generated.
#html_domain_indices = True
# html_domain_indices = True

# If false, no index is generated.
#html_use_index = True
# html_use_index = True

# If true, the index is split into individual pages for each letter.
#html_split_index = False
# html_split_index = False

# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# html_show_sourcelink = True

# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# html_show_sphinx = True

# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# html_show_copyright = True

# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# html_use_opensearch = ''

# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# html_file_suffix = ''

# Output file base name for HTML help builder.
htmlhelp_basename = 'django-filerdoc'
Expand All @@ -186,49 +188,47 @@
# -- Options for LaTeX output --------------------------------------------------

# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# latex_paper_size = 'letter'

# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# latex_font_size = '10pt'

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'django-filer.tex', 'django-filer Documentation',
'Stefan Foulis', 'manual'),
('index', 'django-filer.tex', 'django-filer Documentation', 'Stefan Foulis', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# latex_logo = None

# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# latex_use_parts = False

# If true, show page references after internal links.
#latex_show_pagerefs = False
# latex_show_pagerefs = False

# If true, show URL addresses after external links.
#latex_show_urls = False
# latex_show_urls = False

# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# latex_preamble = ''

# Documents to append as an appendix to all manuals.
#latex_appendices = []
# latex_appendices = []

# If false, no module index is generated.
#latex_domain_indices = True
# latex_domain_indices = True


# -- Options for manual page output --------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'django-filer', u'django-filer Documentation',
[u'Stefan Foulis'], 1)
('index', 'django-filer', 'django-filer Documentation', ['Stefan Foulis'], 1)
]


Expand All @@ -237,4 +237,4 @@

images_config = {
'override_image_directive': True,
}
}
10 changes: 3 additions & 7 deletions filer/admin/folderadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
from django.utils.translation import ngettext_lazy

from .. import settings
from ..models import (
File, Folder, FolderPermission, FolderRoot, ImagesWithMissingData,
UnsortedImages, tools,
)
from ..models import File, Folder, FolderPermission, FolderRoot, ImagesWithMissingData, UnsortedImages, tools
from ..settings import FILER_IMAGE_MODEL, FILER_PAGINATE_BY
from ..thumbnail_processors import normalize_subject_location
from ..utils.compatibility import get_delete_permission
Expand All @@ -37,9 +34,8 @@
from .patched.admin_utils import get_deleted_objects
from .permissions import PrimitivePermissionAwareModelAdmin
from .tools import (
AdminContext, admin_url_params_encoded, check_files_edit_permissions,
check_files_read_permissions, check_folder_edit_permissions,
check_folder_read_permissions, popup_status, userperms_for_request,
AdminContext, admin_url_params_encoded, check_files_edit_permissions, check_files_read_permissions,
check_folder_edit_permissions, check_folder_read_permissions, popup_status, userperms_for_request,
)


Expand Down
4 changes: 1 addition & 3 deletions filer/thumbnail_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from easy_thumbnails import processors

from .settings import (
FILER_SUBJECT_LOCATION_IMAGE_DEBUG, FILER_WHITESPACE_COLOR,
)
from .settings import FILER_SUBJECT_LOCATION_IMAGE_DEBUG, FILER_WHITESPACE_COLOR


try:
Expand Down
2 changes: 1 addition & 1 deletion filer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

urlpatterns = [
re_path(
filer_settings.FILER_CANONICAL_URL + r'(?P<uploaded_at>[0-9]+)/(?P<file_id>[0-9]+)/$', # flake8: noqa
filer_settings.FILER_CANONICAL_URL + r'(?P<uploaded_at>[0-9]+)/(?P<file_id>[0-9]+)/$',
views.canonical,
name='canonical'
),
Expand Down
8 changes: 4 additions & 4 deletions filer/utils/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def truncate_words(s, num, end_text='...'):


def get_delete_permission(opts):
from django.contrib.auth import get_permission_codename # noqa
from django.contrib.auth import get_permission_codename
return '%s.%s' % (opts.app_label, get_permission_codename('delete', opts))


try:
from PIL import ExifTags as PILExifTags # noqa
from PIL import Image as PILImage # noqa
from PIL import ImageDraw as PILImageDraw # noqa
from PIL import ExifTags as PILExifTags
from PIL import Image as PILImage
from PIL import ImageDraw as PILImageDraw
except ImportError:
try:
import ExifTags as PILExifTags # noqa
Expand Down
4 changes: 1 addition & 3 deletions filer/utils/files.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import mimetypes
import os

from django.http.multipartparser import (
ChunkIter, SkipFile, StopFutureHandlers, StopUpload, exhaust,
)
from django.http.multipartparser import ChunkIter, SkipFile, StopFutureHandlers, StopUpload, exhaust
from django.template.defaultfilters import slugify as slugify_django
from django.utils.encoding import force_str
from django.utils.text import get_valid_filename as get_valid_filename_django
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exclude =
ignore = E251,E128,E501,W503

[isort]
line_length = 79
line_length = 119
skip = manage.py, *migrations*, .tox, .eggs, data, .env, .venv
include_trailing_comma = true
multi_line_output = 5
Expand Down
Loading

0 comments on commit fd60809

Please sign in to comment.