From f977f9faeefce4ca317fa8b3facbb5be13417594 Mon Sep 17 00:00:00 2001 From: Vadim Stepanov Date: Wed, 26 Jul 2023 14:45:44 +0100 Subject: [PATCH] Minor formatting changes (#2641) # What this PR does - Updates `black` and `flake8` to latest - Removes `F541` from flake8 ignore (`F541 f-string is missing placeholders`) - Enables ["float to top" option](https://pycqa.github.io/isort/docs/configuration/options.html#float-to-top) for `isort` --- .pre-commit-config.yaml | 14 ++++++-------- .../escalation_snapshot_mixin.py | 2 +- .../apps/alerts/models/alert_group_log_record.py | 2 +- .../apps/alerts/tasks/check_escalation_finished.py | 2 +- engine/apps/alerts/tasks/notify_user.py | 6 +++--- .../resolve_alert_group_by_source_if_needed.py | 1 - engine/apps/api/serializers/channel_filter.py | 4 ++-- engine/apps/api/tests/test_alert_group.py | 6 +++--- engine/apps/api/tests/test_channel_filter.py | 6 +++--- engine/apps/api/tests/test_team.py | 2 +- engine/apps/api/views/user.py | 4 ++-- engine/apps/email/inbound.py | 4 ++-- engine/apps/email/tasks.py | 2 +- engine/apps/grafana_plugin/apps.py | 2 +- .../grafana_plugin/tests/test_gcom_api_client.py | 2 +- .../grafana_plugin/views/self_hosted_install.py | 2 +- engine/apps/integrations/tasks.py | 2 +- engine/apps/metrics_exporter/tasks.py | 1 - engine/apps/mobile_app/tasks.py | 2 +- .../tests/test_your_going_oncall_notification.py | 2 +- .../oss_installation/models/cloud_connector.py | 6 +++--- engine/apps/phone_notifications/phone_backend.py | 4 ++-- engine/apps/public_api/serializers/routes.py | 4 ++-- engine/apps/public_api/tests/test_incidents.py | 10 +++++----- engine/apps/schedules/models/shift_swap_request.py | 1 - engine/apps/slack/scenarios/manual_incident.py | 2 +- engine/apps/slack/scenarios/paging.py | 2 +- engine/apps/slack/views.py | 2 +- engine/apps/twilioapp/phone_provider.py | 4 ++-- engine/apps/zvonok/models/phone_call.py | 1 - engine/apps/zvonok/phone_provider.py | 8 ++++---- .../common/insight_log/maintenance_insight_log.py | 2 +- engine/engine/celery.py | 2 +- engine/pyproject.toml | 7 +++---- engine/settings/prod_without_db.py | 3 ++- engine/tox.ini | 2 +- 36 files changed, 61 insertions(+), 67 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6706b246..07d10bf6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: args: [--settings-file=dev/scripts/.isort.cfg, --filter-files] - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.7.0 hooks: - id: black files: ^engine @@ -29,7 +29,7 @@ repos: files: ^dev/scripts - repo: https://github.com/pycqa/flake8 - rev: 3.9.2 + rev: 6.0.0 hooks: - id: flake8 files: ^engine @@ -40,22 +40,20 @@ repos: name: flake8 - pd-migrator files: ^tools/pagerduty-migrator # Make sure config is compatible with black - # https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length + # https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8 args: [ - --max-line-length=88, - "--select=C,E,F,W,B,B950", + "--max-line-length=88", "--extend-ignore=E203,E501", ] - id: flake8 name: flake8 - dev/scripts files: ^dev/scripts # Make sure config is compatible with black - # https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length + # https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8 args: [ - --max-line-length=88, - "--select=C,E,F,W,B,B950", + "--max-line-length=88", "--extend-ignore=E203,E501", ] diff --git a/engine/apps/alerts/escalation_snapshot/escalation_snapshot_mixin.py b/engine/apps/alerts/escalation_snapshot/escalation_snapshot_mixin.py index 7af4e8c6..e846a83d 100644 --- a/engine/apps/alerts/escalation_snapshot/escalation_snapshot_mixin.py +++ b/engine/apps/alerts/escalation_snapshot/escalation_snapshot_mixin.py @@ -247,7 +247,7 @@ class EscalationSnapshotMixin: ) task_id = celery_uuid() - AlertGroup.objects.filter(pk=self.pk,).update( + AlertGroup.objects.filter(pk=self.pk).update( active_escalation_id=task_id, is_escalation_finished=False, raw_escalation_snapshot=raw_escalation_snapshot, diff --git a/engine/apps/alerts/models/alert_group_log_record.py b/engine/apps/alerts/models/alert_group_log_record.py index 0d28b23d..e62d19cf 100644 --- a/engine/apps/alerts/models/alert_group_log_record.py +++ b/engine/apps/alerts/models/alert_group_log_record.py @@ -271,7 +271,7 @@ class AlertGroupLogRecord(models.Model): if escalation_chain is not None: result += f' with escalation chain "{escalation_chain.name}"' else: - result += f" with no escalation chain, skipping escalation" + result += " with no escalation chain, skipping escalation" else: result += "alert group assigned to deleted route, skipping escalation" elif self.type == AlertGroupLogRecord.TYPE_ACK: diff --git a/engine/apps/alerts/tasks/check_escalation_finished.py b/engine/apps/alerts/tasks/check_escalation_finished.py index 9dfbe6e1..7726f95f 100644 --- a/engine/apps/alerts/tasks/check_escalation_finished.py +++ b/engine/apps/alerts/tasks/check_escalation_finished.py @@ -25,7 +25,7 @@ def send_alert_group_escalation_auditor_task_heartbeat() -> None: requests.get(heartbeat_url).raise_for_status() task_logger.info(f"Heartbeat successfully sent to {heartbeat_url}") else: - task_logger.info(f"Skipping sending heartbeat as no heartbeat URL is configured") + task_logger.info("Skipping sending heartbeat as no heartbeat URL is configured") def audit_alert_group_escalation(alert_group: "AlertGroup") -> None: diff --git a/engine/apps/alerts/tasks/notify_user.py b/engine/apps/alerts/tasks/notify_user.py index 113edf57..21cfd762 100644 --- a/engine/apps/alerts/tasks/notify_user.py +++ b/engine/apps/alerts/tasks/notify_user.py @@ -55,7 +55,7 @@ def notify_user_task( UserNotificationPolicyLogRecord( author=user, type=UserNotificationPolicyLogRecord.TYPE_PERSONAL_NOTIFICATION_FAILED, - reason=f"notification is not allowed for user", + reason="notification is not allowed for user", alert_group=alert_group, notification_error_code=UserNotificationPolicyLogRecord.ERROR_NOTIFICATION_FORBIDDEN, ).save() @@ -253,7 +253,7 @@ def perform_notification(log_record_pk): UserNotificationPolicyLogRecord( author=user, type=UserNotificationPolicyLogRecord.TYPE_PERSONAL_NOTIFICATION_FAILED, - reason=f"notification is not allowed for user", + reason="notification is not allowed for user", alert_group=alert_group, notification_error_code=UserNotificationPolicyLogRecord.ERROR_NOTIFICATION_FORBIDDEN, ).save() @@ -347,7 +347,7 @@ def perform_notification(log_record_pk): backend = None if backend is None: - task_logger.debug(f"notify_user failed because messaging backend is not available") + task_logger.debug("notify_user failed because messaging backend is not available") UserNotificationPolicyLogRecord( author=user, type=UserNotificationPolicyLogRecord.TYPE_PERSONAL_NOTIFICATION_FAILED, diff --git a/engine/apps/alerts/tasks/resolve_alert_group_by_source_if_needed.py b/engine/apps/alerts/tasks/resolve_alert_group_by_source_if_needed.py index 701cfe02..680bd83c 100644 --- a/engine/apps/alerts/tasks/resolve_alert_group_by_source_if_needed.py +++ b/engine/apps/alerts/tasks/resolve_alert_group_by_source_if_needed.py @@ -20,7 +20,6 @@ def resolve_alert_group_by_source_if_needed(alert_group_pk): alert_group.active_resolve_calculation_id ) else: - is_more_than_max_alerts_in_group = alert_group.alerts_count_gt( AlertGroupForAlertManager.MAX_ALERTS_IN_GROUP_FOR_AUTO_RESOLVE ) diff --git a/engine/apps/api/serializers/channel_filter.py b/engine/apps/api/serializers/channel_filter.py index 388bdcb8..16f257a2 100644 --- a/engine/apps/api/serializers/channel_filter.py +++ b/engine/apps/api/serializers/channel_filter.py @@ -62,13 +62,13 @@ class ChannelFilterSerializer(EagerLoadingMixin, serializers.ModelSerializer): try: valid_jinja_template_for_serializer_method_field({"route_template": filtering_term}) except JinjaTemplateError: - raise serializers.ValidationError([f"Jinja template is incorrect"]) + raise serializers.ValidationError(["Jinja template is incorrect"]) elif filtering_term_type == ChannelFilter.FILTERING_TERM_TYPE_REGEX or filtering_term_type is None: if filtering_term is not None: if not is_regex_valid(filtering_term): raise serializers.ValidationError(["Regular expression is incorrect"]) else: - raise serializers.ValidationError([f"Expression type is incorrect"]) + raise serializers.ValidationError(["Expression type is incorrect"]) return data def get_slack_channel(self, obj): diff --git a/engine/apps/api/tests/test_alert_group.py b/engine/apps/api/tests/test_alert_group.py index 0bd09c83..f83c7822 100644 --- a/engine/apps/api/tests/test_alert_group.py +++ b/engine/apps/api/tests/test_alert_group.py @@ -77,7 +77,7 @@ def test_get_filter_started_at(alert_group_internal_api_setup, make_user_auth_he url = reverse("api-internal:alertgroup-list") response = client.get( - url + f"?started_at=1970-01-01T00:00:00/2099-01-01T23:59:59", + url + "?started_at=1970-01-01T00:00:00/2099-01-01T23:59:59", format="json", **make_user_auth_headers(user, token), ) @@ -653,7 +653,7 @@ def test_get_filter_mine( url = reverse("api-internal:alertgroup-list") first_response = client.get( - url + f"?mine=true", + url + "?mine=true", format="json", **make_user_auth_headers(first_user, token), ) @@ -661,7 +661,7 @@ def test_get_filter_mine( assert len(first_response.data["results"]) == 1 second_response = client.get( - url + f"?mine=false", + url + "?mine=false", format="json", **make_user_auth_headers(first_user, token), ) diff --git a/engine/apps/api/tests/test_channel_filter.py b/engine/apps/api/tests/test_channel_filter.py index f979a426..5c8167f4 100644 --- a/engine/apps/api/tests/test_channel_filter.py +++ b/engine/apps/api/tests/test_channel_filter.py @@ -269,7 +269,7 @@ def test_move_to_position( url = reverse( "api-internal:channel_filter-move-to-position", kwargs={"pk": first_channel_filter.public_primary_key} ) - url += f"?position=1" + url += "?position=1" response = client.put(url, **make_user_auth_headers(user, token)) assert response.status_code == status.HTTP_200_OK @@ -297,7 +297,7 @@ def test_move_to_position_invalid_index( url = reverse( "api-internal:channel_filter-move-to-position", kwargs={"pk": first_channel_filter.public_primary_key} ) - url += f"?position=2" + url += "?position=2" response = client.put(url, **make_user_auth_headers(user, token)) assert response.status_code == status.HTTP_400_BAD_REQUEST @@ -320,7 +320,7 @@ def test_move_to_position_cant_move_default( url = reverse( "api-internal:channel_filter-move-to-position", kwargs={"pk": default_channel_filter.public_primary_key} ) - url += f"?position=1" + url += "?position=1" response = client.put(url, **make_user_auth_headers(user, token)) assert response.status_code == status.HTTP_400_BAD_REQUEST diff --git a/engine/apps/api/tests/test_team.py b/engine/apps/api/tests/test_team.py index 21614068..91c7d5fe 100644 --- a/engine/apps/api/tests/test_team.py +++ b/engine/apps/api/tests/test_team.py @@ -255,7 +255,7 @@ def test_team_permissions_not_in_team( assert response.json() == {"error_code": "wrong_team"} # Editor cannot retrieve other user information - url = reverse(f"api-internal:user-detail", kwargs={"pk": another_user.public_primary_key}) + url = reverse("api-internal:user-detail", kwargs={"pk": another_user.public_primary_key}) response = client.get(url, **make_user_auth_headers(user, token)) assert response.status_code == status.HTTP_403_FORBIDDEN diff --git a/engine/apps/api/views/user.py b/engine/apps/api/views/user.py index 23c252ab..9c524ec8 100644 --- a/engine/apps/api/views/user.py +++ b/engine/apps/api/views/user.py @@ -331,7 +331,7 @@ class UserView( logger.info("get_verification_code: validating reCAPTCHA code") valid = check_recaptcha_internal_api(request, "mobile_verification_code") if not valid: - logger.warning(f"get_verification_code: invalid reCAPTCHA validation") + logger.warning("get_verification_code: invalid reCAPTCHA validation") return Response("failed reCAPTCHA check", status=status.HTTP_400_BAD_REQUEST) logger.info('get_verification_code: pass reCAPTCHA validation"') @@ -358,7 +358,7 @@ class UserView( logger.info("get_verification_code_via_call: validating reCAPTCHA code") valid = check_recaptcha_internal_api(request, "mobile_verification_code") if not valid: - logger.warning(f"get_verification_code_via_call: invalid reCAPTCHA validation") + logger.warning("get_verification_code_via_call: invalid reCAPTCHA validation") return Response("failed reCAPTCHA check", status=status.HTTP_400_BAD_REQUEST) logger.info('get_verification_code_via_call: pass reCAPTCHA validation"') diff --git a/engine/apps/email/inbound.py b/engine/apps/email/inbound.py index 47a99864..6a4a91bf 100644 --- a/engine/apps/email/inbound.py +++ b/engine/apps/email/inbound.py @@ -87,7 +87,7 @@ class InboundEmailWebhookView(AlertChannelDefiningMixin, APIView): if domain == live_settings.INBOUND_EMAIL_DOMAIN: return token else: - logger.info(f"get_integration_token_from_request: message.envelope_recipient is not present") + logger.info("get_integration_token_from_request: message.envelope_recipient is not present") """ TODO: handle case when envelope_recipient is not provided. Now we can't just compare to/cc domains one by one with INBOUND_EMAIL_DOMAIN @@ -123,7 +123,7 @@ class InboundEmailWebhookView(AlertChannelDefiningMixin, APIView): """ # TODO: These settings should be checked before app start. if not live_settings.INBOUND_EMAIL_ESP: - logger.error(f"InboundEmailWebhookView: INBOUND_EMAIL_ESP env variable must be set.") + logger.error("InboundEmailWebhookView: INBOUND_EMAIL_ESP env variable must be set.") return HttpResponse( status=status.HTTP_500_INTERNAL_SERVER_ERROR, ) diff --git a/engine/apps/email/tasks.py b/engine/apps/email/tasks.py index 03f3d591..8d67577b 100644 --- a/engine/apps/email/tasks.py +++ b/engine/apps/email/tasks.py @@ -60,7 +60,7 @@ def notify_user_async(user_pk, alert_group_pk, notification_policy_pk): notification_step=notification_policy.step, notification_channel=notification_policy.notify_by, ) - logger.error(f"Error while sending email: empty EMAIL_HOST env variable") + logger.error("Error while sending email: empty EMAIL_HOST env variable") return emails_left = user.organization.emails_left(user) diff --git a/engine/apps/grafana_plugin/apps.py b/engine/apps/grafana_plugin/apps.py index f427cdd3..aa2926b0 100644 --- a/engine/apps/grafana_plugin/apps.py +++ b/engine/apps/grafana_plugin/apps.py @@ -35,7 +35,7 @@ class GrafanaPluginConfig(AppConfig): # and the GRAFANA_API_URL env var is not specified, exit the application if has_existing_org is False and settings.SELF_HOSTED_SETTINGS["GRAFANA_API_URL"] is None: logger.error( - f"For OSS installations, GRAFANA_API_URL is a required environment variable. Please set it and restart the application." + "For OSS installations, GRAFANA_API_URL is a required environment variable. Please set it and restart the application." ) sys.exit() except OperationalError: diff --git a/engine/apps/grafana_plugin/tests/test_gcom_api_client.py b/engine/apps/grafana_plugin/tests/test_gcom_api_client.py index 249fbe46..3dfc3605 100644 --- a/engine/apps/grafana_plugin/tests/test_gcom_api_client.py +++ b/engine/apps/grafana_plugin/tests/test_gcom_api_client.py @@ -61,7 +61,7 @@ class TestIsRbacEnabledForStack: ({"config": {"feature_toggles": {"enable": f"foo,bar,{TEST_FEATURE_TOGGLE}baz"}}}, False), ({"config": {"feature_toggles": {"enable": f"foo,bar,{TEST_FEATURE_TOGGLE},baz"}}}, True), ({"config": {"feature_toggles": {"enable": f"foo bar {TEST_FEATURE_TOGGLE} baz"}}}, True), - ({"config": {"feature_toggles": {"enable": f"foo bar baz", TEST_FEATURE_TOGGLE: "true"}}}, True), + ({"config": {"feature_toggles": {"enable": "foo bar baz", TEST_FEATURE_TOGGLE: "true"}}}, True), ({"config": {"feature_toggles": {TEST_FEATURE_TOGGLE: "true"}}}, True), # this case will probably never happen, but lets account for it anyways ( diff --git a/engine/apps/grafana_plugin/views/self_hosted_install.py b/engine/apps/grafana_plugin/views/self_hosted_install.py index 6784f700..31486487 100644 --- a/engine/apps/grafana_plugin/views/self_hosted_install.py +++ b/engine/apps/grafana_plugin/views/self_hosted_install.py @@ -26,7 +26,7 @@ class SelfHostedInstallView(GrafanaHeadersMixin, APIView): provisioning_info = {"error": None} if settings.LICENSE != settings.OPEN_SOURCE_LICENSE_NAME: - provisioning_info["error"] = f"License type not authorized" + provisioning_info["error"] = "License type not authorized" return Response(status=status.HTTP_403_FORBIDDEN) grafana_api_client = GrafanaAPIClient(api_url=grafana_url, api_token=grafana_api_token) diff --git a/engine/apps/integrations/tasks.py b/engine/apps/integrations/tasks.py index bec0f068..856818c4 100644 --- a/engine/apps/integrations/tasks.py +++ b/engine/apps/integrations/tasks.py @@ -31,7 +31,7 @@ def create_alertmanager_alerts(alert_receive_channel_pk, alert, is_demo=False, f alert_receive_channel.deleted_at is not None or alert_receive_channel.integration == AlertReceiveChannel.INTEGRATION_MAINTENANCE ): - logger.info(f"AlertReceiveChannel alert ignored if deleted/maintenance") + logger.info("AlertReceiveChannel alert ignored if deleted/maintenance") return try: diff --git a/engine/apps/metrics_exporter/tasks.py b/engine/apps/metrics_exporter/tasks.py index ab7c0ee3..fe476de1 100644 --- a/engine/apps/metrics_exporter/tasks.py +++ b/engine/apps/metrics_exporter/tasks.py @@ -186,7 +186,6 @@ def calculate_and_cache_user_was_notified_metric(organization_id): metric_user_was_notified: typing.Dict[int, UserWasNotifiedOfAlertGroupsMetricsDict] = {} for user in users: - counter = ( user.personal_log_records.filter(type=UserNotificationPolicyLogRecord.TYPE_PERSONAL_NOTIFICATION_TRIGGERED) .values("alert_group") diff --git a/engine/apps/mobile_app/tasks.py b/engine/apps/mobile_app/tasks.py index 9b16baae..98101494 100644 --- a/engine/apps/mobile_app/tasks.py +++ b/engine/apps/mobile_app/tasks.py @@ -76,7 +76,7 @@ def _send_push_notification( if not CloudConnector.objects.exists(): _error_cb() - logger.error(f"Error while sending a mobile push notification: not connected to cloud") + logger.error("Error while sending a mobile push notification: not connected to cloud") return try: diff --git a/engine/apps/mobile_app/tests/test_your_going_oncall_notification.py b/engine/apps/mobile_app/tests/test_your_going_oncall_notification.py index 6d713671..a218fd6f 100644 --- a/engine/apps/mobile_app/tests/test_your_going_oncall_notification.py +++ b/engine/apps/mobile_app/tests/test_your_going_oncall_notification.py @@ -185,7 +185,7 @@ def test_get_youre_going_oncall_fcm_message( ): mock_fcm_message = "mncvmnvcmnvcnmvcmncvmn" mock_notification_title = "asdfasdf" - mock_notification_subtitle = f"9:06\u202fAM - 9:06\u202fAM\nSchedule XYZ" + mock_notification_subtitle = "9:06\u202fAM - 9:06\u202fAM\nSchedule XYZ" shift_pk = "mncvmnvc" seconds_until_going_oncall = 600 diff --git a/engine/apps/oss_installation/models/cloud_connector.py b/engine/apps/oss_installation/models/cloud_connector.py index 3ea43808..a526e080 100644 --- a/engine/apps/oss_installation/models/cloud_connector.py +++ b/engine/apps/oss_installation/models/cloud_connector.py @@ -48,7 +48,7 @@ class CloudConnector(models.Model): error_msg = f"Non-200 HTTP code. Got {r.status_code}" except requests.exceptions.RequestException as e: logger.warning(f"Unable to sync with cloud. Request exception {str(e)}") - error_msg = f"Unable to sync with cloud" + error_msg = "Unable to sync with cloud" return sync_status, error_msg @@ -86,7 +86,7 @@ class CloudConnector(models.Model): fetch_next_page = False except requests.exceptions.RequestException as e: logger.warning(f"Unable to sync users with cloud. Request exception {str(e)}") - error_msg = f"Unable to sync with cloud" + error_msg = "Unable to sync with cloud" users_fetched = False break @@ -146,7 +146,7 @@ class CloudConnector(models.Model): error_msg = f"User with email not found {user.email}" except requests.exceptions.RequestException as e: logger.warning(f"Unable to sync_user_with cloud user_id {user.id}. Request exception {str(e)}") - error_msg = f"Unable to sync with cloud" + error_msg = "Unable to sync with cloud" return sync_status, error_msg diff --git a/engine/apps/phone_notifications/phone_backend.py b/engine/apps/phone_notifications/phone_backend.py index 09f10151..26b64399 100644 --- a/engine/apps/phone_notifications/phone_backend.py +++ b/engine/apps/phone_notifications/phone_backend.py @@ -120,10 +120,10 @@ class PhoneBackend: if response.status_code == 200: logger.info("PhoneBackend._notify_by_cloud_call: OK") elif response.status_code == 400 and response.json().get("error") == "limit-exceeded": - logger.info(f"PhoneBackend._notify_by_cloud_call: phone calls limit exceeded") + logger.info("PhoneBackend._notify_by_cloud_call: phone calls limit exceeded") raise CallsLimitExceeded elif response.status_code == 400 and response.json().get("error") == "number-not-verified": - logger.info(f"PhoneBackend._notify_by_cloud_call: cloud number not verified") + logger.info("PhoneBackend._notify_by_cloud_call: cloud number not verified") raise NumberNotVerified elif response.status_code == 404: logger.info(f"PhoneBackend._notify_by_cloud_call: user not found id={user.id} email={user.email}") diff --git a/engine/apps/public_api/serializers/routes.py b/engine/apps/public_api/serializers/routes.py index 47d3961b..d680acf5 100644 --- a/engine/apps/public_api/serializers/routes.py +++ b/engine/apps/public_api/serializers/routes.py @@ -169,13 +169,13 @@ class ChannelFilterSerializer(BaseChannelFilterSerializer): try: valid_jinja_template_for_serializer_method_field({"route_template": filtering_term}) except JinjaTemplateError: - raise serializers.ValidationError([f"Jinja template is incorrect"]) + raise serializers.ValidationError(["Jinja template is incorrect"]) elif filtering_term_type == ChannelFilter.FILTERING_TERM_TYPE_REGEX or filtering_term_type is None: if filtering_term is not None: if not is_regex_valid(filtering_term): raise serializers.ValidationError(["Regular expression is incorrect"]) else: - raise serializers.ValidationError([f"Expression type is incorrect"]) + raise serializers.ValidationError(["Expression type is incorrect"]) return data diff --git a/engine/apps/public_api/tests/test_incidents.py b/engine/apps/public_api/tests/test_incidents.py index bb3d211f..0918eea3 100644 --- a/engine/apps/public_api/tests/test_incidents.py +++ b/engine/apps/public_api/tests/test_incidents.py @@ -133,7 +133,7 @@ def test_get_incidents_filter_by_state_new( client = APIClient() url = reverse("api-public:alert_groups-list") - response = client.get(url + f"?state=new", format="json", HTTP_AUTHORIZATION=f"{token}") + response = client.get(url + "?state=new", format="json", HTTP_AUTHORIZATION=f"{token}") assert response.status_code == status.HTTP_200_OK assert response.json() == expected_response @@ -149,7 +149,7 @@ def test_get_incidents_filter_by_state_acknowledged( client = APIClient() url = reverse("api-public:alert_groups-list") - response = client.get(url + f"?state=acknowledged", format="json", HTTP_AUTHORIZATION=f"{token}") + response = client.get(url + "?state=acknowledged", format="json", HTTP_AUTHORIZATION=f"{token}") assert response.status_code == status.HTTP_200_OK assert response.json() == expected_response @@ -165,7 +165,7 @@ def test_get_incidents_filter_by_state_silenced( client = APIClient() url = reverse("api-public:alert_groups-list") - response = client.get(url + f"?state=silenced", format="json", HTTP_AUTHORIZATION=f"{token}") + response = client.get(url + "?state=silenced", format="json", HTTP_AUTHORIZATION=f"{token}") assert response.status_code == status.HTTP_200_OK assert response.json() == expected_response @@ -181,7 +181,7 @@ def test_get_incidents_filter_by_state_resolved( client = APIClient() url = reverse("api-public:alert_groups-list") - response = client.get(url + f"?state=resolved", format="json", HTTP_AUTHORIZATION=f"{token}") + response = client.get(url + "?state=resolved", format="json", HTTP_AUTHORIZATION=f"{token}") assert response.status_code == status.HTTP_200_OK assert response.json() == expected_response @@ -195,7 +195,7 @@ def test_get_incidents_filter_by_state_unknown( client = APIClient() url = reverse("api-public:alert_groups-list") - response = client.get(url + f"?state=unknown", format="json", HTTP_AUTHORIZATION=f"{token}") + response = client.get(url + "?state=unknown", format="json", HTTP_AUTHORIZATION=f"{token}") assert response.status_code == status.HTTP_400_BAD_REQUEST diff --git a/engine/apps/schedules/models/shift_swap_request.py b/engine/apps/schedules/models/shift_swap_request.py index e13c5798..c8453f02 100644 --- a/engine/apps/schedules/models/shift_swap_request.py +++ b/engine/apps/schedules/models/shift_swap_request.py @@ -41,7 +41,6 @@ class ShiftSwapRequestManager(models.Manager): class ShiftSwapRequest(models.Model): - objects = ShiftSwapRequestManager() objects_with_deleted = models.Manager() diff --git a/engine/apps/slack/scenarios/manual_incident.py b/engine/apps/slack/scenarios/manual_incident.py index cfe8b98a..d4104c74 100644 --- a/engine/apps/slack/scenarios/manual_incident.py +++ b/engine/apps/slack/scenarios/manual_incident.py @@ -364,7 +364,7 @@ def _get_team_select(slack_user_identity, organization, value, input_id_prefix): { "text": { "type": "plain_text", - "text": f"General", + "text": "General", "emoji": True, }, "value": DEFAULT_TEAM_VALUE, diff --git a/engine/apps/slack/scenarios/paging.py b/engine/apps/slack/scenarios/paging.py index ecd5aca6..13bde725 100644 --- a/engine/apps/slack/scenarios/paging.py +++ b/engine/apps/slack/scenarios/paging.py @@ -496,7 +496,7 @@ def _get_team_select_blocks(slack_user_identity, organization, is_selected, valu { "text": { "type": "plain_text", - "text": f"No team", + "text": "No team", "emoji": True, }, "value": DEFAULT_TEAM_VALUE, diff --git a/engine/apps/slack/views.py b/engine/apps/slack/views.py index 9f94ca4f..404b04c8 100644 --- a/engine/apps/slack/views.py +++ b/engine/apps/slack/views.py @@ -198,7 +198,7 @@ class SlackEventApiEndpointView(APIView): # Means that slack_team_identity unpopulated if not slack_team_identity.organizations.exists(): - logger.warning(f"OnCall Team for SlackTeamIdentity is not detected, stop it!") + logger.warning("OnCall Team for SlackTeamIdentity is not detected, stop it!") # Open pop-up to inform user why OnCall bot doesn't work if any action was triggered warning_text = ( "OnCall is not able to process this action because this Slack workspace was " diff --git a/engine/apps/twilioapp/phone_provider.py b/engine/apps/twilioapp/phone_provider.py index 4f5f1500..988746f1 100644 --- a/engine/apps/twilioapp/phone_provider.py +++ b/engine/apps/twilioapp/phone_provider.py @@ -45,7 +45,7 @@ class TwilioPhoneProvider(PhoneProvider): # If status callback is not valid and not accessible from public url then trying to send message without it # https://www.twilio.com/docs/api/errors/21609 if e.code == 21609: - logger.info(f"TwilioPhoneProvider.make_notification_call: error 21609, calling without callback_url") + logger.info("TwilioPhoneProvider.make_notification_call: error 21609, calling without callback_url") try_without_callback = True else: logger.error(f"TwilioPhoneProvider.make_notification_call: failed {e}") @@ -75,7 +75,7 @@ class TwilioPhoneProvider(PhoneProvider): # If status callback is not valid and not accessible from public url then trying to send message without it # https://www.twilio.com/docs/api/errors/21609 if e.code == 21609: - logger.info(f"TwilioPhoneProvider.send_notification_sms: error 21609, sending without callback_url") + logger.info("TwilioPhoneProvider.send_notification_sms: error 21609, sending without callback_url") try_without_callback = True else: logger.error(f"TwilioPhoneProvider.send_notification_sms: failed {e}") diff --git a/engine/apps/zvonok/models/phone_call.py b/engine/apps/zvonok/models/phone_call.py index d47fa93b..f3f45845 100644 --- a/engine/apps/zvonok/models/phone_call.py +++ b/engine/apps/zvonok/models/phone_call.py @@ -4,7 +4,6 @@ from apps.phone_notifications.phone_provider import ProviderPhoneCall class ZvonokCallStatuses: - ATTEMPTS_EXC = 10 COMPL_FINISHED = 20 COMPL_NOFINISHED = 30 diff --git a/engine/apps/zvonok/phone_provider.py b/engine/apps/zvonok/phone_provider.py index f3f99952..49d7c67b 100644 --- a/engine/apps/zvonok/phone_provider.py +++ b/engine/apps/zvonok/phone_provider.py @@ -34,12 +34,12 @@ class ZvonokPhoneProvider(PhoneProvider): response.raise_for_status() body = response.json() if not body: - logger.error(f"ZvonokPhoneProvider.make_notification_call: failed, empty body") + logger.error("ZvonokPhoneProvider.make_notification_call: failed, empty body") raise FailedToMakeCall(graceful_msg=f"Failed make notification call to {number}, empty body") call_id = body.get("call_id") if not call_id: - logger.error(f"ZvonokPhoneProvider.make_notification_call: failed, missing call id") + logger.error("ZvonokPhoneProvider.make_notification_call: failed, missing call id") raise FailedToMakeCall(graceful_msg=self._get_graceful_msg(body, number)) logger.info(f"ZvonokPhoneProvider.make_notification_call: success, call_id {call_id}") @@ -66,7 +66,7 @@ class ZvonokPhoneProvider(PhoneProvider): response.raise_for_status() body = response.json() if not body: - logger.error(f"ZvonokPhoneProvider.make_call: failed, empty body") + logger.error("ZvonokPhoneProvider.make_call: failed, empty body") raise FailedToMakeCall(graceful_msg=f"Failed make call to {number}, empty body") call_id = body.get("call_id") @@ -116,7 +116,7 @@ class ZvonokPhoneProvider(PhoneProvider): response.raise_for_status() body = response.json() if not body: - logger.error(f"ZvonokPhoneProvider.make_verification_call: failed, empty body") + logger.error("ZvonokPhoneProvider.make_verification_call: failed, empty body") raise FailedToMakeCall(graceful_msg=f"Failed make verification call to {number}, empty body") call_id = body.get("call_id") diff --git a/engine/common/insight_log/maintenance_insight_log.py b/engine/common/insight_log/maintenance_insight_log.py index d0426ebe..884c74cf 100644 --- a/engine/common/insight_log/maintenance_insight_log.py +++ b/engine/common/insight_log/maintenance_insight_log.py @@ -28,7 +28,7 @@ def write_maintenance_insight_log(instance, user, event: MaintenanceEvent): if team: log_line += f" team={json.dumps(team.name)} team_id={team.public_primary_key}" else: - log_line += f' team="General"' + log_line += ' team="General"' if user: username = json.dumps(user.username) user_id = user.public_primary_key diff --git a/engine/engine/celery.py b/engine/engine/celery.py index c7ac45fa..f0159207 100644 --- a/engine/engine/celery.py +++ b/engine/engine/celery.py @@ -3,6 +3,7 @@ import os import time import celery +from celery import Celery from celery.app.log import TaskFormatter from celery.utils.debug import memdump, sample_mem from celery.utils.log import get_task_logger @@ -19,7 +20,6 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.prod") logger = get_task_logger(__name__) logger.setLevel(logging.DEBUG) -from celery import Celery # noqa: E402 app = Celery("proj") diff --git a/engine/pyproject.toml b/engine/pyproject.toml index b74b866f..0cdc724a 100644 --- a/engine/pyproject.toml +++ b/engine/pyproject.toml @@ -1,14 +1,13 @@ [tool.isort] profile = "black" line_length=120 -# TODO: upgrade this to python 3.11 -py_version=39 +float_to_top=true +py_version=311 extend_skip_glob = "**/migrations/**" [tool.black] line-length = 120 -# TODO: upgrade this to python 3.11 -target-version = ["py39"] +target-version = ["py311"] force-exclude = "migrations" [tool.mypy] diff --git a/engine/settings/prod_without_db.py b/engine/settings/prod_without_db.py index 4189f426..da96f94f 100644 --- a/engine/settings/prod_without_db.py +++ b/engine/settings/prod_without_db.py @@ -1,5 +1,7 @@ import os +from .base import * # noqa: F401, F403 + try: import uwsgi from prometheus_client import multiprocess @@ -13,7 +15,6 @@ except ModuleNotFoundError: # Only works under uwsgi web server environment pass -from .base import * # noqa SLACK_SIGNING_SECRET = os.environ.get("SLACK_SIGNING_SECRET") SLACK_SIGNING_SECRET_LIVE = os.environ.get("SLACK_SIGNING_SECRET_LIVE", "") diff --git a/engine/tox.ini b/engine/tox.ini index a8c8fd39..7f458ba2 100644 --- a/engine/tox.ini +++ b/engine/tox.ini @@ -1,6 +1,6 @@ [flake8] max-line-length = 180 -extend-ignore = F541, E203 +extend-ignore = E203 extend-exclude = */migrations/* ban-relative-imports = parents banned-modules =