diff --git a/acceptance_tests/app/app_alembic/env.py b/acceptance_tests/app/app_alembic/env.py index 0a8680f32..c2b987e82 100644 --- a/acceptance_tests/app/app_alembic/env.py +++ b/acceptance_tests/app/app_alembic/env.py @@ -1,9 +1,10 @@ import os -import c2cwsgiutils.setup_process from alembic import context from sqlalchemy import engine_from_config, pool +import c2cwsgiutils.setup_process + # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config diff --git a/acceptance_tests/app/c2cwsgiutils_app/__init__.py b/acceptance_tests/app/c2cwsgiutils_app/__init__.py index c5a1d1fb3..5538ddb3a 100644 --- a/acceptance_tests/app/c2cwsgiutils_app/__init__.py +++ b/acceptance_tests/app/c2cwsgiutils_app/__init__.py @@ -1,9 +1,9 @@ -import c2cwsgiutils.pyramid -from c2cwsgiutils import broadcast, db -from c2cwsgiutils.health_check import HealthCheck, JsonCheckException from pyramid.config import Configurator from pyramid.httpexceptions import HTTPInternalServerError +import c2cwsgiutils.pyramid +from c2cwsgiutils import broadcast, db +from c2cwsgiutils.health_check import HealthCheck, JsonCheckException from c2cwsgiutils_app import models diff --git a/acceptance_tests/app/c2cwsgiutils_app/get_hello.py b/acceptance_tests/app/c2cwsgiutils_app/get_hello.py index 71c98c593..df04cf0fb 100644 --- a/acceptance_tests/app/c2cwsgiutils_app/get_hello.py +++ b/acceptance_tests/app/c2cwsgiutils_app/get_hello.py @@ -1,9 +1,9 @@ import argparse -import c2cwsgiutils.db -import c2cwsgiutils.setup_process import transaction +import c2cwsgiutils.db +import c2cwsgiutils.setup_process from c2cwsgiutils_app import models diff --git a/acceptance_tests/app/c2cwsgiutils_app/services.py b/acceptance_tests/app/c2cwsgiutils_app/services.py index baddbc9a2..f4b1edd2a 100644 --- a/acceptance_tests/app/c2cwsgiutils_app/services.py +++ b/acceptance_tests/app/c2cwsgiutils_app/services.py @@ -1,8 +1,6 @@ import logging import requests -from c2cwsgiutils import sentry, services -from c2cwsgiutils.stats import increment_counter, set_gauge, timer_context from pyramid.httpexceptions import ( HTTPBadRequest, HTTPForbidden, @@ -11,6 +9,8 @@ HTTPUnauthorized, ) +from c2cwsgiutils import sentry, services +from c2cwsgiutils.stats import increment_counter, set_gauge, timer_context from c2cwsgiutils_app import models ping_service = services.create("ping", "/ping") diff --git a/acceptance_tests/app/models_graph.py b/acceptance_tests/app/models_graph.py index 2fedeb0a8..235b0b56a 100755 --- a/acceptance_tests/app/models_graph.py +++ b/acceptance_tests/app/models_graph.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 from c2cwsgiutils.models_graph import generate_model_graph - from c2cwsgiutils_app import models diff --git a/acceptance_tests/tests/tests/conftest.py b/acceptance_tests/tests/tests/conftest.py index 58f1da2b3..ccb5ebdd9 100644 --- a/acceptance_tests/tests/tests/conftest.py +++ b/acceptance_tests/tests/tests/conftest.py @@ -3,6 +3,7 @@ import psycopg2 import pytest + from c2cwsgiutils.acceptance import utils from c2cwsgiutils.acceptance.composition import Composition from c2cwsgiutils.acceptance.connection import Connection diff --git a/c2cwsgiutils/acceptance/composition.py b/c2cwsgiutils/acceptance/composition.py index 0f1e337b2..9eaf9964c 100644 --- a/c2cwsgiutils/acceptance/composition.py +++ b/c2cwsgiutils/acceptance/composition.py @@ -7,9 +7,10 @@ from typing import Any, Callable, Dict, List, Mapping, Optional, cast import netifaces -from c2cwsgiutils.acceptance import utils from pyramid.request import Request +from c2cwsgiutils.acceptance import utils + LOG = logging.getLogger(__name__) logging.basicConfig( level=logging.DEBUG, diff --git a/c2cwsgiutils/acceptance/print.py b/c2cwsgiutils/acceptance/print.py index 9d76362e0..36f38b202 100644 --- a/c2cwsgiutils/acceptance/print.py +++ b/c2cwsgiutils/acceptance/print.py @@ -4,6 +4,7 @@ from typing import Any, Dict, Optional import requests + from c2cwsgiutils.acceptance import connection, utils LOG = logging.getLogger(__name__) diff --git a/c2cwsgiutils/auth.py b/c2cwsgiutils/auth.py index c896c3598..281f66a0c 100644 --- a/c2cwsgiutils/auth.py +++ b/c2cwsgiutils/auth.py @@ -5,10 +5,11 @@ import jwt import pyramid.request -from c2cwsgiutils.config_utils import config_bool, env_or_config, env_or_settings from pyramid.httpexceptions import HTTPForbidden from requests_oauthlib import OAuth2Session +from c2cwsgiutils.config_utils import config_bool, env_or_config, env_or_settings + COOKIE_AGE = 7 * 24 * 3600 SECRET_PROP = "c2c.secret" # nosec # noqa SECRET_ENV = "C2C_SECRET" # nosec # noqa diff --git a/c2cwsgiutils/broadcast/__init__.py b/c2cwsgiutils/broadcast/__init__.py index 9e1125041..3b95525c8 100644 --- a/c2cwsgiutils/broadcast/__init__.py +++ b/c2cwsgiutils/broadcast/__init__.py @@ -5,6 +5,7 @@ from typing import Any, Callable, Dict, List, Optional, TypeVar import pyramid.config + from c2cwsgiutils import config_utils, redis_utils from c2cwsgiutils.broadcast import interface, local, redis diff --git a/c2cwsgiutils/broadcast/redis.py b/c2cwsgiutils/broadcast/redis.py index 2a185fe96..f0e319aa5 100644 --- a/c2cwsgiutils/broadcast/redis.py +++ b/c2cwsgiutils/broadcast/redis.py @@ -7,6 +7,7 @@ from typing import Any, Callable, List, Mapping, Optional import redis + from c2cwsgiutils.broadcast import interface, local, utils LOG = logging.getLogger(__name__) diff --git a/c2cwsgiutils/db_maintenance_view.py b/c2cwsgiutils/db_maintenance_view.py index 752db2a4d..09de0b41b 100644 --- a/c2cwsgiutils/db_maintenance_view.py +++ b/c2cwsgiutils/db_maintenance_view.py @@ -3,6 +3,7 @@ from typing import Any, Mapping, Optional, cast import pyramid.request + from c2cwsgiutils import auth, broadcast, config_utils, db, redis_utils LOG = logging.getLogger(__name__) diff --git a/c2cwsgiutils/debug/__init__.py b/c2cwsgiutils/debug/__init__.py index 5167d3a7e..0ab27b77d 100644 --- a/c2cwsgiutils/debug/__init__.py +++ b/c2cwsgiutils/debug/__init__.py @@ -2,6 +2,7 @@ from typing import Optional import pyramid.config + from c2cwsgiutils import auth, config_utils from c2cwsgiutils.debug import utils diff --git a/c2cwsgiutils/debug/_listeners.py b/c2cwsgiutils/debug/_listeners.py index 00f33fd5e..2a8773e68 100644 --- a/c2cwsgiutils/debug/_listeners.py +++ b/c2cwsgiutils/debug/_listeners.py @@ -6,6 +6,7 @@ from typing import Any, Dict, List, Mapping, Optional, Tuple, cast import objgraph + from c2cwsgiutils import broadcast from c2cwsgiutils.debug.utils import get_size diff --git a/c2cwsgiutils/debug/_views.py b/c2cwsgiutils/debug/_views.py index c05b4bf36..e5bc2a242 100644 --- a/c2cwsgiutils/debug/_views.py +++ b/c2cwsgiutils/debug/_views.py @@ -10,9 +10,10 @@ import pyramid.config import pyramid.request import pyramid.response +from pyramid.httpexceptions import HTTPException, exception_response + from c2cwsgiutils import auth, broadcast, config_utils from c2cwsgiutils.debug.utils import dump_memory_maps, get_size -from pyramid.httpexceptions import HTTPException, exception_response LOG = logging.getLogger(__name__) SPACE_RE = re.compile(r" +") diff --git a/c2cwsgiutils/errors.py b/c2cwsgiutils/errors.py index 40916c5f6..f42144f50 100644 --- a/c2cwsgiutils/errors.py +++ b/c2cwsgiutils/errors.py @@ -7,11 +7,12 @@ import pyramid.request import sqlalchemy.exc -from c2cwsgiutils import auth, config_utils from cornice import cors from pyramid.httpexceptions import HTTPError, HTTPException, HTTPRedirection, HTTPSuccessful from webob.request import DisconnectionError +from c2cwsgiutils import auth, config_utils + DEVELOPMENT = os.environ.get("DEVELOPMENT", "0") != "0" DEPRECATED_CONFIG_KEY = "c2c.error_details_secret" DEPRECATED_ENV_KEY = "ERROR_DETAILS_SECRET" diff --git a/c2cwsgiutils/health_check.py b/c2cwsgiutils/health_check.py index 7e48e1d7b..782ee9ea7 100644 --- a/c2cwsgiutils/health_check.py +++ b/c2cwsgiutils/health_check.py @@ -30,16 +30,17 @@ cast, ) -import c2cwsgiutils.db import pyramid.config import pyramid.request import requests import sqlalchemy.engine import sqlalchemy.orm import sqlalchemy.sql -from c2cwsgiutils import auth, broadcast, config_utils, redis_utils, stats, version from pyramid.httpexceptions import HTTPNotFound +import c2cwsgiutils.db +from c2cwsgiutils import auth, broadcast, config_utils, redis_utils, stats, version + if TYPE_CHECKING: scoped_session = sqlalchemy.orm.scoped_session[sqlalchemy.orm.Session] else: diff --git a/c2cwsgiutils/index.py b/c2cwsgiutils/index.py index 9b459c290..cef6b9711 100644 --- a/c2cwsgiutils/index.py +++ b/c2cwsgiutils/index.py @@ -7,6 +7,9 @@ import pyramid.config import pyramid.request import pyramid.response +from pyramid.httpexceptions import HTTPFound +from requests_oauthlib import OAuth2Session + from c2cwsgiutils import config_utils from c2cwsgiutils.auth import ( GITHUB_AUTH_COOKIE_ENV, @@ -38,8 +41,6 @@ is_auth_user, ) from c2cwsgiutils.config_utils import env_or_settings -from pyramid.httpexceptions import HTTPFound -from requests_oauthlib import OAuth2Session LOG = logging.getLogger(__name__) diff --git a/c2cwsgiutils/loader.py b/c2cwsgiutils/loader.py index 76d0285d1..2f02fadab 100644 --- a/c2cwsgiutils/loader.py +++ b/c2cwsgiutils/loader.py @@ -1,9 +1,10 @@ import logging from typing import Dict, Optional, cast -from c2cwsgiutils import get_config_defaults from plaster_pastedeploy import Loader as BaseLoader +from c2cwsgiutils import get_config_defaults + LOG = logging.getLogger(__name__) diff --git a/c2cwsgiutils/logging_view.py b/c2cwsgiutils/logging_view.py index 749d9b806..db5d83057 100644 --- a/c2cwsgiutils/logging_view.py +++ b/c2cwsgiutils/logging_view.py @@ -3,6 +3,7 @@ from typing import Any, Generator, Mapping, Tuple import pyramid.request + from c2cwsgiutils import auth, broadcast, config_utils, redis_utils LOG = logging.getLogger(__name__) diff --git a/c2cwsgiutils/metrics.py b/c2cwsgiutils/metrics.py index ae2caf146..033a0869a 100644 --- a/c2cwsgiutils/metrics.py +++ b/c2cwsgiutils/metrics.py @@ -8,6 +8,7 @@ import pyramid.request import pyramid.response + from c2cwsgiutils.debug.utils import dump_memory_maps diff --git a/c2cwsgiutils/pretty_json.py b/c2cwsgiutils/pretty_json.py index bbb3d6d44..8e56a60d9 100644 --- a/c2cwsgiutils/pretty_json.py +++ b/c2cwsgiutils/pretty_json.py @@ -3,10 +3,11 @@ import pyramid.config import ujson -from c2cwsgiutils.config_utils import config_bool, env_or_config from cornice.renderer import CorniceRenderer from pyramid.renderers import JSON +from c2cwsgiutils.config_utils import config_bool, env_or_config + class _FastDumps: """Dump the json fast using ujson.""" diff --git a/c2cwsgiutils/pyramid.py b/c2cwsgiutils/pyramid.py index 280a1bb79..390201285 100644 --- a/c2cwsgiutils/pyramid.py +++ b/c2cwsgiutils/pyramid.py @@ -3,6 +3,7 @@ import cornice import pyramid.config import pyramid_tm + from c2cwsgiutils import ( broadcast, coverage_setup, diff --git a/c2cwsgiutils/redis_stats.py b/c2cwsgiutils/redis_stats.py index 1d99f4154..75dfd92db 100644 --- a/c2cwsgiutils/redis_stats.py +++ b/c2cwsgiutils/redis_stats.py @@ -3,6 +3,7 @@ from typing import Any, Callable, Dict, Optional import pyramid.config + from c2cwsgiutils import config_utils, stats LOG = logging.getLogger(__name__) diff --git a/c2cwsgiutils/redis_utils.py b/c2cwsgiutils/redis_utils.py index 3a9f4056a..0f2dbb6ee 100644 --- a/c2cwsgiutils/redis_utils.py +++ b/c2cwsgiutils/redis_utils.py @@ -3,12 +3,13 @@ import time from typing import Any, Mapping, Optional, Tuple -import c2cwsgiutils.config_utils import redis.client import redis.exceptions import redis.sentinel import yaml +import c2cwsgiutils.config_utils + LOG = logging.getLogger(__name__) REDIS_URL_KEY = "C2C_REDIS_URL" diff --git a/c2cwsgiutils/request_tracking/__init__.py b/c2cwsgiutils/request_tracking/__init__.py index ac2e478da..2b35c6e94 100644 --- a/c2cwsgiutils/request_tracking/__init__.py +++ b/c2cwsgiutils/request_tracking/__init__.py @@ -12,9 +12,10 @@ import pyramid.request import requests.adapters import requests.models -from c2cwsgiutils import config_utils, stats from pyramid.threadlocal import get_current_request +from c2cwsgiutils import config_utils, stats + ID_HEADERS: List[str] = [] _HTTPAdapter_send = requests.adapters.HTTPAdapter.send LOG = logging.getLogger(__name__) diff --git a/c2cwsgiutils/scripts/check_es.py b/c2cwsgiutils/scripts/check_es.py index bb4e2ee26..03fa938df 100755 --- a/c2cwsgiutils/scripts/check_es.py +++ b/c2cwsgiutils/scripts/check_es.py @@ -9,11 +9,12 @@ import warnings from typing import Any, List, Optional -import c2cwsgiutils.setup_process import requests.exceptions -from c2cwsgiutils import stats from dateutil import parser as dp +import c2cwsgiutils.setup_process +from c2cwsgiutils import stats + def _ensure_slash(txt: Optional[str]) -> Optional[str]: if txt is None: diff --git a/c2cwsgiutils/scripts/stats_db.py b/c2cwsgiutils/scripts/stats_db.py index 1d9282ad5..89f12f531 100755 --- a/c2cwsgiutils/scripts/stats_db.py +++ b/c2cwsgiutils/scripts/stats_db.py @@ -7,14 +7,15 @@ import time from typing import TYPE_CHECKING, Dict, List, Optional -import c2cwsgiutils.setup_process import sqlalchemy import sqlalchemy.exc import sqlalchemy.orm import transaction +from zope.sqlalchemy import register + +import c2cwsgiutils.setup_process from c2cwsgiutils import stats from c2cwsgiutils.prometheus import PushgatewayGroupPublisher -from zope.sqlalchemy import register if TYPE_CHECKING: scoped_session = sqlalchemy.orm.scoped_session[sqlalchemy.orm.Session] diff --git a/c2cwsgiutils/sentry.py b/c2cwsgiutils/sentry.py index ccad5f3ca..6d0e47f36 100644 --- a/c2cwsgiutils/sentry.py +++ b/c2cwsgiutils/sentry.py @@ -6,13 +6,14 @@ import pyramid.config import sentry_sdk -from c2cwsgiutils import config_utils from sentry_sdk.integrations.logging import LoggingIntegration, ignore_logger from sentry_sdk.integrations.pyramid import PyramidIntegration from sentry_sdk.integrations.redis import RedisIntegration from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware +from c2cwsgiutils import config_utils + LOG = logging.getLogger(__name__) _client_setup = False diff --git a/c2cwsgiutils/setup_process.py b/c2cwsgiutils/setup_process.py index cbc8f03d0..132c11318 100644 --- a/c2cwsgiutils/setup_process.py +++ b/c2cwsgiutils/setup_process.py @@ -13,10 +13,11 @@ import pyramid.registry import pyramid.request import pyramid.router -from c2cwsgiutils import broadcast, coverage_setup, redis_stats, sentry, sql_profiler, stats from pyramid.paster import bootstrap from pyramid.scripts.common import get_config_loader, parse_vars +from c2cwsgiutils import broadcast, coverage_setup, redis_stats, sentry, sql_profiler, stats + def fill_arguments( parser: argparse.ArgumentParser, diff --git a/c2cwsgiutils/sql_profiler/__init__.py b/c2cwsgiutils/sql_profiler/__init__.py index da61b4321..e201ead35 100644 --- a/c2cwsgiutils/sql_profiler/__init__.py +++ b/c2cwsgiutils/sql_profiler/__init__.py @@ -7,6 +7,7 @@ import warnings import pyramid.request + from c2cwsgiutils import auth ENV_KEY = "C2C_SQL_PROFILER_ENABLED" diff --git a/c2cwsgiutils/sql_profiler/_impl.py b/c2cwsgiutils/sql_profiler/_impl.py index a2c785f5c..4338bbd47 100644 --- a/c2cwsgiutils/sql_profiler/_impl.py +++ b/c2cwsgiutils/sql_profiler/_impl.py @@ -11,6 +11,7 @@ import pyramid.request import sqlalchemy.engine import sqlalchemy.event + from c2cwsgiutils import auth, broadcast, config_utils LOG = logging.getLogger(__name__) diff --git a/c2cwsgiutils/sqlalchemylogger/handlers.py b/c2cwsgiutils/sqlalchemylogger/handlers.py index b9a0f219d..d8038cf08 100644 --- a/c2cwsgiutils/sqlalchemylogger/handlers.py +++ b/c2cwsgiutils/sqlalchemylogger/handlers.py @@ -6,13 +6,14 @@ from typing import Any, Dict, List import sqlalchemy -from c2cwsgiutils.sqlalchemylogger._filters import ContainsExpression, DoesNotContainExpression -from c2cwsgiutils.sqlalchemylogger._models import Base, create_log_class from sqlalchemy import create_engine from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.orm import sessionmaker from sqlalchemy_utils import create_database, database_exists +from c2cwsgiutils.sqlalchemylogger._filters import ContainsExpression, DoesNotContainExpression +from c2cwsgiutils.sqlalchemylogger._models import Base, create_log_class + LOG = logging.getLogger(__name__) diff --git a/c2cwsgiutils/stats.py b/c2cwsgiutils/stats.py index 64e2ce22b..04d445834 100644 --- a/c2cwsgiutils/stats.py +++ b/c2cwsgiutils/stats.py @@ -11,6 +11,7 @@ from typing import Any, Callable, Dict, Generator, List, Mapping, MutableMapping, Optional, Sequence, Tuple import pyramid.request + from c2cwsgiutils import config_utils LOG = logging.getLogger(__name__) diff --git a/c2cwsgiutils/stats_pyramid/__init__.py b/c2cwsgiutils/stats_pyramid/__init__.py index 1860269de..d9884a29a 100644 --- a/c2cwsgiutils/stats_pyramid/__init__.py +++ b/c2cwsgiutils/stats_pyramid/__init__.py @@ -3,6 +3,7 @@ import pyramid.config import pyramid.request + from c2cwsgiutils import stats diff --git a/c2cwsgiutils/stats_pyramid/_db_spy.py b/c2cwsgiutils/stats_pyramid/_db_spy.py index 6f0a7e585..a401a1f2f 100644 --- a/c2cwsgiutils/stats_pyramid/_db_spy.py +++ b/c2cwsgiutils/stats_pyramid/_db_spy.py @@ -3,10 +3,11 @@ from typing import Any, Callable, Dict, Optional import sqlalchemy.event -from c2cwsgiutils import stats from sqlalchemy.engine import Connection, Engine from sqlalchemy.orm import Session +from c2cwsgiutils import stats + LOG = logging.getLogger(__name__) diff --git a/c2cwsgiutils/stats_pyramid/_pyramid_spy.py b/c2cwsgiutils/stats_pyramid/_pyramid_spy.py index 40fd79b8c..7aad286eb 100644 --- a/c2cwsgiutils/stats_pyramid/_pyramid_spy.py +++ b/c2cwsgiutils/stats_pyramid/_pyramid_spy.py @@ -3,9 +3,10 @@ import pyramid.config import pyramid.events import pyramid.request -from c2cwsgiutils import stats from pyramid.httpexceptions import HTTPException +from c2cwsgiutils import stats + def _add_server_metric( request: pyramid.request.Request, diff --git a/c2cwsgiutils/stats_pyramid/_views.py b/c2cwsgiutils/stats_pyramid/_views.py index d13250d80..5ac717979 100644 --- a/c2cwsgiutils/stats_pyramid/_views.py +++ b/c2cwsgiutils/stats_pyramid/_views.py @@ -1,6 +1,7 @@ from typing import cast import pyramid.config + from c2cwsgiutils import config_utils, stats diff --git a/c2cwsgiutils/version.py b/c2cwsgiutils/version.py index 9ff2e4e9e..5570cf595 100644 --- a/c2cwsgiutils/version.py +++ b/c2cwsgiutils/version.py @@ -5,6 +5,7 @@ from typing import Dict, Optional, cast import pyramid.config + from c2cwsgiutils import config_utils, stats VERSIONS_PATH = "/app/versions.json" diff --git a/tests/test_acceptance_image.py b/tests/test_acceptance_image.py index 64222d2df..4dfc23cd9 100644 --- a/tests/test_acceptance_image.py +++ b/tests/test_acceptance_image.py @@ -1,6 +1,7 @@ import os import pytest + from c2cwsgiutils.acceptance.image import check_image_file diff --git a/tests/test_broadcast.py b/tests/test_broadcast.py index 83db6a779..05d956353 100644 --- a/tests/test_broadcast.py +++ b/tests/test_broadcast.py @@ -1,4 +1,5 @@ import pytest + from c2cwsgiutils import broadcast from c2cwsgiutils.broadcast import local diff --git a/tests/test_loader.py b/tests/test_loader.py index c36687e83..adc966021 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -1,8 +1,9 @@ from unittest.mock import mock_open, patch -from c2cwsgiutils import get_config_defaults from pyramid.scripts.common import get_config_loader +from c2cwsgiutils import get_config_defaults + @patch( "paste.deploy.loadwsgi.open", diff --git a/tests/test_prometheus.py b/tests/test_prometheus.py index 376b0fef1..0f48a93cf 100644 --- a/tests/test_prometheus.py +++ b/tests/test_prometheus.py @@ -1,4 +1,5 @@ import pytest + from c2cwsgiutils.prometheus import PushgatewayGroupPublisher diff --git a/tests/test_sqlalchemylogger.py b/tests/test_sqlalchemylogger.py index 81ff36a75..902fe0c94 100644 --- a/tests/test_sqlalchemylogger.py +++ b/tests/test_sqlalchemylogger.py @@ -4,9 +4,10 @@ import time import unittest -from c2cwsgiutils.sqlalchemylogger.handlers import SQLAlchemyHandler from sqlalchemy import text +from c2cwsgiutils.sqlalchemylogger.handlers import SQLAlchemyHandler + class SqlAlchemyLoggerTests(unittest.TestCase): dummy_db_name = "dummy.db"