From 0d5e1a7b5c686edffbb7d2a06e447fcbb4a7ea64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20de=20Saint=20Martin?= Date: Thu, 25 Jul 2024 11:14:41 +0200 Subject: [PATCH] chore!: upgrade requirements, test for python 3.12 --- .github/workflows/python-test.yml | 4 +- CHANGELOG.md | 6 ++ example/Dockerfile | 2 +- example/Dockerfile-dev | 2 +- example/alembic/env.py | 2 +- requirements.txt | 70 ++++++++----------- setup.cfg | 4 +- setup.py | 2 +- src/chartreuse/chartreuse.py | 2 +- src/chartreuse/chartreuse_upgrade.py | 5 +- src/chartreuse/tests/conftest.py | 5 +- src/chartreuse/tests/e2e_tests/conftest.py | 2 +- .../unit_tests/test_chartreuse_upgrade.py | 4 +- .../utils/alembic_migration_helper.py | 9 ++- 14 files changed, 56 insertions(+), 63 deletions(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 5ed823a..f824e03 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.7, 3.8, 3.9, 3.10.10, 3.11] + python-version: [3.11, 3.12] steps: - uses: actions/checkout@v2 @@ -44,7 +44,7 @@ jobs: - name: Check syntax with pyupgrade run: | - find . -type f -regex '.*\.py$' -exec pyupgrade --py37-plus {} \; + find . -type f -regex '.*\.py$' -exec pyupgrade --py311-plus {} \; - name: Set up Helm uses: azure/setup-helm@v1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 816f3f7..01eab31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v5.0.0 (2024-07-25) +### BREAKING CHANGE +- Change minimum supported version of python: 3.11 (drop 3.7, 3.8, 3.9, 3.10) +### Chore +- chore(ci): upgrade requirements, test for python 3.12 + ## v4.3.5 (2024-05-01) ### Chore - tests: e2e: apply expecteddeploymentscales CRD from wiremind helm chart repository diff --git a/example/Dockerfile b/example/Dockerfile index 4339b50..a36d06c 100644 --- a/example/Dockerfile +++ b/example/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9 +FROM python:3.12 WORKDIR /app diff --git a/example/Dockerfile-dev b/example/Dockerfile-dev index 2e1407d..efe32f5 100644 --- a/example/Dockerfile-dev +++ b/example/Dockerfile-dev @@ -1,6 +1,6 @@ # Only used for e2e tests. Do not use in production. -FROM python:3.9 +FROM python:3.12 WORKDIR /app diff --git a/example/alembic/env.py b/example/alembic/env.py index 835fd83..494647a 100644 --- a/example/alembic/env.py +++ b/example/alembic/env.py @@ -57,7 +57,7 @@ def run_migrations_online() -> None: """ patroni_postgresql: bool = "patroni_postgresql" in context.get_x_argument(as_dictionary=True) connectable = engine_from_config( - config.get_section(config.config_ini_section), + config.get_section(config.config_ini_section), # type: ignore prefix="sqlalchemy.", poolclass=pool.NullPool, ) diff --git a/requirements.txt b/requirements.txt index a44e9c8..cdbad3f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,76 +1,68 @@ # -# This file is autogenerated by pip-compile with python 3.8 -# To update, run: +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: # -# pip-compile --no-emit-index-url +# pip-compile --no-emit-index-url --output-file=requirements.txt pyproject.toml # -alembic==1.8.1 - # via chartreuse (setup.py) -cachetools==5.2.0 +alembic==1.13.2 + # via chartreuse (pyproject.toml) +cachetools==5.4.0 # via google-auth certifi==2024.7.4 # via # kubernetes # requests -charset-normalizer==2.1.1 +charset-normalizer==3.3.2 # via requests -google-auth==2.14.1 +google-auth==2.32.0 # via kubernetes -greenlet==2.0.1 - # via sqlalchemy idna==3.7 # via requests -importlib-metadata==5.0.0 - # via alembic -importlib-resources==5.10.0 - # via alembic -kubernetes==25.3.0 +kubernetes==30.1.0 # via wiremind-kubernetes -mako==1.2.4 +mako==1.3.5 # via alembic -markupsafe==2.1.1 +markupsafe==2.1.5 # via mako oauthlib==3.2.2 - # via requests-oauthlib -psycopg2==2.9.5 - # via chartreuse (setup.py) -pyasn1==0.4.8 + # via + # kubernetes + # requests-oauthlib +psycopg2==2.9.9 + # via chartreuse (pyproject.toml) +pyasn1==0.6.0 # via # pyasn1-modules # rsa -pyasn1-modules==0.2.8 +pyasn1-modules==0.4.0 # via google-auth -python-dateutil==2.8.2 +python-dateutil==2.9.0.post0 # via kubernetes -pyyaml==6.0 +pyyaml==6.0.1 # via kubernetes -requests==2.31.0 +requests==2.32.3 # via # kubernetes # requests-oauthlib -requests-oauthlib==1.3.1 +requests-oauthlib==2.0.0 # via kubernetes rsa==4.9 # via google-auth six==1.16.0 # via - # google-auth # kubernetes # python-dateutil -sqlalchemy==1.4.44 +sqlalchemy==2.0.31 # via alembic -urllib3==1.26.19 +typing-extensions==4.12.2 + # via + # alembic + # sqlalchemy +urllib3==2.2.2 # via # kubernetes # requests -websocket-client==1.4.2 +websocket-client==1.8.0 # via kubernetes -wiremind-kubernetes==7.0.0 - # via chartreuse (setup.py) -zipp==3.10.0 - # via - # importlib-metadata - # importlib-resources - -# The following packages are considered to be unsafe in a requirements file: -# setuptools +wiremind-kubernetes==7.4.5 + # via chartreuse (pyproject.toml) diff --git a/setup.cfg b/setup.cfg index b78b1c7..fcd8c6a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [options] -python_requires = >= 3.7 +python_requires = >= 3.11 [flake8] max-line-length = 120 @@ -13,7 +13,7 @@ ignore = W503, E203, E231, E501 jobs = 4 [mypy] -python_version = 3.7 +python_version = 3.11 ignore_missing_imports = True check_untyped_defs = True disallow_untyped_defs = True diff --git a/setup.py b/setup.py index d8b92d4..d5fcc09 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ package_dir={"": "src"}, include_package_data=True, zip_safe=True, - python_requires=">=3.7.0", + python_requires=">=3.11.0", install_requires=[ "alembic", "psycopg2", diff --git a/src/chartreuse/chartreuse.py b/src/chartreuse/chartreuse.py index 4e9524d..d3f6621 100644 --- a/src/chartreuse/chartreuse.py +++ b/src/chartreuse/chartreuse.py @@ -22,7 +22,7 @@ def __init__( release_name: str, alembic_allow_migration_for_empty_database: bool, alembic_additional_parameters: str = "", - kubernetes_helper: wiremind_kubernetes.kubernetes_helper.KubernetesDeploymentManager = None, + kubernetes_helper: wiremind_kubernetes.kubernetes_helper.KubernetesDeploymentManager | None = None, ): configure_logging() diff --git a/src/chartreuse/chartreuse_upgrade.py b/src/chartreuse/chartreuse_upgrade.py index ec3c9a6..2c132f1 100755 --- a/src/chartreuse/chartreuse_upgrade.py +++ b/src/chartreuse/chartreuse_upgrade.py @@ -1,6 +1,5 @@ import logging import os -from typing import List from wiremind_kubernetes import KubernetesDeploymentManager @@ -18,7 +17,7 @@ def ensure_safe_run() -> None: """ package_v: str = get_version() # Get "1.2" from "1.2.3" - package_v_major_minor: List[str] = package_v.split(".", 2)[:2] + package_v_major_minor: list[str] = package_v.split(".", 2)[:2] helm_chart_v: str = os.getenv("HELM_CHART_VERSION", "") if not helm_chart_v: @@ -26,7 +25,7 @@ def ensure_safe_run() -> None: "Couldn't get the Chartreuse's Helm Chart version from the env var HELM_CHART_VERSION," " couldn't make sure that the package is of a compatible version, ABORTING!" ) - helm_chart_v_major_minor: List[str] = helm_chart_v.split(".", 2)[:2] + helm_chart_v_major_minor: list[str] = helm_chart_v.split(".", 2)[:2] if helm_chart_v_major_minor != package_v_major_minor: raise ValueError( f"Chartreuse's Helm Chart version '{helm_chart_v}' and the package's version '{package_v}' " diff --git a/src/chartreuse/tests/conftest.py b/src/chartreuse/tests/conftest.py index 6324643..813c099 100644 --- a/src/chartreuse/tests/conftest.py +++ b/src/chartreuse/tests/conftest.py @@ -1,13 +1,12 @@ import os -from typing import Dict, Union from pytest_mock.plugin import MockerFixture def configure_os_environ_mock( - mocker: MockerFixture, additional_environment: Union[Dict[str, str], None] = None + mocker: MockerFixture, additional_environment: dict[str, str] | None = None ) -> None: - new_environ: Dict[str, str] = dict( + new_environ: dict[str, str] = dict( CHARTREUSE_ALEMBIC_ADDITIONAL_PARAMETERS="", CHARTREUSE_ALEMBIC_ALLOW_MIGRATION_FOR_EMPTY_DATABASE="1", CHARTREUSE_ALEMBIC_URL="foo", diff --git a/src/chartreuse/tests/e2e_tests/conftest.py b/src/chartreuse/tests/e2e_tests/conftest.py index 4aeb600..c330701 100644 --- a/src/chartreuse/tests/e2e_tests/conftest.py +++ b/src/chartreuse/tests/e2e_tests/conftest.py @@ -2,7 +2,7 @@ import os import subprocess import time -from typing import Generator +from collections.abc import Generator import pytest import sqlalchemy diff --git a/src/chartreuse/tests/unit_tests/test_chartreuse_upgrade.py b/src/chartreuse/tests/unit_tests/test_chartreuse_upgrade.py index a4cd080..54b8d8d 100644 --- a/src/chartreuse/tests/unit_tests/test_chartreuse_upgrade.py +++ b/src/chartreuse/tests/unit_tests/test_chartreuse_upgrade.py @@ -1,5 +1,3 @@ -from typing import Optional - import pytest from pytest_mock.plugin import MockerFixture @@ -74,7 +72,7 @@ def test_chartreuse_upgrade_no_migration_disabled_stop_pods(mocker: MockerFixtur ], ) def test_chartreuse_upgrade_compatibility_check( - mocker: MockerFixture, helm_chart_version: Optional[str], package_version: str, should_raise: bool + mocker: MockerFixture, helm_chart_version: str | None, package_version: str, should_raise: bool ) -> None: """ Test that chartreuse_upgrade deals as expected with compatibility with the package version and the diff --git a/src/chartreuse/utils/alembic_migration_helper.py b/src/chartreuse/utils/alembic_migration_helper.py index ecdb121..fdb8eed 100755 --- a/src/chartreuse/utils/alembic_migration_helper.py +++ b/src/chartreuse/utils/alembic_migration_helper.py @@ -3,7 +3,6 @@ import re from subprocess import SubprocessError from time import sleep, time -from typing import List import sqlalchemy from sqlalchemy import inspect, text @@ -45,13 +44,13 @@ def __init__( self.is_migration_needed = self._check_migration_needed() def _configure(self) -> None: - with open("%s/%s" % (self.alembic_directory_path, self.alembic_config_file_path), "r") as f: + with open(f"{self.alembic_directory_path}/{self.alembic_config_file_path}") as f: content = f.read() content_new = re.sub( "(sqlalchemy.url.*=.*){1}", r"sqlalchemy.url=%s" % self.database_url, content, flags=re.M ) if content != content_new: - with open("%s/%s" % (self.alembic_directory_path, self.alembic_config_file_path), "w") as f: + with open(f"{self.alembic_directory_path}/{self.alembic_config_file_path}", "w") as f: f.write(content_new) logger.info("alembic.ini was configured.") else: @@ -66,7 +65,7 @@ def _wait_postgres_is_configured(self) -> None: wait_timeout = int(os.getenv("CHARTREUSE_ALEMBIC_POSTGRES_WAIT_CONFIGURED_TIMEOUT", 60)) engine = sqlalchemy.create_engine(self.database_url, poolclass=NullPool, connect_args={"connect_timeout": 1}) - default_privileges_checks: List[str] = [ + default_privileges_checks: list[str] = [ "SET ROLE wiremind_owner", # The real owner, alembic will switch to it before running migrations. "CREATE TABLE _chartreuse_test_default_privileges(id serial)", "SET ROLE wiremind_writer_user", @@ -103,7 +102,7 @@ def _wait_postgres_is_configured(self) -> None: f" Postgres database. Check the Postgres logs and then postgres-operator for anything fishy." ) - def _get_table_list(self) -> List[str]: + def _get_table_list(self) -> list[str]: return inspect(sqlalchemy.create_engine(self.database_url)).get_table_names() def is_postgres_empty(self) -> bool: