Skip to content

Commit efc3b00

Browse files
authored
Make tox consistent (#141)
* update tox config * Make linting consistent * remove black * fix F401 and re-add
1 parent a8e50db commit efc3b00

File tree

14 files changed

+117
-72
lines changed

14 files changed

+117
-72
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ RUN apt-get update && \
2626
apt-get install --no-install-recommends python3 tini ca-certificates -y && \
2727
rm -rf /var/lib/apt/lists/*
2828

29-
# Copy accross the venv
29+
# Copy across the venv
3030
COPY --from=build-image /opt/venv /opt/venv
3131
ENV PATH="/opt/venv/bin:$PATH"
3232

azimuth_schedule_operator/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async def main():
1010
Run the operator and the metrics server together.
1111
"""
1212
# This import is required to pick up the operator handlers
13-
from . import operator # noqa
13+
from . import operator # noqa: F401
1414

1515
kopf.configure(log_prefix=True)
1616
tasks = await kopf.spawn_tasks(

azimuth_schedule_operator/metrics.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import asyncio
22
import functools
33

4+
import easykube
45
from aiohttp import web
5-
66
from dateutil.parser import isoparse
77

8-
import easykube
9-
108
from .models import registry
119

1210

@@ -15,7 +13,7 @@ class Metric:
1513
prefix = None
1614
# The suffix for the metric
1715
suffix = None
18-
# The type of the metric - info or guage
16+
# The type of the metric - info or gauge
1917
type = "info"
2018
# The description of the metric
2119
description = None
@@ -129,7 +127,7 @@ def format_value(value):
129127
formatted = repr(value)
130128
dot = formatted.find(".")
131129
if value > 0 and dot > 6:
132-
mantissa = f"{formatted[0]}.{formatted[1:dot]}{formatted[dot + 1:]}".rstrip(
130+
mantissa = f"{formatted[0]}.{formatted[1:dot]}{formatted[dot + 1 :]}".rstrip(
133131
"0."
134132
)
135133
return f"{mantissa}e+0{dot - 1}"
@@ -147,7 +145,7 @@ def render_openmetrics(*metrics):
147145

148146
for labels, value in metric.records():
149147
if labels:
150-
labelstr = "{{{0}}}".format(
148+
labelstr = "{{{}}}".format(
151149
",".join([f'{k}="{escape(v)}"' for k, v in sorted(labels.items())])
152150
)
153151
else:

azimuth_schedule_operator/models/v1alpha1/lease.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import datetime as dt
2-
import typing as t
3-
4-
from pydantic import Field
52

63
from kube_custom_resource import CustomResource, schema
4+
from pydantic import Field
75

86

97
class Machine(schema.BaseModel):
@@ -20,7 +18,7 @@ class Machine(schema.BaseModel):
2018
class ResourcesSpec(schema.BaseModel):
2119
"""The resources that a lease is reserving."""
2220

23-
machines: t.List[Machine] = Field(
21+
machines: list[Machine] = Field(
2422
default_factory=list,
2523
description="Machines that should be reserved by the lease.",
2624
)
@@ -92,7 +90,7 @@ class LeaseStatus(schema.BaseModel, extra="allow"):
9290
description="Mapping of original size name to reserved size name.",
9391
)
9492

95-
def set_phase(self, phase: LeasePhase, error_message: t.Optional[str] = None):
93+
def set_phase(self, phase: LeasePhase, error_message: str | None = None):
9694
"""Set the phase of the lease, along with an optional error message."""
9795
self.phase = phase
9896
self.error_message = error_message if phase == LeasePhase.ERROR else ""

azimuth_schedule_operator/models/v1alpha1/schedule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import datetime
22

33
import kube_custom_resource as crd
4-
from kube_custom_resource import schema
54
import pydantic
5+
from kube_custom_resource import schema
66

77

88
class ScheduleStatus(schema.BaseModel):

azimuth_schedule_operator/openstack.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import urllib.parse
55

66
import httpx
7-
87
import yaml
9-
108
from easykube import rest
119

1210

@@ -172,7 +170,7 @@ async def __aenter__(self):
172170
client = Client(
173171
base_url=self._auth.url, auth=self._auth, transport=self._transport
174172
)
175-
# We have to slightly artifically create the catalog URL as we don't
173+
# We have to slightly artificially create the catalog URL as we don't
176174
# benefit from the prefix handling that the resources use
177175
catalog_url = self._auth.url.rstrip("/") + "/v3/auth/catalog"
178176
try:

azimuth_schedule_operator/operator.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
import os
77
import sys
88

9+
import easykube
910
import httpx
1011
import kopf
1112

12-
import easykube
13-
13+
from azimuth_schedule_operator import openstack
1414
from azimuth_schedule_operator.models import registry
1515
from azimuth_schedule_operator.models.v1alpha1 import (
1616
lease as lease_crd,
17+
)
18+
from azimuth_schedule_operator.models.v1alpha1 import (
1719
schedule as schedule_crd,
1820
)
19-
from azimuth_schedule_operator import openstack
2021
from azimuth_schedule_operator.utils import k8s
2122

2223
LOG = logging.getLogger(__name__)
@@ -163,8 +164,8 @@ async def check_for_delete(namespace: str, schedule: schedule_crd.Schedule):
163164
async def update_schedule(
164165
namespace: str,
165166
name: str,
166-
ref_exists: bool = None,
167-
ref_delete_triggered: bool = None,
167+
ref_exists: bool | None = None,
168+
ref_delete_triggered: bool | None = None,
168169
):
169170
now = datetime.datetime.now(datetime.timezone.utc)
170171
now_string = now.strftime("%Y-%m-%dT%H:%M:%SZ")
@@ -375,7 +376,7 @@ async def reconcile_lease(body, logger, **_):
375376
lease.status.size_name_map = await get_size_name_map(
376377
cloud, lease.status.size_map
377378
)
378-
# Save the currrent status of the lease
379+
# Save the current status of the lease
379380
await save_instance_status(lease)
380381
else:
381382
# We are not using Blazar

azimuth_schedule_operator/tests/models/test_crds.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# ruff: noqa: E501
2+
13
import json
24

35
from azimuth_schedule_operator.models import registry
@@ -293,5 +295,5 @@ def test_lease_crd_json(self):
293295
}
294296
]
295297
}
296-
}""" # noqa
298+
}"""
297299
self.assertEqual(expected, actual)

azimuth_schedule_operator/tests/test_lease.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
import unittest
33
from unittest import mock
44

5-
from easykube.rest.util import PropertyDict
6-
75
import freezegun
8-
96
import kopf
7+
from easykube.rest.util import PropertyDict
108

11-
from ..models.v1alpha1 import lease as lease_crd
12-
from .. import openstack, operator
9+
from azimuth_schedule_operator import openstack, operator
10+
from azimuth_schedule_operator.models.v1alpha1 import lease as lease_crd
1311

1412
from . import util
1513

16-
1714
API_VERSION = "scheduling.azimuth.stackhpc.com/v1alpha1"
1815

1916

@@ -185,9 +182,9 @@ async def test_save_instance_status(self, k8s_client):
185182
async def test_save_instance_status_conflict(self, k8s_client):
186183
lease_data = fake_lease(phase=lease_crd.LeasePhase.PENDING)
187184

188-
k8s_client.apis[API_VERSION].resources["leases/status"].replace.side_effect = (
189-
util.k8s_api_error(409)
190-
)
185+
k8s_client.apis[API_VERSION].resources[
186+
"leases/status"
187+
].replace.side_effect = util.k8s_api_error(409)
191188

192189
lease = lease_crd.Lease.model_validate(lease_data)
193190
with self.assertRaises(kopf.TemporaryError):
@@ -351,15 +348,15 @@ def test_get_size_map(self):
351348

352349
async def test_get_size_name_map(self):
353350
cloud = util.mock_openstack_cloud()
354-
cloud.clients["compute"].resources["flavors"].list.return_value = (
355-
util.as_async_iterable(
356-
[
357-
PropertyDict({"id": "id1", "name": "flavor1"}),
358-
PropertyDict({"id": "id2", "name": "flavor2"}),
359-
PropertyDict({"id": "newid1", "name": "newflavor1"}),
360-
PropertyDict({"id": "newid2", "name": "newflavor2"}),
361-
]
362-
)
351+
cloud.clients["compute"].resources[
352+
"flavors"
353+
].list.return_value = util.as_async_iterable(
354+
[
355+
PropertyDict({"id": "id1", "name": "flavor1"}),
356+
PropertyDict({"id": "id2", "name": "flavor2"}),
357+
PropertyDict({"id": "newid1", "name": "newflavor1"}),
358+
PropertyDict({"id": "newid2", "name": "newflavor2"}),
359+
]
363360
)
364361

365362
size_map = {"id1": "newid1", "id2": "newid2", "id3": "newid3"}
@@ -1290,9 +1287,9 @@ async def test_delete_lease_finalizer_present(self, k8s_client):
12901287
async def test_delete_lease_secret_already_deleted(self, k8s_client):
12911288
# Configure the Kubernetes client
12921289
self.k8s_client_config_common(k8s_client)
1293-
k8s_client.apis["v1"].resources["secrets"].fetch.side_effect = (
1294-
util.k8s_api_error(404)
1295-
)
1290+
k8s_client.apis["v1"].resources[
1291+
"secrets"
1292+
].fetch.side_effect = util.k8s_api_error(404)
12961293

12971294
lease = fake_lease()
12981295
await operator.delete_lease(lease, mock.Mock())

azimuth_schedule_operator/tests/test_schedule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import unittest
33
from unittest import mock
44

5-
from azimuth_schedule_operator.models.v1alpha1 import schedule as schedule_crd
65
from azimuth_schedule_operator import operator
6+
from azimuth_schedule_operator.models.v1alpha1 import schedule as schedule_crd
77

88

99
class TestSchedule(unittest.IsolatedAsyncioTestCase):

0 commit comments

Comments
 (0)