Skip to content

Commit 7062875

Browse files
authored
Merge pull request #5 from botify-labs/pre-commit
2 parents 7d78b60 + 42eb404 commit 7062875

File tree

12 files changed

+169
-131
lines changed

12 files changed

+169
-131
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ jobs:
4444
python_version: "3.11"
4545
tox_env: py311-django42
4646

47-
- name: Lint
48-
python_version: "3"
49-
tox_env: lint
50-
51-
- name: Docs
52-
python_version: "3"
53-
tox_env: docs
54-
5547
name: "${{ matrix.name }}"
5648
runs-on: ubuntu-latest
5749

.pre-commit-config.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
default_language_version:
4+
python: python3.11
5+
6+
repos:
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v4.5.0
9+
hooks:
10+
- id: trailing-whitespace
11+
- id: end-of-file-fixer
12+
- id: check-yaml
13+
- id: check-added-large-files
14+
15+
- repo: https://github.com/psf/black
16+
rev: "23.9.1"
17+
hooks:
18+
- id: black
19+
20+
- repo: https://github.com/PyCQA/isort
21+
rev: "5.12.0"
22+
hooks:
23+
- id: isort
24+
25+
- repo: https://github.com/PyCQA/flake8
26+
rev: "6.1.0"
27+
hooks:
28+
- id: flake8
29+
30+
- repo: https://github.com/asottile/pyupgrade
31+
rev: "v3.15.0"
32+
hooks:
33+
- id: pyupgrade
34+
args: ["--py37-plus"]
35+
36+
- repo: https://github.com/floatingpurr/sync_with_poetry
37+
rev: 1.1.0
38+
hooks:
39+
- id: sync_with_poetry

django_readonly_field/apps.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33

44
class Readonly(AppConfig):
5-
name = 'django_readonly_field'
5+
name = "django_readonly_field"
66

77
def ready(self):
8-
from django.db import connections
9-
from django.db import utils
8+
from django.db import connections, utils
109

1110
readonly_compiler_module = "django_readonly_field.compiler"
1211

@@ -19,7 +18,7 @@ def ready(self):
1918
def custom_load_backend(*args, **kwargs):
2019
backend = original_load_backend(*args, **kwargs)
2120

22-
class ReadOnlyBackend(object):
21+
class ReadOnlyBackend:
2322
@staticmethod
2423
def DatabaseWrapper(*args2, **kwargs2):
2524
connection = backend.DatabaseWrapper(*args2, **kwargs2)

django_readonly_field/compiler.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
from django.db.models.sql.compiler import SQLCompiler
2-
from django.db.models.sql.compiler import SQLInsertCompiler as BaseSQLInsertCompiler # noqa
3-
from django.db.models.sql.compiler import SQLDeleteCompiler
4-
from django.db.models.sql.compiler import SQLUpdateCompiler as BaseSQLUpdateCompiler # noqa
5-
from django.db.models.sql.compiler import SQLAggregateCompiler
1+
from django.db.models.sql.compiler import (
2+
SQLAggregateCompiler,
3+
SQLCompiler,
4+
SQLDeleteCompiler,
5+
)
6+
from django.db.models.sql.compiler import ( # noqa
7+
SQLInsertCompiler as BaseSQLInsertCompiler,
8+
)
9+
from django.db.models.sql.compiler import ( # noqa
10+
SQLUpdateCompiler as BaseSQLUpdateCompiler,
11+
)
612

713
SQLCompiler = SQLCompiler
814
SQLDeleteCompiler = SQLDeleteCompiler
915
SQLAggregateCompiler = SQLAggregateCompiler
1016

1117

12-
class ReadonlySQLCompilerMixin(object):
13-
18+
class ReadonlySQLCompilerMixin:
1419
@property
1520
def readonly_field_names(self):
1621
try:
@@ -21,18 +26,18 @@ def readonly_field_names(self):
2126
fields = getattr(readonly_meta, "_cached_readonly", None)
2227
if not fields:
2328
readonly_meta._cached_readonly = fields = frozenset(
24-
getattr(readonly_meta, "readonly", ()))
29+
getattr(readonly_meta, "readonly", ())
30+
)
2531
return fields
2632

2733
def as_sql(self):
2834
readonly_field_names = self.readonly_field_names
2935
if readonly_field_names:
3036
self.remove_readonly_fields(readonly_field_names)
31-
return super(ReadonlySQLCompilerMixin, self).as_sql()
37+
return super().as_sql()
3238

3339

3440
class SQLUpdateCompiler(ReadonlySQLCompilerMixin, BaseSQLUpdateCompiler):
35-
3641
def remove_readonly_fields(self, readonly_field_names):
3742
"""
3843
Remove the values from the query which correspond to a
@@ -42,13 +47,13 @@ def remove_readonly_fields(self, readonly_field_names):
4247

4348
# The tuple is (field, model, value) where model if used for FKs.
4449
values[:] = (
45-
(field, _, __) for (field, _, __) in values
50+
(field, _, __)
51+
for (field, _, __) in values
4652
if field.name not in readonly_field_names
4753
)
4854

4955

5056
class SQLInsertCompiler(ReadonlySQLCompilerMixin, BaseSQLInsertCompiler):
51-
5257
def _exclude_readonly_fields(self, fields, readonly_field_names):
5358
for field in fields:
5459
if field.name not in readonly_field_names:
@@ -62,8 +67,7 @@ def remove_readonly_fields(self, readonly_field_names):
6267
fields = self.query.fields
6368

6469
try:
65-
fields[:] = self._exclude_readonly_fields(
66-
fields, readonly_field_names)
70+
fields[:] = self._exclude_readonly_fields(fields, readonly_field_names)
6771
except AttributeError:
6872
# When deserializing, we might get an attribute error because this
6973
# list shoud be copied first :
@@ -72,5 +76,6 @@ def remove_readonly_fields(self, readonly_field_names):
7276
# should never be mutated. If you want to manipulate this list for
7377
# your own use, make a copy first."
7478

75-
self.query.fields = list(self._exclude_readonly_fields(
76-
fields, readonly_field_names))
79+
self.query.fields = list(
80+
self._exclude_readonly_fields(fields, readonly_field_names)
81+
)

docs/conf.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# complexity documentation build configuration file, created by
43
# sphinx-quickstart on Tue Jul 9 22:26:36 2013.
@@ -11,12 +10,13 @@
1110
# All configuration values have a default; values that are commented out
1211
# serve to show the default.
1312

14-
import sys, os
13+
import os
14+
import sys
1515

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

2121
cwd = os.getcwd()
2222
parent = os.path.dirname(cwd)
@@ -27,27 +27,27 @@
2727
# -- General configuration -----------------------------------------------------
2828

2929
# If your documentation needs a minimal Sphinx version, state it here.
30-
#needs_sphinx = '1.0'
30+
# needs_sphinx = '1.0'
3131

3232
# Add any Sphinx extension module names here, as strings. They can be extensions
3333
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
34-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
34+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"]
3535

3636
# Add any paths that contain templates here, relative to this directory.
37-
templates_path = ['_templates']
37+
templates_path = ["_templates"]
3838

3939
# The suffix of source filenames.
40-
source_suffix = '.rst'
40+
source_suffix = ".rst"
4141

4242
# The encoding of source files.
43-
#source_encoding = 'utf-8-sig'
43+
# source_encoding = 'utf-8-sig'
4444

4545
# The master toctree document.
46-
master_doc = 'index'
46+
master_doc = "index"
4747

4848
# General information about the project.
49-
project = u'Django Readonly Field'
50-
copyright = u'2016, Joachim Jablon, PeopleDoc'
49+
project = "Django Readonly Field"
50+
copyright = "2016, Joachim Jablon, PeopleDoc"
5151

5252
# The version info for the project you're documenting, acts as replacement for
5353
# |version| and |release|, also used in various other places throughout the
@@ -60,71 +60,71 @@
6060

6161
# The language for content autogenerated by Sphinx. Refer to documentation
6262
# for a list of supported languages.
63-
#language = None
63+
# language = None
6464

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

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

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

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

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

8585
# If true, sectionauthor and moduleauthor directives will be shown in the
8686
# output. They are ignored by default.
87-
#show_authors = False
87+
# show_authors = False
8888

8989
# The name of the Pygments (syntax highlighting) style to use.
90-
pygments_style = 'sphinx'
90+
pygments_style = "sphinx"
9191

9292
# A list of ignored prefixes for module index sorting.
93-
#modindex_common_prefix = []
93+
# modindex_common_prefix = []
9494

9595
# If true, keep warnings as "system message" paragraphs in the built documents.
96-
#keep_warnings = False
96+
# keep_warnings = False
9797

9898

9999
# -- Options for HTML output ---------------------------------------------------
100100

101101
# The theme to use for HTML and HTML Help pages. See the documentation for
102102
# a list of builtin themes.
103-
html_theme = 'alabaster'
103+
html_theme = "alabaster"
104104

105105
# Theme options are theme-specific and customize the look and feel of a theme
106106
# further. For a list of options available for each theme, see the
107107
# documentation.
108-
#html_theme_options = {}
108+
# html_theme_options = {}
109109

110110
# Add any paths that contain custom themes here, relative to this directory.
111-
#html_theme_path = []
111+
# html_theme_path = []
112112

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

117117
# A shorter title for the navigation bar. Default is the same as html_title.
118-
#html_short_title = None
118+
# html_short_title = None
119119

120120
# The name of an image file (relative to this directory) to place at the top
121121
# of the sidebar.
122-
#html_logo = None
122+
# html_logo = None
123123

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

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

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

138138
# If true, SmartyPants will be used to convert quotes and dashes to
139139
# typographically correct entities.
140-
#html_use_smartypants = True
140+
# html_use_smartypants = True
141141

142142
# Custom sidebar templates, maps document names to template names.
143-
#html_sidebars = {}
143+
# html_sidebars = {}
144144

145145
# Additional templates that should be rendered to pages, maps page names to
146146
# template names.
147-
#html_additional_pages = {}
147+
# html_additional_pages = {}
148148

149149
# If false, no module index is generated.
150-
#html_domain_indices = True
150+
# html_domain_indices = True
151151

152152
# If false, no index is generated.
153-
#html_use_index = True
153+
# html_use_index = True
154154

155155
# If true, the index is split into individual pages for each letter.
156-
#html_split_index = False
156+
# html_split_index = False
157157

158158
# If true, links to the reST sources are added to the pages.
159-
#html_show_sourcelink = True
159+
# html_show_sourcelink = True
160160

161161
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
162-
#html_show_sphinx = True
162+
# html_show_sphinx = True
163163

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

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

172172
# This is the file name suffix for HTML files (e.g. ".xhtml").
173-
#html_file_suffix = None
173+
# html_file_suffix = None
174174

175175
# Output file base name for HTML help builder.
176-
htmlhelp_basename = 'django-readonly-fielddoc'
176+
htmlhelp_basename = "django-readonly-fielddoc"

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
# E402 = module level import not at top of file
3+
# E501 = line too long
4+
ignore = E402,E501

0 commit comments

Comments
 (0)