Skip to content

Commit

Permalink
Merge pull request #708 from SUNET/ylle_update_python_version
Browse files Browse the repository at this point in the history
Update_python_version to 3.11
  • Loading branch information
johanlundberg authored Oct 10, 2024
2 parents 41e5872 + 8dec8a3 commit 2ed2ea8
Show file tree
Hide file tree
Showing 110 changed files with 272 additions and 316 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/devcontainers/python:0-3.10
FROM mcr.microsoft.com/devcontainers/python:0-3.11

ARG NONROOT_USER=vscode

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
python-version: ["3.11"]
env:
PIP_INDEX_URL: https://pypi.sunet.se/simple/
NEO4J_VERSION: 4.4-enterprise
Expand Down Expand Up @@ -52,10 +52,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: "Set up Python 3.10"
- name: "Set up Python 3.11"
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"

- name: Install dependencies
run: |
Expand All @@ -74,7 +74,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 2 additions & 2 deletions .jenkins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pre_build_script:
environment_variables:
NEO4J_VERSION: "4.4-enterprise"
script:
- "python3.10 -m venv venv"
- "python3.11 -m venv venv"
- ". venv/bin/activate"
- "pip install -U pip setuptools wheel mypy"
- "pip install --index-url https://pypi.sunet.se -r requirements/test_requirements.txt"
Expand All @@ -31,7 +31,7 @@ extra_jobs:
github_push: false
cron: "@daily"
script:
- "python3.10 -m venv venv"
- "python3.11 -m venv venv"
- ". venv/bin/activate"
- "pip install -U pip setuptools wheel pip-tools mypy"
- "touch requirements/*in"
Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Set the maximum line length to 120.
line-length = 120
target-version = "py310"
target-version = "py311"

[lint]
select = ["E", "F", "W", "I", "ASYNC", "UP", "FLY", "PERF", "FURB", "ERA", "ANN"]
Expand Down
6 changes: 3 additions & 3 deletions src/eduid/common/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from collections.abc import Iterable, Mapping, Sequence
from datetime import timedelta
from enum import Enum, unique
from enum import Enum, StrEnum, unique
from pathlib import Path
from re import Pattern
from typing import IO, Annotated, Any, TypeVar
Expand Down Expand Up @@ -69,7 +69,7 @@ class CookieConfig(BaseModel):
TRootConfigSubclass = TypeVar("TRootConfigSubclass", bound="RootConfig")


class EduidEnvironment(str, Enum):
class EduidEnvironment(StrEnum):
dev = "dev"
staging = "staging"
production = "production"
Expand All @@ -89,7 +89,7 @@ class RootConfig(BaseModel):
TEduIDBaseAppConfigSubclass = TypeVar("TEduIDBaseAppConfigSubclass", bound="EduIDBaseAppConfig")


class LoggingFilters(str, Enum):
class LoggingFilters(StrEnum):
"""Identifiers to coherently map elements in LocalContext.filters to filter classes in logging dictConfig."""

DEBUG_TRUE: str = "require_debug_true"
Expand Down
13 changes: 7 additions & 6 deletions src/eduid/common/fastapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from fastapi import Response

from eduid.common.fastapi.context_request import ContextRequest
from eduid.common.misc.timeutil import utc_now


@dataclass
Expand All @@ -36,7 +37,7 @@ def __str__(self) -> str:

def log_failure_info(req: ContextRequest, key: str, msg: str, exc: Exception | None = None) -> None:
if key not in FAILURE_INFO:
FAILURE_INFO[key] = FailCountItem(first_failure=datetime.utcnow())
FAILURE_INFO[key] = FailCountItem(first_failure=utc_now())
FAILURE_INFO[key].count += 1
req.app.context.logger.warning(f"{msg} {FAILURE_INFO[key]}: {exc}")

Expand All @@ -57,11 +58,11 @@ def check_restart(key: str, restart: int, terminate: int) -> bool:
info = replace(info, restart_at=info.first_failure + timedelta(seconds=restart))
if terminate and not info.exit_at:
info = replace(info, exit_at=info.first_failure + timedelta(seconds=terminate))
if info.exit_at and datetime.utcnow() >= info.exit_at:
if info.exit_at and utc_now() >= info.exit_at:
# Exit application and rely on something else restarting it
sys.exit(1)
if info.restart_at and datetime.utcnow() >= info.restart_at:
info = replace(info, restart_at=datetime.utcnow() + timedelta(seconds=restart))
if info.restart_at and utc_now() >= info.restart_at:
info = replace(info, restart_at=utc_now() + timedelta(seconds=restart))
# Try to restart/reinitialize the failing functionality
res = True
FAILURE_INFO[key] = info
Expand All @@ -72,7 +73,7 @@ def get_cached_response(req: ContextRequest, resp: Response, key: str) -> Mappin
cache_for_seconds = req.app.context.config.status_cache_seconds
resp.headers["Cache-Control"] = f"public,max-age={cache_for_seconds}"

now = datetime.utcnow()
now = utc_now()
if SIMPLE_CACHE.get(key) is not None and now < SIMPLE_CACHE[key].expire_time:
if req.app.context.config.debug:
req.app.context.logger.debug(f"Returned cached response for {key} {now} < {SIMPLE_CACHE[key].expire_time}")
Expand All @@ -83,7 +84,7 @@ def get_cached_response(req: ContextRequest, resp: Response, key: str) -> Mappin

def set_cached_response(req: ContextRequest, resp: Response, key: str, data: Mapping) -> None:
cache_for_seconds = req.app.context.config.status_cache_seconds
now = datetime.utcnow()
now = utc_now()
expires = now + timedelta(seconds=cache_for_seconds)
resp.headers["Expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S UTC")
SIMPLE_CACHE[key] = SimpleCacheItem(expire_time=expires, data=data)
Expand Down
4 changes: 2 additions & 2 deletions src/eduid/common/misc/timeutil.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime, timezone
from datetime import UTC, datetime


def utc_now() -> datetime:
"""Return current time with tz=UTC"""
return datetime.now(tz=timezone.utc)
return datetime.now(tz=UTC)
6 changes: 3 additions & 3 deletions src/eduid/common/models/amapi_user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from enum import Enum
from enum import StrEnum

from pydantic import BaseModel, Field

Expand All @@ -10,7 +10,7 @@
__author__ = "masv"


class Reason(str, Enum):
class Reason(StrEnum):
USER_DECEASED = "user_deceased"
USER_DEREGISTERED = "user_deregistered"
NAME_CHANGED = "name_changed"
Expand All @@ -19,7 +19,7 @@ class Reason(str, Enum):
TEST = "test"


class Source(str, Enum):
class Source(StrEnum):
SKV_NAVET_V2 = "swedish_tax_agency_navet_v2"
NO_SOURCE = "no_source"
TEST = "test"
Expand Down
4 changes: 2 additions & 2 deletions src/eduid/common/models/bearer_token.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from collections.abc import Mapping
from copy import copy
from enum import Enum
from enum import StrEnum
from typing import Any

from pydantic import BaseModel, Field, StrictInt, field_validator, model_validator
Expand All @@ -11,7 +11,7 @@
from eduid.userdb.scimapi.groupdb import ScimApiGroupDB


class AuthSource(str, Enum):
class AuthSource(StrEnum):
INTERACTION = "interaction"
CONFIG = "config"
MDQ = "mdq"
Expand Down
6 changes: 3 additions & 3 deletions src/eduid/common/models/gnap_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from enum import Enum
from enum import StrEnum
from typing import Any

from pydantic import AnyUrl, BaseModel, ConfigDict, Field, field_validator
Expand All @@ -21,7 +21,7 @@ class GnapBaseModel(BaseModel):
model_config = ConfigDict(populate_by_name=True)


class ProofMethod(str, Enum):
class ProofMethod(StrEnum):
DPOP = "dpop"
HTTPSIGN = "httpsign"
JWSD = "jwsd"
Expand Down Expand Up @@ -51,7 +51,7 @@ def expand_proof(cls, v: str | dict[str, Any]) -> dict[str, Any]:
return v


class AccessTokenFlags(str, Enum):
class AccessTokenFlags(StrEnum):
BEARER = "bearer"
DURABLE = "durable"

Expand Down
18 changes: 9 additions & 9 deletions src/eduid/common/models/jose_models.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import datetime
from enum import Enum
from enum import StrEnum
from typing import Any

from pydantic import AnyUrl, BaseModel, Field

__author__ = "lundberg"
from eduid.common.misc.timeutil import utc_now

from eduid.userdb.util import utc_now
__author__ = "lundberg"


class KeyType(str, Enum):
class KeyType(StrEnum):
EC = "EC"
RSA = "RSA"
OCT = "oct"


class KeyUse(str, Enum):
class KeyUse(StrEnum):
SIGN = "sig"
ENCRYPT = "enc"


class KeyOptions(str, Enum):
class KeyOptions(StrEnum):
SIGN = "sign"
VERIFY = "verify"
ENCRYPT = "encrypt"
Expand All @@ -31,13 +31,13 @@ class KeyOptions(str, Enum):
DERIVE_BITS = "deriveBits"


class SupportedAlgorithms(str, Enum):
class SupportedAlgorithms(StrEnum):
RS256 = "RS256"
ES256 = "ES256"
ES384 = "ES384"


class SupportedHTTPMethods(str, Enum):
class SupportedHTTPMethods(StrEnum):
POST = "POST"


Expand Down Expand Up @@ -84,7 +84,7 @@ class JWKS(BaseModel):
keys: list[ECJWK | RSAJWK | SymmetricJWK]


class SupportedJWSType(str, Enum):
class SupportedJWSType(StrEnum):
JWS = "gnap-binding+jws"
JWSD = "gnap-binding+jwsd"

Expand Down
4 changes: 2 additions & 2 deletions src/eduid/common/models/saml2.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from enum import Enum, unique
from enum import StrEnum, unique

__author__ = "lundberg"


@unique
class EduidAuthnContextClass(str, Enum):
class EduidAuthnContextClass(StrEnum):
DIGG_LOA2 = "http://id.elegnamnden.se/loa/1.0/loa2"
REFEDS_MFA = "https://refeds.org/profile/mfa"
REFEDS_SFA = "https://refeds.org/profile/sfa"
Expand Down
17 changes: 7 additions & 10 deletions src/eduid/common/models/scim_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime
from enum import Enum
from typing import Annotated, Any, TypeVar
from enum import StrEnum
from typing import Annotated, Any, Self
from uuid import UUID

from bson import ObjectId
Expand Down Expand Up @@ -57,7 +57,7 @@
ScimDatetime = Annotated[datetime, PlainSerializer(serialize_xml_datetime)]


class SCIMSchema(str, Enum):
class SCIMSchema(StrEnum):
CORE_20_USER = "urn:ietf:params:scim:schemas:core:2.0:User"
CORE_20_GROUP = "urn:ietf:params:scim:schemas:core:2.0:Group"
API_MESSAGES_20_SEARCH_REQUEST = "urn:ietf:params:scim:api:messages:2.0:SearchRequest"
Expand All @@ -72,20 +72,20 @@ class SCIMSchema(str, Enum):
DEBUG_V1 = "https://scim.eduid.se/schema/nutid-DEBUG/v1"


class SCIMResourceType(str, Enum):
class SCIMResourceType(StrEnum):
USER = "User"
GROUP = "Group"
INVITE = "Invite"
EVENT = "Event"


class EmailType(str, Enum):
class EmailType(StrEnum):
HOME = "home"
WORK = "work"
OTHER = "other"


class PhoneNumberType(str, Enum):
class PhoneNumberType(StrEnum):
HOME = "home"
WORK = "work"
OTHER = "other"
Expand All @@ -98,9 +98,6 @@ class EduidBaseModel(BaseModel):
model_config = ConfigDict(extra="forbid", frozen=True, populate_by_name=True)


TSubResource = TypeVar("TSubResource", bound="SubResource")


class SubResource(EduidBaseModel):
value: UUID
ref: str = Field(alias="$ref")
Expand All @@ -115,7 +112,7 @@ def is_group(self) -> bool:
return self.ref is not None and "/Groups/" in self.ref

@classmethod
def from_mapping(cls: type[TSubResource], data: object) -> TSubResource:
def from_mapping(cls, data: object) -> Self:
return cls.model_validate(data)


Expand Down
2 changes: 1 addition & 1 deletion src/eduid/common/models/scim_invite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Self
from uuid import UUID

from pydantic import Field, model_validator
from typing_extensions import Self

from eduid.common.models.scim_base import (
BaseCreateRequest,
Expand Down
6 changes: 3 additions & 3 deletions src/eduid/common/rpc/msg_relay.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from enum import Enum
from enum import StrEnum

from pydantic import BaseModel, ConfigDict, Field, ValidationError

Expand Down Expand Up @@ -70,7 +70,7 @@ class RelationId(NavetModelConfig):
birth_time_number: str | None = Field(default=None, alias="BirthTimeNumber")


class RelationType(str, Enum):
class RelationType(StrEnum):
CHILD = "B"
MOTHER = "MO"
FATHER = "FA"
Expand All @@ -94,7 +94,7 @@ class PostalAddresses(NavetModelConfig):
official_address: OfficialAddress = Field(alias="OfficialAddress")


class DeregisteredCauseCode(str, Enum):
class DeregisteredCauseCode(StrEnum):
DECEASED = "AV"
EMIGRATED = "UV"
OLD_NIN = "GN"
Expand Down
4 changes: 2 additions & 2 deletions src/eduid/common/rpc/tests/test_msg_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def setUp(self) -> None:
self.message_sender = MessageSender()

@staticmethod
def _fix_relations_to(relative_nin: str, relations: Mapping[str, Any]) -> list[dict[str, Any]]:
result: list[dict[str, Any]] = []
def _fix_relations_to(relative_nin: str, relations: Mapping[str, Any]) -> list[str]:
result: list[str] = []
for d in relations["Relations"]["Relation"]:
if d.get("RelationId", {}).get("NationalIdentityNumber") == relative_nin:
if "RelationType" in d:
Expand Down
Loading

0 comments on commit 2ed2ea8

Please sign in to comment.