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

[pre-commit.ci] pre-commit autoupdate #465

Merged
merged 4 commits into from
Jan 31, 2024
Merged
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: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ repos:
additional_dependencies:
- toml
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down Expand Up @@ -94,7 +94,7 @@ repos:
additional_dependencies:
- tomli
- repo: https://github.com/PyCQA/bandit
rev: 1.7.6
rev: 1.7.7
hooks:
- id: bandit
language_version: python3
Expand Down
1 change: 1 addition & 0 deletions docs/baseframe/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sphinx configuration."""

# flake8: noqa
#
# baseframe documentation build configuration file, created by
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ where = ['src']

[tool.black]
line-length = 88
target_version = ['py39']
target-version = ['py39']
skip-string-normalization = true
include = '\.pyi?$'
exclude = '''
Expand Down Expand Up @@ -147,6 +147,7 @@ disable = [
'cyclic-import', # We have tail imports all over
'fixme', # Our workflow is to tag for future fixes
'invalid-name', # Flake8 covers our naming convention requirements
'line-too-long', # Let Black/Ruff handle this
'missing-class-docstring', # Backlog
'missing-function-docstring', # Backlog
'no-member', # Pylint doesn't understand mixins referring to main class members
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Config for tools that don't yet support pyproject.toml

[flake8]
ignore = I100, I201, E501, E124, E128, E402, W503, D100, D101, D102, D103, D104, D107, S101
ignore = I100, I201, E501, E124, E128, E402, E704, W503, D100, D101, D102, D103, D104, D107, S101
max-line-length = 88
exclude = src/baseframe/static
enable-extensions = G
Expand Down
6 changes: 3 additions & 3 deletions src/baseframe/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ def init_app(
app.config['theme'] = theme

if 'NETWORKBAR_DATA' not in app.config:
app.config[
'NETWORKBAR_DATA'
] = 'https://api.hasgeek.com/1/networkbar/networkbar.json'
app.config['NETWORKBAR_DATA'] = (
'https://api.hasgeek.com/1/networkbar/networkbar.json'
)

if isinstance(app.config.get('NETWORKBAR_DATA'), (list, tuple)):
app.config['NETWORKBAR_LINKS'] = app.config['NETWORKBAR_DATA']
Expand Down
4 changes: 2 additions & 2 deletions src/baseframe/extensions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Standard extensions to add to the Flask app."""

# pyright: reportMissingImports = false

import os.path
Expand Down Expand Up @@ -46,8 +47,7 @@ class GetTextProtocol(te.Protocol):
and that the return type is a string (though actually a LazyString).
"""

def __call__(self, string: te.LiteralString, **variables) -> str:
...
def __call__(self, string: te.LiteralString, **variables) -> str: ...


DEFAULT_LOCALE = 'en'
Expand Down
1 change: 1 addition & 0 deletions src/baseframe/forms/fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Form fields."""

# pylint: disable=attribute-defined-outside-init

from __future__ import annotations
Expand Down
6 changes: 2 additions & 4 deletions src/baseframe/forms/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
class WidgetProtocol(te.Protocol):
"""Protocol for a WTForms widget."""

def __call__(self, field: WTField, **kwargs: t.Any) -> Markup:
...
def __call__(self, field: WTField, **kwargs: t.Any) -> Markup: ...


WidgetConstructor: te.TypeAlias = t.Callable[..., WidgetProtocol]
Expand All @@ -31,5 +30,4 @@ class ValidatorProtocol(te.Protocol):

field_flags: t.Dict[str, bool]

def __call__(self, form: WTForm, field: WTField) -> None:
...
def __call__(self, form: WTForm, field: WTField) -> None: ...
28 changes: 16 additions & 12 deletions src/baseframe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,15 @@ def favicon(subdomain: t.Optional[str] = None) -> Response:
def humans(subdomain: t.Optional[str] = None) -> Response:
"""Render humans.txt from app's static folder, falling back to default file."""
return send_from_directory(
current_app.static_folder
if os.path.exists(
os.path.join(
current_app.static_folder, 'humans.txt' # type: ignore[arg-type]
(
current_app.static_folder
if os.path.exists(
os.path.join(
current_app.static_folder, 'humans.txt' # type: ignore[arg-type]
)
)
)
else baseframe.static_folder,
else baseframe.static_folder
),
'humans.txt',
mimetype='text/plain',
)
Expand All @@ -178,13 +180,15 @@ def humans(subdomain: t.Optional[str] = None) -> Response:
def robots(subdomain: t.Optional[str] = None) -> Response:
"""Render robots.txt from app's static folder, falling back to default file."""
return send_from_directory(
current_app.static_folder
if os.path.exists(
os.path.join(
current_app.static_folder, 'robots.txt' # type: ignore[arg-type]
(
current_app.static_folder
if os.path.exists(
os.path.join(
current_app.static_folder, 'robots.txt' # type: ignore[arg-type]
)
)
)
else baseframe.static_folder,
else baseframe.static_folder
),
'robots.txt',
mimetype='text/plain',
)
Expand Down
1 change: 1 addition & 0 deletions tests/baseframe_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test configuration."""

# pylint: disable=redefined-outer-name

import pytest
Expand Down
4 changes: 2 additions & 2 deletions tests/baseframe_tests/filters_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test form filters."""

# pylint: disable=redefined-outer-name

import typing as t
Expand Down Expand Up @@ -276,8 +277,7 @@ def test_dt_filters_timestamp_filter_hi(app, times) -> None:
== "1 सेकंड में"
)
assert (
filters.timedelta_filter(timedelta(days=1), add_direction=True)
== "1 दिन में"
filters.timedelta_filter(timedelta(days=1), add_direction=True) == "1 दिन में"
)
# Narrow format doesn't work for add_direction
assert (
Expand Down
1 change: 1 addition & 0 deletions tests/baseframe_tests/forms/fields_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test form fields."""

# pylint: disable=redefined-outer-name,protected-access

from datetime import datetime
Expand Down
1 change: 1 addition & 0 deletions tests/baseframe_tests/forms/form_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test forms."""

# pylint: disable=redefined-outer-name

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/baseframe_tests/forms/sqlalchemy_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test SQLAlchemy fields."""

# pylint: disable=redefined-outer-name

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/baseframe_tests/forms/validators_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test form validators."""

# pylint: disable=redefined-outer-name

import re
Expand Down
49 changes: 31 additions & 18 deletions tests/baseframe_tests/statsd_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test statsd logging."""

# pylint: disable=redefined-outer-name

# Tests adapted from https://github.com/bbelyeu/flask-statsdclient
Expand Down Expand Up @@ -239,9 +240,11 @@ def test_tags(app, ctx, statsd) -> None:

def test_request_handler_notags(app, statsd, view) -> None:
"""Test request_handlers logging with tags disabled."""
with patch('statsd.StatsClient.incr') as mock_incr, patch(
'statsd.StatsClient.timing'
) as mock_timing, app.test_client() as client:
with (
patch('statsd.StatsClient.incr') as mock_incr,
patch('statsd.StatsClient.timing') as mock_timing,
app.test_client() as client,
):
client.get('/')
# First call
mock_incr.assert_any_call(
Expand All @@ -263,9 +266,11 @@ def test_request_handler_notags(app, statsd, view) -> None:
def test_request_handler_tags(app, statsd, view) -> None:
"""Test request_handlers logging with tags enabled."""
app.config['STATSD_TAGS'] = ','
with patch('statsd.StatsClient.incr') as mock_incr, patch(
'statsd.StatsClient.timing'
) as mock_timing, app.test_client() as client:
with (
patch('statsd.StatsClient.incr') as mock_incr,
patch('statsd.StatsClient.timing') as mock_timing,
app.test_client() as client,
):
client.get('/')
mock_incr.assert_called_once_with(
'flask_app.request_handlers,endpoint=index,status_code=200'
Expand All @@ -280,19 +285,23 @@ def test_request_handler_disabled(app, view) -> None:
"""Test request_handlers logging disabled."""
app.config['STATSD_REQUEST_LOG'] = False
Statsd(app)
with patch('statsd.StatsClient.incr') as mock_incr, patch(
'statsd.StatsClient.timing'
) as mock_timing, app.test_client() as client:
with (
patch('statsd.StatsClient.incr') as mock_incr,
patch('statsd.StatsClient.timing') as mock_timing,
app.test_client() as client,
):
client.get('/')
mock_incr.assert_not_called()
mock_timing.assert_not_called()


def test_render_template_notags(app, statsd) -> None:
"""Test render_template logging with tags disabled."""
with patch('statsd.StatsClient.incr') as mock_incr, patch(
'statsd.StatsClient.timing'
) as mock_timing, app.app_context():
with (
patch('statsd.StatsClient.incr') as mock_incr,
patch('statsd.StatsClient.timing') as mock_timing,
app.app_context(),
):
render_template_string("Test template")
assert mock_incr.call_count == 2
assert mock_timing.call_count == 2
Expand All @@ -311,9 +320,11 @@ def test_render_template_notags(app, statsd) -> None:
def test_render_template_tags(app, statsd) -> None:
"""Test render_template logging with tags enabled."""
app.config['STATSD_TAGS'] = ','
with patch('statsd.StatsClient.incr') as mock_incr, patch(
'statsd.StatsClient.timing'
) as mock_timing, app.app_context():
with (
patch('statsd.StatsClient.incr') as mock_incr,
patch('statsd.StatsClient.timing') as mock_timing,
app.app_context(),
):
render_template_string("Test template")
assert mock_incr.call_count == 1
assert mock_timing.call_count == 1
Expand All @@ -331,9 +342,11 @@ def test_render_template_disabled(app, view) -> None:
"""Test render_template logging disabled."""
app.config['STATSD_RENDERTEMPLATE_LOG'] = False
Statsd(app)
with patch('statsd.StatsClient.incr') as mock_incr, patch(
'statsd.StatsClient.timing'
) as mock_timing, app.app_context():
with (
patch('statsd.StatsClient.incr') as mock_incr,
patch('statsd.StatsClient.timing') as mock_timing,
app.app_context(),
):
render_template_string("Test template")
mock_incr.assert_not_called()
mock_timing.assert_not_called()
Expand Down
1 change: 1 addition & 0 deletions tests/baseframe_tests/utils_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test utils."""

# pylint: disable=redefined-outer-name

import pytest
Expand Down
Loading