Skip to content

Commit

Permalink
Format with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
olzhasar-reef committed May 4, 2024
1 parent cf9b3bb commit d5ee696
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 39 deletions.
16 changes: 7 additions & 9 deletions app/src/bittensor_panel/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='HyperParameter',
name="HyperParameter",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('name', models.CharField(max_length=255, unique=True)),
('value', models.IntegerField()),
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("name", models.CharField(max_length=255, unique=True)),
("value", models.IntegerField()),
],
),
]
12 changes: 3 additions & 9 deletions app/src/bittensor_panel/core/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ def update_hyperparam(instance: HyperParameter) -> None:
try:
result = update_remote_hyperparam(instance.name, instance.value)
except (SystemExit, Exception) as e:
raise HyperParameterUpdateFailed(
"Failed to update remote hyperparameter"
) from e
raise HyperParameterUpdateFailed("Failed to update remote hyperparameter") from e
if not result:
raise HyperParameterUpdateFailed(
"Failed to update remote hyperparameter. Subtensor returned False."
)
raise HyperParameterUpdateFailed("Failed to update remote hyperparameter. Subtensor returned False.")

instance.save(update_fields=["value"])

Expand All @@ -48,6 +44,4 @@ def refresh_hyperparams() -> None:
for name, value in hyperparam_dict.items():
objs.append(HyperParameter(name=name, value=value))

HyperParameter.objects.bulk_create(
objs, update_conflicts=True, update_fields=["value"], unique_fields=["name"]
)
HyperParameter.objects.bulk_create(objs, update_conflicts=True, update_fields=["value"], unique_fields=["name"])
8 changes: 2 additions & 6 deletions app/src/bittensor_panel/core/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def mock_refresh_hyperparams(mocker: MockerFixture):
return mocker.patch("bittensor_panel.core.admin.refresh_hyperparams")


def test_refresh_hyperparams_view(
admin_client: Client, mock_refresh_hyperparams: MagicMock
):
def test_refresh_hyperparams_view(admin_client: Client, mock_refresh_hyperparams: MagicMock):
response = admin_client.post("/admin/core/hyperparameter/refresh-hyperparams/")

mock_refresh_hyperparams.assert_called_once()
Expand All @@ -24,9 +22,7 @@ def test_refresh_hyperparams_view(
assert response.url == "/admin/core/hyperparameter/"


def test_refresh_hyperparams_view_exception(
admin_client: Client, mock_refresh_hyperparams: MagicMock
):
def test_refresh_hyperparams_view_exception(admin_client: Client, mock_refresh_hyperparams: MagicMock):
mock_refresh_hyperparams.side_effect = HyperParameterRefreshFailed("error")

response = admin_client.post("/admin/core/hyperparameter/refresh-hyperparams/")
Expand Down
4 changes: 1 addition & 3 deletions app/src/bittensor_panel/core/tests/test_bt.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ def mock_wallet(mocker: MockerFixture):


@pytest.mark.parametrize("result", [True, False])
def test_update_remote_hyperparam(
mock_subtensor: MagicMock, mock_wallet: MagicMock, result: bool, settings
):
def test_update_remote_hyperparam(mock_subtensor: MagicMock, mock_wallet: MagicMock, result: bool, settings):
mock_subtensor.return_value.set_hyperparameter.return_value = result

name = "difficulty"
Expand Down
4 changes: 1 addition & 3 deletions app/src/bittensor_panel/core/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ def hyperparam_dict(faker: Faker):

@pytest.fixture
def mock_load_hyperparams(mocker: MockerFixture, hyperparam_dict: dict[str, int]):
return mocker.patch(
"bittensor_panel.core.services.load_hyperparams", return_value=hyperparam_dict
)
return mocker.patch("bittensor_panel.core.services.load_hyperparams", return_value=hyperparam_dict)


def test_refresh_hyperparams(
Expand Down
12 changes: 3 additions & 9 deletions app/src/bittensor_panel/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ def wrapped(*args, **kwargs):
WSGI_APPLICATION = "bittensor_panel.wsgi.application"

DATABASES = {}
if env(
"DATABASE_POOL_URL"
): # DB transaction-based connection pool, such as one provided PgBouncer
if env("DATABASE_POOL_URL"): # DB transaction-based connection pool, such as one provided PgBouncer
DATABASES["default"] = {
**env.db_url("DATABASE_POOL_URL"),
"DISABLE_SERVER_SIDE_CURSORS": True, # prevents random cursor errors with transaction-based connection pool
Expand Down Expand Up @@ -206,9 +204,7 @@ def wrapped(*args, **kwargs):

CELERY_BROKER_URL = env("CELERY_BROKER_URL", default="")
CELERY_RESULT_BACKEND = env("CELERY_BROKER_URL", default="") # store results in Redis
CELERY_RESULT_EXPIRES = int(
timedelta(days=1).total_seconds()
) # time until task result deletion
CELERY_RESULT_EXPIRES = int(timedelta(days=1).total_seconds()) # time until task result deletion
CELERY_COMPRESSION = "gzip" # task compression
CELERY_MESSAGE_COMPRESSION = "gzip" # result compression
CELERY_SEND_EVENTS = True # needed for worker monitoring
Expand All @@ -227,9 +223,7 @@ def wrapped(*args, **kwargs):
CELERY_ACCEPT_CONTENT = ["json"]
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
CELERY_WORKER_PREFETCH_MULTIPLIER = env.int(
"CELERY_WORKER_PREFETCH_MULTIPLIER", default=10
)
CELERY_WORKER_PREFETCH_MULTIPLIER = env.int("CELERY_WORKER_PREFETCH_MULTIPLIER", default=10)
CELERY_BROKER_POOL_LIMIT = env.int("CELERY_BROKER_POOL_LIMIT", default=50)

EMAIL_BACKEND = env("EMAIL_BACKEND")
Expand Down

0 comments on commit d5ee696

Please sign in to comment.