Skip to content

Commit

Permalink
[INTERNAL] Migrate Black to Ruff for code formatting #487
Browse files Browse the repository at this point in the history
  • Loading branch information
kfdm authored Mar 5, 2024
2 parents 1cab273 + 4680815 commit 1822788
Show file tree
Hide file tree
Showing 39 changed files with 72 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ a81731039c118543398c90869e608dde0acaf32c
af2c352786f952d819e69b928bf6c99dcde5954b
# Compile requirements to update comments
5821434b42203b1080dcdc480d1ffcf07fe53a90
# Format with Ruff
e72aba6d7e5891ac777f533eef6f7520410c9e0b
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ APP_BIN := $(ENV_DIR)/bin/promgen
CELERY_BIN := $(ENV_DIR)/bin/celery
SPHINX := $(ENV_DIR)/bin/sphinx-build
RUFF_BIN := $(ENV_DIR)/bin/ruff
BLACK_BIN := $(ENV_DIR)/bin/black

DOCKER_TAG := promgen:local
SYSTEM_PYTHON ?= python3.9
Expand Down Expand Up @@ -144,13 +143,11 @@ docs: $(SPHINX)
$(RUFF_BIN): $(PIP_BIN)
$(PIP_BIN) install ruff

$(BLACK_BIN): $(PIP_BIN)
$(PIP_BIN) install black

.PHONY: format
format: $(RUFF_BIN) $(BLACK_BIN)
format: $(RUFF_BIN)
$(RUFF_BIN) check promgen --fix
$(BLACK_BIN) promgen
$(RUFF_BIN) format promgen


#### Other assorted commands
Expand Down
2 changes: 0 additions & 2 deletions promgen/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import socket

import celery

from celery.signals import celeryd_after_setup


logger = logging.getLogger(__name__)


Expand Down
4 changes: 2 additions & 2 deletions promgen/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright (c) 2017 LINE Corporation
# These sources are released under the terms of the MIT license: see LICENSE

from promgen import models, util

from django.conf import settings

from promgen import models, util


def settings_in_view(request):
return {
Expand Down
3 changes: 1 addition & 2 deletions promgen/discovery/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

from django.shortcuts import get_object_or_404

from promgen import models
from promgen import discovery
from promgen import discovery, models

logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion promgen/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enum import Enum
from django.utils.translation import gettext as _

from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _


class ValidationErrorEnum(Enum):
Expand Down
2 changes: 1 addition & 1 deletion promgen/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django import forms
from django.core.exceptions import ValidationError

from promgen import models, plugins, prometheus, validators, errors
from promgen import errors, models, plugins, prometheus, validators


class ImportConfigForm(forms.Form):
Expand Down
1 change: 0 additions & 1 deletion promgen/management/commands/import-probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sys

import yaml

from django.core import exceptions
from django.core.management.base import BaseCommand

Expand Down
5 changes: 3 additions & 2 deletions promgen/migrations/0001_squashed_0044_common-rules.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Generated by Django 1.11.10 on 2018-02-07 06:56

from django.conf import settings
import django.contrib.sites.models
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models

import promgen.models
import promgen.validators

Expand Down
2 changes: 1 addition & 1 deletion promgen/migrations/0003_alert_queue.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 2.0.7 on 2018-07-26 08:15

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion promgen/migrations/0003_default-group.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 2.0.7 on 2018-07-31 08:09

from django.db import migrations
from django.conf import settings
from django.db import migrations


def create_group(apps, schema_editor):
Expand Down
2 changes: 1 addition & 1 deletion promgen/migrations/0005_project_owner.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 2.1.2 on 2018-11-16 02:23

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion promgen/migrations/0007_message_filter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 2.1.2 on 2019-03-06 06:20

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion promgen/migrations/0008_shard_service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 2.1.8 on 2019-04-22 07:15

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


def project_to_shard(apps, schema_editor):
Expand Down
2 changes: 1 addition & 1 deletion promgen/migrations/0009_blackbox-module.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 2.1.8 on 2019-05-31 04:46

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


def default_probe(apps, schema_editor):
Expand Down
2 changes: 1 addition & 1 deletion promgen/migrations/0011_notifier_counts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 2.2.4 on 2019-11-28 02:21

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion promgen/migrations/0012_validation_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Generated by Django 2.2.9 on 2020-01-16 06:35

import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion promgen/migrations/0015_internal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 2.2.10 on 2020-02-21 05:56

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion promgen/migrations/0016_alertlabel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 2.2.8 on 2020-02-21 06:03

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
1 change: 1 addition & 0 deletions promgen/notification/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from django import forms
from django.contrib.auth.models import User

from promgen import models
from promgen.notification import NotificationBase

Expand Down
1 change: 0 additions & 1 deletion promgen/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import pytz
import yaml
from dateutil import parser

from django.core.exceptions import ValidationError
from django.utils import timezone

Expand Down
5 changes: 3 additions & 2 deletions promgen/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
from django.http import HttpResponse, JsonResponse
from django.views.generic import View
from django.views.generic.base import TemplateView
from promgen import forms, models, prometheus, util
from requests.exceptions import HTTPError

from promgen import forms, models, prometheus, util

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -213,7 +214,7 @@ def post(self, request):
return JsonResponse(
{
"messages": [
{"class": "alert alert-danger", "message": e.response.text}
{"class": "alert alert-danger", "message": e.response.text},
]
},
status=e.response.status_code,
Expand Down
5 changes: 2 additions & 3 deletions promgen/rest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Copyright (c) 2019 LINE Corporation
# These sources are released under the terms of the MIT license: see LICENSE

from django.http import HttpResponse
from django.views.generic import View
from rest_framework import permissions, viewsets
from rest_framework.decorators import action
from rest_framework.response import Response

from django.http import HttpResponse
from django.views.generic import View

from promgen import filters, models, prometheus, renderers, serializers, tasks


Expand Down
3 changes: 1 addition & 2 deletions promgen/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import collections

from rest_framework import serializers

from django.db.models import prefetch_related_objects
from rest_framework import serializers

import promgen.templatetags.promgen as macro
from promgen import models, shortcuts
Expand Down
3 changes: 1 addition & 2 deletions promgen/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import environ
import yaml

from django.urls import reverse_lazy

from promgen import PROMGEN_CONFIG_FILE
Expand Down Expand Up @@ -175,8 +174,8 @@

if "SENTRY_DSN" in os.environ:
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.django import DjangoIntegration

os.environ.setdefault("SENTRY_RELEASE", PROMGEN_VERSION)
# By default we want to keep sentry's default of NOT sending user
Expand Down
1 change: 1 addition & 0 deletions promgen/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from django.conf import settings
from django.shortcuts import resolve_url

from promgen import models


Expand Down
1 change: 1 addition & 0 deletions promgen/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.core.cache import cache
from django.db.models.signals import post_delete, post_save, pre_delete, pre_save
from django.dispatch import Signal, receiver

from promgen import models, prometheus, tasks

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion promgen/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from celery import shared_task
from requests.exceptions import RequestException

from promgen import models, prometheus, util, notification
from promgen import models, notification, prometheus, util

logger = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions promgen/templatetags/promgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
from urllib.parse import urlencode

import yaml
from pytz import timezone

from django import template
from django.urls import reverse
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _
from pytz import timezone

from promgen import util

Expand Down
6 changes: 3 additions & 3 deletions promgen/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# These sources are released under the terms of the MIT license: see LICENSE

import json
from django.urls import reverse
import yaml

import yaml
from django.conf import settings
from django.contrib.auth.models import Permission, User
from django.test import TestCase
from django.conf import settings
from django.urls import reverse


class Data:
Expand Down
3 changes: 1 addition & 2 deletions promgen/tests/notification/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

from unittest import mock

from requests.exceptions import RequestException

from django.test import override_settings
from requests.exceptions import RequestException

from promgen import models, rest, tests
from promgen.notification.webhook import NotificationWebhook
Expand Down
4 changes: 1 addition & 3 deletions promgen/tests/test_alert_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
for: 1s
labels:
severity: high
""".lstrip().encode(
"utf-8"
)
""".lstrip().encode("utf-8")

TEST_SETTINGS = tests.Data("examples", "promgen.yml").yaml()

Expand Down
1 change: 0 additions & 1 deletion promgen/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from unittest import mock

import requests

from django.test import override_settings
from django.urls import reverse

Expand Down
10 changes: 3 additions & 7 deletions promgen/tests/test_silence.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.test import override_settings
from django.urls import reverse

from promgen import forms, tests, errors
from promgen import errors, forms, tests

TEST_SETTINGS = tests.Data("examples", "promgen.yml").yaml()
TEST_DURATION = tests.Data("examples", "silence.duration.json").json()
Expand Down Expand Up @@ -41,9 +41,7 @@ def test_duration(self, mock_post):
},
content_type="application/json",
)
mock_post.assert_called_with(
"http://alertmanager:9093/api/v2/silences", json=TEST_DURATION
)
mock_post.assert_called_with("http://alertmanager:9093/api/v2/silences", json=TEST_DURATION)

@override_settings(PROMGEN=TEST_SETTINGS)
@mock.patch("promgen.util.post")
Expand All @@ -62,9 +60,7 @@ def test_range(self, mock_post):
content_type="application/json",
)

mock_post.assert_called_with(
"http://alertmanager:9093/api/v2/silences", json=TEST_RANGE
)
mock_post.assert_called_with("http://alertmanager:9093/api/v2/silences", json=TEST_RANGE)

@override_settings(PROMGEN=TEST_SETTINGS)
def test_site_silence_errors(self):
Expand Down
Loading

0 comments on commit 1822788

Please sign in to comment.