Skip to content

Commit b46f806

Browse files
committed
Maintenance: Add support for Python 3.12
1 parent fbafbeb commit b46f806

File tree

9 files changed

+36
-21
lines changed

9 files changed

+36
-21
lines changed

.github/workflows/main.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
python-version: [
2020
"3.10",
2121
"3.11",
22+
"3.12",
2223
]
2324
steps:
2425
- name: Checkout
@@ -54,6 +55,7 @@ jobs:
5455
python-version: [
5556
"3.10",
5657
"3.11",
58+
"3.12",
5759
]
5860
steps:
5961
- name: Checkout
@@ -79,6 +81,7 @@ jobs:
7981
python-version: [
8082
"3.10",
8183
"3.11",
84+
"3.12",
8285
]
8386
steps:
8487
- name: Checkout

.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),

docs/source/conf.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
from typing import List
88

9-
from pkg_resources import get_distribution
9+
from crate.operator import __version__
1010

1111
# Configuration file for the Sphinx documentation builder.
1212
#
@@ -26,7 +26,7 @@
2626
copyright = "2020, Crate.io"
2727
author = "Crate.io"
2828

29-
version = release = get_distribution("crate-operator").version
29+
version = release = __version__
3030

3131

3232
# -- General configuration ---------------------------------------------------
@@ -55,6 +55,7 @@
5555
# undoc'd; https://docs.python.org/3/distutils/apiref.html#module-distutils.version
5656
("py:class", "distutils.version.Version"),
5757
("py:class", "prometheus_client.registry.Collector"),
58+
("py:class", "verlib2.distutils.version.Version"),
5859
]
5960

6061

setup.py

+4-1
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
],
@@ -80,7 +82,7 @@ def read(path: str) -> str:
8082
"mypy==1.13.0",
8183
],
8284
},
83-
python_requires=">=3.10,<3.12",
85+
python_requires=">=3.10,<3.13",
8486
classifiers=[
8587
"Development Status :: 5 - Production/Stable",
8688
"License :: OSI Approved :: Apache Software License",
@@ -89,6 +91,7 @@ def read(path: str) -> str:
8991
"Programming Language :: Python :: 3.9",
9092
"Programming Language :: Python :: 3.10",
9193
"Programming Language :: Python :: 3.11",
94+
"Programming Language :: Python :: 3.12",
9295
],
9396
use_scm_version=True,
9497
)

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)