Skip to content
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

Drop old python versiosn, upgrade requirements, test for python 3.12. #37

Merged
merged 1 commit into from
Jul 25, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9
FROM python:3.12

WORKDIR /app

Expand Down
2 changes: 1 addition & 1 deletion example/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Only used for e2e tests. Do not use in production.

FROM python:3.9
FROM python:3.12

WORKDIR /app

Expand Down
2 changes: 1 addition & 1 deletion example/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
70 changes: 31 additions & 39 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[options]
python_requires = >= 3.7
python_requires = >= 3.11

[flake8]
max-line-length = 120
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/chartreuse/chartreuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
5 changes: 2 additions & 3 deletions src/chartreuse/chartreuse_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import os
from typing import List

from wiremind_kubernetes import KubernetesDeploymentManager

Expand All @@ -18,15 +17,15 @@ 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:
raise ValueError(
"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}' "
Expand Down
5 changes: 2 additions & 3 deletions src/chartreuse/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/chartreuse/tests/e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import subprocess
import time
from typing import Generator
from collections.abc import Generator

import pytest
import sqlalchemy
Expand Down
4 changes: 1 addition & 3 deletions src/chartreuse/tests/unit_tests/test_chartreuse_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

import pytest
from pytest_mock.plugin import MockerFixture

Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/chartreuse/utils/alembic_migration_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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",
Expand Down Expand Up @@ -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:
Expand Down
Loading