Skip to content

Maintenance: Add support for Python 3.12 #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
python-version: [
"3.10",
"3.11",
"3.12",
]
steps:
- name: Checkout
Expand Down Expand Up @@ -54,6 +55,7 @@ jobs:
python-version: [
"3.10",
"3.11",
"3.12",
]
steps:
- name: Checkout
Expand All @@ -79,6 +81,7 @@ jobs:
python-version: [
"3.10",
"3.11",
"3.12",
]
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: "3.8.4"
rev: "7.1.1"
hooks:
- id: flake8
- repo: https://github.com/timothycrosley/isort
Expand Down
18 changes: 13 additions & 5 deletions crate/operator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@
# However, if you have executed another commercial license agreement
# with Crate these terms will supersede the license and you may use the
# software solely pursuant to the terms of the relevant commercial agreement.
from pkg_resources import DistributionNotFound, get_distribution

try:
__version__ = get_distribution("crate-operator").version
except DistributionNotFound:
# package is not installed
pass
from importlib.metadata import PackageNotFoundError, version
except (ImportError, ModuleNotFoundError): # pragma:nocover
from importlib_metadata import ( # type: ignore[assignment,no-redef,unused-ignore]
PackageNotFoundError,
version,
)

__appname__ = "crate-operator"

try:
__version__ = version(__appname__)
except PackageNotFoundError: # pragma: no cover
__version__ = "unknown"
12 changes: 6 additions & 6 deletions crate/operator/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,12 @@ async def restart_cluster(
if next_pod_uid in all_pod_uids:
# The next to-be-terminated pod still appears to be running.
logger.info("Terminating pod '%s'", next_pod_name)
node_index = int(next_pod_name[next_pod_name.rindex("-") + 1 :])
node_progress = f"{node_index + 1}/{len(all_pod_uids)}"
await send_operation_progress_notification(
namespace=namespace,
name=name,
message="Waiting for node "
f"{int(next_pod_name[next_pod_name.rindex('-')+1:])+1}/{len(all_pod_uids)}"
" to be terminated...",
message=f"Waiting for node {node_progress} to be terminated.",
logger=logger,
status=WebhookStatus.IN_PROGRESS,
operation=WebhookOperation.UPDATE,
Expand All @@ -527,12 +527,12 @@ async def restart_cluster(
elif next_pod_name in all_pod_names:
total_nodes = get_total_nodes_count(old["spec"]["nodes"], "all")
# The new pod has been spawned. Only a matter of time until it's ready.
node_index = int(next_pod_name[next_pod_name.rindex("-") + 1 :])
node_progress = f"{node_index + 1}/{len(all_pod_uids)}"
await send_operation_progress_notification(
namespace=namespace,
name=name,
message="Waiting for node "
f"{int(next_pod_name[next_pod_name.rindex('-')+1:])+1}/{len(all_pod_uids)}"
" to be restarted...",
message=f"Waiting for node {node_progress} to be restarted.",
Comment on lines +530 to +535
Copy link
Member Author

@amotl amotl Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This update is just because of line length limitations, now raised by the flake8 linter, after updating it.

Cutting the statements in the middle of the string interpolation feels nasty, so we did it this way, separating the statements from each other.

logger=logger,
status=WebhookStatus.IN_PROGRESS,
operation=WebhookOperation.UPDATE,
Expand Down
3 changes: 2 additions & 1 deletion crate/operator/utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
# software solely pursuant to the terms of the relevant commercial agreement.

import re
from distutils.version import Version
from typing import Optional, Tuple, Union, cast

from verlib2.distutils.version import Version


class CrateVersion(Version):
"""Version numbering for CrateDB releases.
Expand Down
5 changes: 2 additions & 3 deletions crate/operator/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import aiohttp
import kopf
from aiohttp import TCPConnector
from pkg_resources import get_distribution

from crate.operator import __version__
from crate.operator.utils.crd import has_compute_changed


Expand Down Expand Up @@ -225,11 +225,10 @@ def configure(self, url: str, username: str, password: str) -> None:
:param password: All requests will include HTTP Basic Auth credentials.
This is the password for that.
"""
version = get_distribution("crate-operator").version
self._url = url
self._session = aiohttp.ClientSession(
headers={
"User-Agent": f"cratedb-operator/{version}",
"User-Agent": f"cratedb-operator/{__version__}",
"Content-Type": "application/json",
},
auth=aiohttp.BasicAuth(username, password),
Expand Down
5 changes: 3 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
from typing import List

from pkg_resources import get_distribution
from crate.operator import __version__

# Configuration file for the Sphinx documentation builder.
#
Expand All @@ -26,7 +26,7 @@
copyright = "2020, Crate.io"
author = "Crate.io"

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


# -- General configuration ---------------------------------------------------
Expand Down Expand Up @@ -55,6 +55,7 @@
# undoc'd; https://docs.python.org/3/distutils/apiref.html#module-distutils.version
("py:class", "distutils.version.Version"),
("py:class", "prometheus_client.registry.Collector"),
("py:class", "verlib2.distutils.version.Version"),
]


Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ def read(path: str) -> str:
install_requires=[
"aiopg==1.4.0",
"bitmath==1.3.3.1",
"importlib-metadata; python_version<'3.8'",
"kopf==1.36.2",
"kubernetes-asyncio==31.1.0",
"PyYAML<7.0",
"prometheus_client==0.21.1",
"aiohttp==3.11.16",
"verlib2==0.3.1",
"wrapt==1.17.2",
"python-json-logger==3.3.0",
],
Expand All @@ -80,13 +82,14 @@ def read(path: str) -> str:
"mypy==1.13.0",
],
},
python_requires=">=3.10,<3.12",
python_requires=">=3.10,<3.13",
classifiers=[
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
use_scm_version=True,
)
4 changes: 2 additions & 2 deletions tests/test_change_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ async def test_generate_body_patch(
affinity = body["spec"]["template"]["spec"]["affinity"]
tolerations = body["spec"]["template"]["spec"]["tolerations"]
if new_cpu_request or new_memory_request:
assert type(affinity.node_affinity) == V1NodeAffinity
assert type(affinity.node_affinity) is V1NodeAffinity
assert affinity.pod_anti_affinity == {"$patch": "delete"}
assert len(tolerations) == 1
assert tolerations[0].to_dict() == {
Expand All @@ -373,7 +373,7 @@ async def test_generate_body_patch(
"value": "shared",
}
else:
assert type(affinity.pod_anti_affinity) == V1PodAntiAffinity
assert type(affinity.pod_anti_affinity) is V1PodAntiAffinity
assert affinity.node_affinity == {"$patch": "delete"}
assert len(tolerations) == 1
assert tolerations[0].to_dict() == {
Expand Down