diff --git a/app/src/bittensor_panel/core/migrations/0001_initial.py b/app/src/bittensor_panel/core/migrations/0001_initial.py index 00c04ac..fe0ea6b 100644 --- a/app/src/bittensor_panel/core/migrations/0001_initial.py +++ b/app/src/bittensor_panel/core/migrations/0001_initial.py @@ -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()), ], ), ] diff --git a/app/src/bittensor_panel/core/services.py b/app/src/bittensor_panel/core/services.py index c45079b..b3d0f17 100644 --- a/app/src/bittensor_panel/core/services.py +++ b/app/src/bittensor_panel/core/services.py @@ -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"]) @@ -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"]) diff --git a/app/src/bittensor_panel/core/tests/test_admin.py b/app/src/bittensor_panel/core/tests/test_admin.py index 9f355b0..965579f 100644 --- a/app/src/bittensor_panel/core/tests/test_admin.py +++ b/app/src/bittensor_panel/core/tests/test_admin.py @@ -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() @@ -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/") diff --git a/app/src/bittensor_panel/core/tests/test_bt.py b/app/src/bittensor_panel/core/tests/test_bt.py index 2985c6c..22595e5 100644 --- a/app/src/bittensor_panel/core/tests/test_bt.py +++ b/app/src/bittensor_panel/core/tests/test_bt.py @@ -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" diff --git a/app/src/bittensor_panel/core/tests/test_services.py b/app/src/bittensor_panel/core/tests/test_services.py index 4d935d7..46ff0c3 100644 --- a/app/src/bittensor_panel/core/tests/test_services.py +++ b/app/src/bittensor_panel/core/tests/test_services.py @@ -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( diff --git a/app/src/bittensor_panel/settings.py b/app/src/bittensor_panel/settings.py index b676fd9..dde631d 100644 --- a/app/src/bittensor_panel/settings.py +++ b/app/src/bittensor_panel/settings.py @@ -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 @@ -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 @@ -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")