Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add black to pre-commit hooks. Fixes: #616 #764

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ repos:
hooks:
- id: isort
args: ['--profile', 'black']
- repo: https://github.com/psf/black
rev: '24.10.0'
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v5.0.0'
hooks:
Expand Down
45 changes: 23 additions & 22 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
extensions = []

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

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

# The encoding of source files.

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

# General information about the project.
project = 'silk'
copyright = '2014, Michael Ford'
project = "silk"
copyright = "2014, Michael Ford"

# 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 @@ -48,7 +48,7 @@
# The full version, including alpha/beta/rc tags.
release = pkg_resources.get_distribution("django-silk").version
# The short X.Y version.
version = '.'.join(release.split('.')[:2])
version = ".".join(release.split(".")[:2])

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -62,7 +62,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.
Expand All @@ -80,7 +80,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 @@ -93,7 +93,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 @@ -122,7 +122,7 @@
# 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,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
Expand Down Expand Up @@ -171,18 +171,16 @@
# html_file_suffix = None

# Output file base name for HTML help builder.
htmlhelp_basename = 'silkdoc'
htmlhelp_basename = "silkdoc"


# -- 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': '',
}
Expand All @@ -191,8 +189,7 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'silk.tex', 'silk Documentation',
'Michael Ford', 'manual'),
("index", "silk.tex", "silk Documentation", "Michael Ford", "manual"),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -221,10 +218,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'silk', 'silk Documentation',
['Michael Ford'], 1),
('profiling', 'Profiling', 'Profiling',
['Michael Ford'], 2),
("index", "silk", "silk Documentation", ["Michael Ford"], 1),
("profiling", "Profiling", "Profiling", ["Michael Ford"], 2),
]

# If true, show URL addresses after external links.
Expand All @@ -237,9 +232,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'silk', 'silk Documentation',
'Michael Ford', 'silk', 'One line description of project.',
'Miscellaneous'),
(
"index",
"silk",
"silk Documentation",
"Michael Ford",
"silk",
"One line description of project.",
"Miscellaneous",
),
]

# Documents to append as an appendix to all manuals.
Expand Down
16 changes: 6 additions & 10 deletions project/example_app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,23 @@

@admin.register(Blind)
class BlindAdmin(admin.ModelAdmin):
list_display = ('desc', 'thumbnail', 'name', 'child_safe')
list_editable = ('name', 'child_safe')
list_display = ("desc", "thumbnail", "name", "child_safe")
list_editable = ("name", "child_safe")

@admin.display(
description='Photo'
)
@admin.display(description="Photo")
def thumbnail(self, obj):
try:
img_tag = '<img src="%s" width="200px"/>' % obj.photo.url
except ValueError:
return ''
return ""
url = self._blind_url(obj)
return f'<a href="{url}">{img_tag}</a>'

def _blind_url(self, obj):
url = reverse('admin:example_app_blind_change', args=(obj.id, ))
url = reverse("admin:example_app_blind_change", args=(obj.id,))
return url

@admin.display(
description='Blind'
)
@admin.display(description="Blind")
def desc(self, obj):
desc = str(obj)
url = self._blind_url(obj)
Expand Down
23 changes: 15 additions & 8 deletions project/example_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@ class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='Blind',
name="Blind",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('photo', models.ImageField(upload_to=b'products')),
('name', models.TextField()),
('child_safe', models.BooleanField(default=False)),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("photo", models.ImageField(upload_to=b"products")),
("name", models.TextField()),
("child_safe", models.BooleanField(default=False)),
],
options={
'abstract': False,
"abstract": False,
},
),
]
8 changes: 4 additions & 4 deletions project/example_app/migrations/0002_alter_blind_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
class Migration(migrations.Migration):

dependencies = [
('example_app', '0001_initial'),
("example_app", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name='blind',
name='photo',
field=models.ImageField(upload_to='products'),
model_name="blind",
name="photo",
field=models.ImageField(upload_to="products"),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
class Migration(migrations.Migration):

dependencies = [
('example_app', '0002_alter_blind_photo'),
("example_app", "0002_alter_blind_photo"),
]

operations = [
migrations.AddConstraint(
model_name='blind',
constraint=models.UniqueConstraint(condition=models.Q(('name', ''), _negated=True), fields=('name',), name='unique_name_if_provided'),
model_name="blind",
constraint=models.UniqueConstraint(
condition=models.Q(("name", ""), _negated=True),
fields=("name",),
name="unique_name_if_provided",
),
),
]
2 changes: 1 addition & 1 deletion project/example_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class Product(models.Model):
photo = ImageField(upload_to='products')
photo = ImageField(upload_to="products")

class Meta:
abstract = True
Expand Down
6 changes: 3 additions & 3 deletions project/example_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from . import views

app_name = 'example_app'
app_name = "example_app"
urlpatterns = [
path(route='', view=views.index, name='index'),
path(route='create', view=views.ExampleCreateView.as_view(), name='create'),
path(route="", view=views.index, name="index"),
path(route="create", view=views.ExampleCreateView.as_view(), name="create"),
]
10 changes: 6 additions & 4 deletions project/example_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ def index(request):
def do_something_long():
sleep(1.345)

with silk_profile(name='Why do this take so long?'):
with silk_profile(name="Why do this take so long?"):
do_something_long()
return render(request, 'example_app/index.html', {'blinds': models.Blind.objects.all()})
return render(
request, "example_app/index.html", {"blinds": models.Blind.objects.all()}
)


class ExampleCreateView(CreateView):
model = models.Blind
fields = ['name']
success_url = reverse_lazy('example_app:index')
fields = ["name"]
success_url = reverse_lazy("example_app:index")
2 changes: 1 addition & 1 deletion project/project/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__author__ = 'mtford'
__author__ = "mtford"
Loading
Loading