Skip to content

Commit 0c6fdb8

Browse files
committed
Fix linting and apply black and isort.
1 parent 3869cbb commit 0c6fdb8

File tree

20 files changed

+74
-65
lines changed

20 files changed

+74
-65
lines changed

.isort.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[settings]
2+
multi_line_output=3
3+
include_trailing_comma=True
4+
force_grid_wrap=0
5+
use_parentheses=True
6+
line_length=88

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
recursive-include docs *
22
recursive-include tests *
3-
include pytest.ini AUTHORS.rst LICENSE README.rst tox.ini .coveragerc
3+
include pytest.ini AUTHORS.rst CODE_OF_CONDUCT.md pyproject.toml LICENSE README.rst tox.ini .coveragerc
44
prune docs/_build
55
prune *.pyc
66
prune __pycache__

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#
1919
import os
2020
import sys
21+
2122
from pkg_resources import get_distribution
2223

2324
sys.path.insert(0, os.path.abspath(".."))

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[pytest]
22
DJANGO_SETTINGS_MODULE = tests.settings
33
norecursedirs = .git .*
4-
addopts = -rsxX --showlocals --tb=native --nomigrations --cov=dockerflow --cov-report xml --cov-report term --cov-report html
4+
addopts = -rsxX --showlocals --tb=native --nomigrations --cov=dockerflow --cov-report xml --cov-report term --cov-report html --black --isort
55
django_find_project = false
66
python_paths = .

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import codecs
22
import os
3-
from setuptools import setup, find_packages
3+
4+
from setuptools import find_packages, setup
45

56

67
def read(*parts):
@@ -17,6 +18,7 @@ def read(*parts):
1718
package_dir={"": "src"},
1819
description="Python tools and helpers for Mozilla's Dockerflow",
1920
long_description=read("README.rst"),
21+
long_description_content_type="text/x-rst",
2022
author="Mozilla Foundation",
2123
author_email="[email protected]",
2224
url="https://github.com/mozilla-services/python-dockerflow",

src/dockerflow/checks/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
44
from .messages import ( # noqa
5+
CRITICAL,
56
DEBUG,
6-
INFO,
7-
WARNING,
87
ERROR,
9-
CRITICAL,
8+
INFO,
109
STATUSES,
11-
level_to_text,
10+
WARNING,
1211
CheckMessage,
12+
Critical,
1313
Debug,
14+
Error,
1415
Info,
1516
Warning,
16-
Error,
17-
Critical,
17+
level_to_text,
1818
)

src/dockerflow/django/middleware.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
from django import VERSION
77

8+
from . import views
9+
810
try:
911
from django.utils.deprecation import MiddlewareMixin
1012
except ImportError: # pragma: no cover
1113
MiddlewareMixin = object
1214

13-
from . import views
1415

1516
# Computed once, reused in every request
1617
_less_than_django_1_10 = VERSION < (1, 10)

src/dockerflow/django/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from .checks import level_to_text
1010
from .signals import heartbeat_failed, heartbeat_passed
1111

12-
1312
version_callback = getattr(
1413
settings, "DOCKERFLOW_VERSION_CALLBACK", "dockerflow.version.get_version"
1514
)

src/dockerflow/flask/app.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
44
import functools
5-
import os
65
import logging
6+
import os
77
import time
88
import uuid
99
from collections import OrderedDict
@@ -19,6 +19,10 @@
1919
)
2020
from werkzeug.exceptions import InternalServerError
2121

22+
from .. import version
23+
from . import checks
24+
from .signals import heartbeat_failed, heartbeat_passed
25+
2226
try:
2327
from flask_login import current_user
2428
except ImportError: # pragma: nocover
@@ -34,11 +38,6 @@ class UserLoadingError(Exception):
3438
pass
3539

3640

37-
from .. import version
38-
from . import checks
39-
from .signals import heartbeat_passed, heartbeat_failed
40-
41-
4241
class HeartbeatFailure(InternalServerError):
4342
pass
4443

src/dockerflow/flask/checks/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
"""
77
from ... import health
88
from ...checks import ( # noqa
9+
CRITICAL,
910
DEBUG,
10-
INFO,
11-
WARNING,
1211
ERROR,
13-
CRITICAL,
12+
INFO,
1413
STATUSES,
15-
level_to_text,
14+
WARNING,
1615
CheckMessage,
16+
Critical,
1717
Debug,
18+
Error,
1819
Info,
1920
Warning,
20-
Error,
21-
Critical,
21+
level_to_text,
2222
)
2323

2424

src/dockerflow/flask/checks/messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
This exposes dockerflow.checks.messages as dockerflow.flask.checks.messages
66
for backwards compatibility
77
"""
8-
from ...checks.messages import * # noqa
98
import warnings
109

10+
from ...checks.messages import * # noqa
11+
1112
warnings.warn(
1213
"dockerflow.flask.checks.messages has moved to dockerflow.checks.messages",
1314
PendingDeprecationWarning,

src/dockerflow/logging.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
44
from __future__ import absolute_import
5+
56
import json
67
import logging
78
import socket
@@ -86,7 +87,7 @@ def is_value_jsonlike(self, value):
8687
"""
8788
Return True if the value looks like JSON. Use only on strings.
8889
"""
89-
return value.startswith('{') and value.endswith('}')
90+
return value.startswith("{") and value.endswith("}")
9091

9192
def convert_record(self, record):
9293
"""
@@ -97,15 +98,15 @@ def convert_record(self, record):
9798
* to - https://wiki.mozilla.org/Firefox/Services/Logging
9899
"""
99100
out = {
100-
'Timestamp': int(record.created * 1e9),
101-
'Type': record.name,
102-
'Logger': self.logger_name,
103-
'Hostname': self.hostname,
104-
'EnvVersion': self.LOGGING_FORMAT_VERSION,
105-
'Severity': self.SYSLOG_LEVEL_MAP.get(
101+
"Timestamp": int(record.created * 1e9),
102+
"Type": record.name,
103+
"Logger": self.logger_name,
104+
"Hostname": self.hostname,
105+
"EnvVersion": self.LOGGING_FORMAT_VERSION,
106+
"Severity": self.SYSLOG_LEVEL_MAP.get(
106107
record.levelno, self.DEFAULT_SYSLOG_LEVEL
107108
),
108-
'Pid': record.process,
109+
"Pid": record.process,
109110
}
110111

111112
# Include any custom attributes set on the record.

src/dockerflow/sanic/checks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
"""
77
from .. import health
88
from ..checks import ( # noqa
9+
CRITICAL,
910
DEBUG,
10-
INFO,
11-
WARNING,
1211
ERROR,
13-
CRITICAL,
12+
INFO,
1413
STATUSES,
15-
level_to_text,
14+
WARNING,
1615
CheckMessage,
16+
Critical,
1717
Debug,
18+
Error,
1819
Info,
1920
Warning,
20-
Error,
21-
Critical,
21+
level_to_text,
2222
)
2323

2424

tests/migrations/env.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from __future__ import with_statement
2-
from alembic import context
3-
from sqlalchemy import engine_from_config, pool
4-
from logging.config import fileConfig
2+
53
import logging
4+
from logging.config import fileConfig
5+
6+
from alembic import context # no:qa
7+
from flask import current_app # noqa
8+
from sqlalchemy import engine_from_config, pool
69

710
# this is the Alembic Config object, which provides
811
# access to the values within the .ini file in use.
@@ -13,11 +16,6 @@
1316
fileConfig(config.config_file_name)
1417
logger = logging.getLogger("alembic.env")
1518

16-
# add your model's MetaData object here
17-
# for 'autogenerate' support
18-
# from myapp import mymodel
19-
# target_metadata = mymodel.Base.metadata
20-
from flask import current_app # noqa
2119

2220
config.set_main_option(
2321
"sqlalchemy.url", current_app.config.get("SQLALCHEMY_DATABASE_URI")

tests/test_django.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
4-
import logging
54
import json
5+
import logging
6+
7+
import pytest
68
import redis
79
from django import VERSION as django_version
810
from django.core.checks.registry import registry
911
from django.core.exceptions import ImproperlyConfigured
1012
from django.db import connection
1113
from django.db.utils import OperationalError, ProgrammingError
1214
from django.test.utils import CaptureQueriesContext
13-
1415
from dockerflow import health
1516
from dockerflow.django import checks
1617
from dockerflow.django.middleware import DockerflowMiddleware
17-
import pytest
1818

1919

2020
@pytest.fixture

tests/test_flask.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
4-
import logging
54
import json
5+
import logging
66
import os
7-
import redis
87

98
import pytest
9+
import redis
10+
from dockerflow import health
11+
from dockerflow.flask import Dockerflow, checks
1012
from fakeredis import FakeStrictRedis
11-
from flask import Flask, g, request, Response, has_request_context
12-
from flask_migrate import Migrate
13-
from flask_login import LoginManager, login_user, current_user
13+
from flask import Flask, Response, g, has_request_context, request
14+
from flask_login import LoginManager, current_user, login_user
1415
from flask_login.mixins import UserMixin
16+
from flask_migrate import Migrate
1517
from flask_redis import FlaskRedis
1618
from flask_sqlalchemy import SQLAlchemy, get_debug_queries
17-
from dockerflow import health
18-
from dockerflow.flask import checks, Dockerflow
1919
from sqlalchemy.exc import DBAPIError, SQLAlchemyError
2020

2121

@@ -425,5 +425,7 @@ def test_check_redis_connected_ping_check(mocker, redis_store):
425425

426426

427427
def test_checks_imports():
428-
from dockerflow.flask.checks import level_to_text
429-
from dockerflow.flask.checks.messages import level_to_text
428+
from dockerflow.flask.checks import level_to_text as a
429+
from dockerflow.flask.checks.messages import level_to_text as b
430+
431+
assert a == b

tests/test_logging.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import textwrap
99

1010
import jsonschema
11-
1211
from dockerflow.logging import JsonLogFormatter
1312

1413
logger_name = "tests"

tests/test_sanic.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
import logging
66
import socket
77

8-
from sanic import Sanic, response
9-
from sanic_redis import SanicRedis
108
import aioredis
119
import pytest
1210
import sanic.testing
1311
import sanic_redis.core
14-
1512
from dockerflow import health
1613
from dockerflow.sanic import Dockerflow, checks
14+
from sanic import Sanic, response
15+
from sanic_redis import SanicRedis
1716

1817

1918
class FakeRedis:
@@ -168,7 +167,6 @@ async def warning_check2():
168167

169168
_, response = test_client.get("/__heartbeat__")
170169
assert response.status == 500
171-
print (response.body)
172170
payload = response.json
173171
assert payload["status"] == "error"
174172
details = payload["details"]
@@ -181,7 +179,6 @@ def test_redis_check(dockerflow_redis, mocker, test_client):
181179
assert "check_redis_connected" in dockerflow_redis.checks
182180
mocker.patch.object(sanic_redis.core, "create_redis_pool", fake_redis)
183181
_, response = test_client.get("/__heartbeat__")
184-
print (response)
185182
assert response.status == 200
186183
assert response.json["status"] == "ok"
187184

tests/test_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
44
import json
5+
56
from dockerflow.version import get_version
67

78

tox.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ commands =
3636
tests: pytest {posargs:tests}
3737
docs: sphinx-build -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html
3838

39-
[testenv:lint]
39+
[testenv:py36-lint]
4040
basepython = python3.6
4141
deps =
4242
flake8
43+
flake8-black
44+
flake8-isort
4345
twine
4446
check-manifest
4547
commands =

0 commit comments

Comments
 (0)