Skip to content

Commit 48e86f4

Browse files
committed
Maintenance: Add support for Python 3.12
1 parent 553e58f commit 48e86f4

File tree

7 files changed

+28
-18
lines changed

7 files changed

+28
-18
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
hooks:
1111
- id: black
1212
- repo: https://github.com/PyCQA/flake8
13-
rev: "3.8.4"
13+
rev: "7.1.1"
1414
hooks:
1515
- id: flake8
1616
- repo: https://github.com/timothycrosley/isort

crate/operator/__init__.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@
1818
# However, if you have executed another commercial license agreement
1919
# with Crate these terms will supersede the license and you may use the
2020
# software solely pursuant to the terms of the relevant commercial agreement.
21-
from pkg_resources import DistributionNotFound, get_distribution
2221

2322
try:
24-
__version__ = get_distribution("crate-operator").version
25-
except DistributionNotFound:
26-
# package is not installed
27-
pass
23+
from importlib.metadata import PackageNotFoundError, version
24+
except (ImportError, ModuleNotFoundError): # pragma:nocover
25+
from importlib_metadata import ( # type: ignore[assignment,no-redef,unused-ignore]
26+
PackageNotFoundError,
27+
version,
28+
)
29+
30+
__appname__ = "crate-operator"
31+
32+
try:
33+
__version__ = version(__appname__)
34+
except PackageNotFoundError: # pragma: no cover
35+
__version__ = "unknown"

crate/operator/operations.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,12 @@ async def restart_cluster(
505505
if next_pod_uid in all_pod_uids:
506506
# The next to-be-terminated pod still appears to be running.
507507
logger.info("Terminating pod '%s'", next_pod_name)
508+
node_index = int(next_pod_name[next_pod_name.rindex("-") + 1 :])
509+
node_progress = f"{node_index + 1}/{len(all_pod_uids)}"
508510
await send_operation_progress_notification(
509511
namespace=namespace,
510512
name=name,
511-
message="Waiting for node "
512-
f"{int(next_pod_name[next_pod_name.rindex('-')+1:])+1}/{len(all_pod_uids)}"
513-
" to be terminated...",
513+
message=f"Waiting for node {node_progress} to be terminated.",
514514
logger=logger,
515515
status=WebhookStatus.IN_PROGRESS,
516516
operation=WebhookOperation.UPDATE,
@@ -527,12 +527,12 @@ async def restart_cluster(
527527
elif next_pod_name in all_pod_names:
528528
total_nodes = get_total_nodes_count(old["spec"]["nodes"], "all")
529529
# The new pod has been spawned. Only a matter of time until it's ready.
530+
node_index = int(next_pod_name[next_pod_name.rindex("-") + 1 :])
531+
node_progress = f"{node_index + 1}/{len(all_pod_uids)}"
530532
await send_operation_progress_notification(
531533
namespace=namespace,
532534
name=name,
533-
message="Waiting for node "
534-
f"{int(next_pod_name[next_pod_name.rindex('-')+1:])+1}/{len(all_pod_uids)}"
535-
" to be restarted...",
535+
message=f"Waiting for node {node_progress} to be restarted.",
536536
logger=logger,
537537
status=WebhookStatus.IN_PROGRESS,
538538
operation=WebhookOperation.UPDATE,

crate/operator/utils/version.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
# software solely pursuant to the terms of the relevant commercial agreement.
2121

2222
import re
23-
from distutils.version import Version
2423
from typing import Optional, Tuple, Union, cast
2524

25+
from verlib2.distutils.version import Version
26+
2627

2728
class CrateVersion(Version):
2829
"""Version numbering for CrateDB releases.

crate/operator/webhooks.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import aiohttp
2727
import kopf
2828
from aiohttp import TCPConnector
29-
from pkg_resources import get_distribution
3029

30+
from crate.operator import __version__
3131
from crate.operator.utils.crd import has_compute_changed
3232

3333

@@ -225,11 +225,10 @@ def configure(self, url: str, username: str, password: str) -> None:
225225
:param password: All requests will include HTTP Basic Auth credentials.
226226
This is the password for that.
227227
"""
228-
version = get_distribution("crate-operator").version
229228
self._url = url
230229
self._session = aiohttp.ClientSession(
231230
headers={
232-
"User-Agent": f"cratedb-operator/{version}",
231+
"User-Agent": f"cratedb-operator/{__version__}",
233232
"Content-Type": "application/json",
234233
},
235234
auth=aiohttp.BasicAuth(username, password),

setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ def read(path: str) -> str:
5151
install_requires=[
5252
"aiopg==1.4.0",
5353
"bitmath==1.3.3.1",
54+
"importlib-metadata; python_version<'3.8'",
5455
"kopf==1.36.2",
5556
"kubernetes-asyncio==31.1.0",
5657
"PyYAML<7.0",
5758
"prometheus_client==0.21.1",
5859
"aiohttp==3.11.11",
60+
"verlib2==0.3.1",
5961
"wrapt==1.17.0",
6062
"python-json-logger==3.2.1",
6163
],

tests/test_change_compute.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ async def test_generate_body_patch(
362362
affinity = body["spec"]["template"]["spec"]["affinity"]
363363
tolerations = body["spec"]["template"]["spec"]["tolerations"]
364364
if new_cpu_request or new_memory_request:
365-
assert type(affinity.node_affinity) == V1NodeAffinity
365+
assert type(affinity.node_affinity) is V1NodeAffinity
366366
assert affinity.pod_anti_affinity == {"$patch": "delete"}
367367
assert len(tolerations) == 1
368368
assert tolerations[0].to_dict() == {
@@ -373,7 +373,7 @@ async def test_generate_body_patch(
373373
"value": "shared",
374374
}
375375
else:
376-
assert type(affinity.pod_anti_affinity) == V1PodAntiAffinity
376+
assert type(affinity.pod_anti_affinity) is V1PodAntiAffinity
377377
assert affinity.node_affinity == {"$patch": "delete"}
378378
assert len(tolerations) == 1
379379
assert tolerations[0].to_dict() == {

0 commit comments

Comments
 (0)