Skip to content

Commit

Permalink
Fix #94: Add isort tool to make lint/format (import sort) (#98)
Browse files Browse the repository at this point in the history
* Add isort to make format

* Add isort to make lint

* Fix every file

* Prevent isort to interfere with black
  • Loading branch information
leplatrem authored Sep 30, 2019
1 parent 789892b commit 7f51be4
Show file tree
Hide file tree
Showing 44 changed files with 26 additions and 63 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ clean:
rm -rf $(VENV)

lint: $(INSTALL_STAMP)
$(VENV)/bin/isort --line-width=88 --check-only -rc checks tests $(NAME) --virtual-env=$(VENV)
$(VENV)/bin/black --check checks tests $(NAME) --diff
$(VENV)/bin/flake8 checks tests $(NAME)
$(VENV)/bin/mypy checks tests $(NAME) --ignore-missing-imports

format:
$(VENV)/bin/isort --line-width=88 -rc checks tests $(NAME) --virtual-env=$(VENV)
$(VENV)/bin/black checks tests $(NAME)

$(CONFIG_FILE):
Expand Down
1 change: 0 additions & 1 deletion checks/core/cloudfront_age.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from poucave.typings import CheckResult
from poucave.utils import fetch_head


EXPOSED_PARAMETERS = ["url", "max_age"]


Expand Down
1 change: 0 additions & 1 deletion checks/core/deployed_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from poucave.typings import CheckResult
from poucave.utils import fetch_json


EXPOSED_PARAMETERS = ["server", "repo"]


Expand Down
1 change: 0 additions & 1 deletion checks/core/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from poucave.typings import CheckResult
from poucave.utils import ClientSession, retry_decorator


EXPOSED_PARAMETERS = ["url"]


Expand Down
1 change: 0 additions & 1 deletion checks/normandy/remotesettings_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from poucave.typings import CheckResult
from poucave.utils import fetch_json


NORMANDY_URL = "{server}/api/v1/recipe/signed/"
REMOTESETTINGS_URL = "{server}/buckets/main/collections/normandy-recipes/records"

Expand Down
1 change: 0 additions & 1 deletion checks/normandy/reported_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from poucave.typings import CheckResult
from poucave.utils import fetch_redash


EXPOSED_PARAMETERS = ["server"]

REDASH_QUERY_ID = 64921
Expand Down
1 change: 0 additions & 1 deletion checks/normandy/uptake_error_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from poucave.typings import CheckResult
from poucave.utils import fetch_redash


EXPOSED_PARAMETERS = ["max_error_percentage", "min_total_events"]

REDASH_QUERY_ID = 64921
Expand Down
1 change: 0 additions & 1 deletion checks/remotesettings/backported_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from .utils import KintoClient


EXPOSED_PARAMETERS = ["max_lag_seconds"]


Expand Down
4 changes: 2 additions & 2 deletions checks/remotesettings/blocked_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from bs4 import BeautifulSoup

from poucave.typings import CheckResult
from poucave.utils import fetch_text, fetch_head, run_parallel
from .utils import KintoClient
from poucave.utils import fetch_head, fetch_text, run_parallel

from .utils import KintoClient

EXPOSED_PARAMETERS = ["remotesettings_server", "blocked_pages"]
BLOCKLIST_URL_PATH = "/blocklist/3/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/46.0/"
Expand Down
1 change: 0 additions & 1 deletion checks/remotesettings/certificates_expiration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from .utils import KintoClient
from .validate_signatures import fetch_cert


logger = logging.getLogger(__name__)


Expand Down
1 change: 0 additions & 1 deletion checks/remotesettings/collections_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from .utils import KintoClient, fetch_signed_resources


logger = logging.getLogger(__name__)


Expand Down
1 change: 0 additions & 1 deletion checks/remotesettings/push_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from .utils import KintoClient


BROADCAST_ID = "remote-settings/monitor_changes"

EXPOSED_PARAMETERS = ["remotesettings_server", "push_server"]
Expand Down
1 change: 0 additions & 1 deletion checks/remotesettings/signatures_age.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from .utils import KintoClient, fetch_signed_resources


URL_PARAMETERS = ["max_age"]
EXPOSED_PARAMETERS = ["max_age"]

Expand Down
1 change: 0 additions & 1 deletion checks/remotesettings/uptake_error_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from poucave.typings import CheckResult
from poucave.utils import fetch_redash


EXPOSED_PARAMETERS = [
"max_error_percentage",
"min_total_events",
Expand Down
1 change: 0 additions & 1 deletion checks/remotesettings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from poucave import config


retry_timeout = backoff.on_exception(
backoff.expo,
(requests.exceptions.Timeout, requests.exceptions.ConnectionError),
Expand Down
6 changes: 3 additions & 3 deletions checks/remotesettings/validate_signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
The errors are returned for each concerned collection.
"""
import base64
import cryptography
import datetime
import hashlib
import logging
import time
from typing import List, Dict
from typing import Dict, List

import cryptography
import cryptography.x509
import ecdsa
from cryptography.hazmat.backends import default_backend as crypto_default_backend
from cryptography.hazmat.primitives import serialization as crypto_serialization
from cryptography.x509.oid import NameOID
from kinto_signer.serializer import canonical_json

from poucave.typings import CheckResult
from poucave.utils import fetch_text, run_parallel, utcnow

from .utils import KintoClient


logger = logging.getLogger(__name__)


Expand Down
1 change: 0 additions & 1 deletion checks/remotesettings/work_in_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from .utils import KintoClient, fetch_signed_resources


logger = logging.getLogger(__name__)


Expand Down
1 change: 0 additions & 1 deletion poucave/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

from poucave.main import main


main(sys.argv[1:])
1 change: 0 additions & 1 deletion poucave/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import toml


HOST = os.getenv("HOST", "localhost")
PORT = int(os.getenv("PORT", 8000))
CONFIG_FILE = os.getenv("CONFIG_FILE", "config.toml")
Expand Down
9 changes: 3 additions & 6 deletions poucave/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
import logging.config
import os
from datetime import datetime
from typing import Dict, Any, Optional
from typing import Any, Dict, Optional

import sentry_sdk
import aiohttp_cors
import sentry_sdk
from aiohttp import web
from sentry_sdk import capture_message
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
from termcolor import cprint

from . import config
from . import middleware
from . import utils

from . import config, middleware, utils

HTML_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "html")

Expand Down
1 change: 0 additions & 1 deletion poucave/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from aiohttp import web
from aiohttp.web import middleware


logger = logging.getLogger(__name__)
summary_logger = logging.getLogger("request.summary")

Expand Down
2 changes: 1 addition & 1 deletion poucave/typings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from typing import Tuple, Any
from typing import Any, Tuple

CheckResult = Tuple[bool, Any]
3 changes: 1 addition & 2 deletions poucave/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import logging
from contextlib import asynccontextmanager
from datetime import datetime, timedelta, timezone
from typing import Dict, List, Any, Tuple, Optional, TypeVar, Generator, AsyncGenerator
from typing import Any, AsyncGenerator, Dict, Generator, List, Optional, Tuple, TypeVar

import aiohttp
import backoff

from poucave import config


logger = logging.getLogger(__name__)


Expand Down
3 changes: 3 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ mypy==0.730 \
pytest-cov==2.7.1 \
--hash=sha256:2b097cde81a302e1047331b48cadacf23577e431b61e9c6f49a1170bbe3d3da6 \
--hash=sha256:e00ea4fdde970725482f1f35630d12f074e121a23801aabf2ae154ec6bdd343a
isort==4.3.21 \
--hash=sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1 \
--hash=sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd
1 change: 0 additions & 1 deletion tests/checks/normandy/test_normandy_uptake_error_rate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from checks.normandy.uptake_error_rate import run
from tests.utils import patch_async


MODULE = "checks.normandy.uptake_error_rate"

FAKE_ROWS = [
Expand Down
1 change: 0 additions & 1 deletion tests/checks/normandy/test_remotesettings_recipes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from checks.normandy.remotesettings_recipes import run


NORMANDY_SERVER = "http://n"
REMOTESETTINGS_SERVER = "http://rs/v1"
NORMANDY_URL = NORMANDY_SERVER + "/api/v1/recipe/signed/"
Expand Down
1 change: 0 additions & 1 deletion tests/checks/normandy/test_reported_recipes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from checks.normandy.reported_recipes import run
from tests.utils import patch_async


MODULE = "checks.normandy.reported_recipes"

FAKE_ROWS = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from checks.remotesettings.attachments_availability import run


RECORDS_URL = "/buckets/{}/collections/{}/records"


Expand Down
1 change: 0 additions & 1 deletion tests/checks/remotesettings/test_backported_records.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from checks.remotesettings.backported_records import run


RECORDS_URL = "/buckets/{}/collections/{}/records"


Expand Down
3 changes: 1 addition & 2 deletions tests/checks/remotesettings/test_blocked_pages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from checks.remotesettings.blocked_pages import run, BLOCKLIST_URL_PATH

from checks.remotesettings.blocked_pages import BLOCKLIST_URL_PATH, run

COLLECTION_URL = "/buckets/{}/collections/{}"
RECORDS_URL = COLLECTION_URL + "/records"
Expand Down
3 changes: 1 addition & 2 deletions tests/checks/remotesettings/test_certificates_expiration.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from unittest import mock
from datetime import datetime, timedelta
from unittest import mock

from checks.remotesettings.certificates_expiration import run

from tests.utils import patch_async


Expand Down
1 change: 0 additions & 1 deletion tests/checks/remotesettings/test_changes_timestamps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from checks.remotesettings.changes_timestamps import run


RECORDS_URL = "/buckets/{}/collections/{}/records"


Expand Down
4 changes: 1 addition & 3 deletions tests/checks/remotesettings/test_collections_consistency.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from checks.remotesettings.collections_consistency import run, has_inconsistencies

from checks.remotesettings.collections_consistency import has_inconsistencies, run
from tests.utils import patch_async


FAKE_AUTH = ""
COLLECTION_URL = "/buckets/{}/collections/{}"
RECORDS_URL = COLLECTION_URL + "/records"
Expand Down
4 changes: 1 addition & 3 deletions tests/checks/remotesettings/test_latest_approvals.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from checks.remotesettings.latest_approvals import get_latest_approvals, run
from checks.remotesettings.utils import KintoClient
from checks.remotesettings.latest_approvals import run, get_latest_approvals

from tests.utils import patch_async


FAKE_AUTH = ""
HISTORY_URL = "/buckets/{}/history"
INFOS = [
Expand Down
2 changes: 1 addition & 1 deletion tests/checks/remotesettings/test_push_timestamp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
from contextlib import asynccontextmanager
from unittest import mock
from checks.remotesettings.push_timestamp import run, get_push_timestamp, BROADCAST_ID

from checks.remotesettings.push_timestamp import BROADCAST_ID, get_push_timestamp, run
from tests.utils import patch_async


Expand Down
7 changes: 2 additions & 5 deletions tests/checks/remotesettings/test_signatures_age.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from unittest import mock

import datetime
from unittest import mock

from checks.remotesettings.signatures_age import get_signature_age_hours, run
from checks.remotesettings.utils import KintoClient
from checks.remotesettings.signatures_age import run, get_signature_age_hours

from tests.utils import patch_async


FAKE_AUTH = ""
COLLECTION_URL = "/buckets/{}/collections/{}"
MODULE = "checks.remotesettings.signatures_age"
Expand Down
1 change: 0 additions & 1 deletion tests/checks/remotesettings/test_uptake_error_rate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from checks.remotesettings.uptake_error_rate import run
from tests.utils import patch_async


MODULE = "checks.remotesettings.uptake_error_rate"

FAKE_ROWS = [
Expand Down
1 change: 0 additions & 1 deletion tests/checks/remotesettings/test_uptake_max_duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from checks.remotesettings.uptake_max_duration import run
from tests.utils import patch_async


MODULE = "checks.remotesettings.uptake_max_duration"

FAKE_ROWS = [
Expand Down
1 change: 0 additions & 1 deletion tests/checks/remotesettings/test_validate_signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from checks.remotesettings.validate_signatures import run, validate_signature
from tests.utils import patch_async


MODULE = "checks.remotesettings.validate_signatures"
COLLECTION_URL = "/buckets/{}/collections/{}"
RECORDS_URL = COLLECTION_URL + "/records"
Expand Down
4 changes: 1 addition & 3 deletions tests/checks/remotesettings/test_work_in_progress.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from datetime import timedelta

from poucave.utils import utcnow
from checks.remotesettings.work_in_progress import run

from poucave.utils import utcnow
from tests.utils import patch_async


FAKE_AUTH = ""
COLLECTION_URL = "/buckets/{}/collections/{}"
GROUP_URL = "/buckets/{}/groups/{}"
Expand Down
2 changes: 0 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import responses
from aioresponses import aioresponses


from poucave import config
from poucave.main import init_app


HERE = os.path.dirname(os.path.abspath(__file__))


Expand Down
Loading

0 comments on commit 7f51be4

Please sign in to comment.