From b1100bcdb5a32d1b2062d5ecdaa9463a04a6782d Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Mon, 20 May 2024 12:46:43 +0200 Subject: [PATCH] build: add py3.12 support (#234) --- .github/workflows/checks.yml | 7 +++++-- docker/Dockerfile | 2 +- examples/petstore-access-control/README.md | 2 +- examples/petstore/README.md | 2 +- foca/models/config.py | 13 ++++++------- .../access_control/register_access_control.py | 7 ++++--- setup.py | 1 + tests/security/test_cors.py | 17 ++++++++--------- 8 files changed, 27 insertions(+), 24 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 28995a32..c2a15762 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -21,7 +21,8 @@ jobs: py-version-img: [ ["3.9", "3.9-slim-bookworm"], ["3.10", "3.10-slim-bookworm"], - ["3.11", "3.11-slim-bookworm"] + ["3.11", "3.11-slim-bookworm"], + ["3.12", "3.12-slim-bookworm"], ] mongodb-version: ["4.4", "5.0", "6.0", "7.0"] mongodb-port: [12345] @@ -35,6 +36,7 @@ jobs: - name: Install requirements run: | pip install -e .[dev] + pip install setuptools - name: Lint with flake8 run: flake8 - name: Run mypy @@ -83,7 +85,8 @@ jobs: py-version-img-tag: [ ["3.9", "3.9-slim-bookworm", ""], ["3.10", "3.10-slim-bookworm", ""], - ["3.11", "3.11-slim-bookworm", "latest"], + ["3.11", "3.11-slim-bookworm", ""], + ["3.12", "3.12-slim-bookworm", "latest"], ] steps: diff --git a/docker/Dockerfile b/docker/Dockerfile index efd0c69f..b7b235a6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -ARG PY_IMAGE=3.11-slim-bookworm +ARG PY_IMAGE=3.12-slim-bookworm FROM python:$PY_IMAGE as base # Metadata diff --git a/examples/petstore-access-control/README.md b/examples/petstore-access-control/README.md index 482759c4..750ce4e0 100644 --- a/examples/petstore-access-control/README.md +++ b/examples/petstore-access-control/README.md @@ -79,7 +79,7 @@ Some notes: > executing the build command. For example: > > ```bash -> export PETSTORE_PY_IMAGE=3.11-slim-bookworm +> export PETSTORE_PY_IMAGE=3.12-slim-bookworm > ``` > > * In case Docker complains about port conflicts or if any of the used ports diff --git a/examples/petstore/README.md b/examples/petstore/README.md index b64e7d8c..dfad12fc 100644 --- a/examples/petstore/README.md +++ b/examples/petstore/README.md @@ -77,7 +77,7 @@ Some notes: > executing the build command. For example: > > ```bash -> export PETSTORE_PY_IMAGE=3.11-slim-bookworm +> export PETSTORE_PY_IMAGE=3.12-slim-bookworm > ``` > > * In case Docker complains about port conflicts or if any of the used ports diff --git a/foca/models/config.py b/foca/models/config.py index f36bd95e..babe5fde 100644 --- a/foca/models/config.py +++ b/foca/models/config.py @@ -4,12 +4,11 @@ from enum import Enum from functools import reduce import importlib +from importlib.resources import path as resource_path import operator from pathlib import Path from typing import (Any, Dict, List, Optional, Union) -from pkg_resources import resource_filename - from pydantic import (BaseModel, Field, validator) # pylint: disable=E0611 import pymongo @@ -710,11 +709,11 @@ def validate_model_path(cls, v: Optional[Path]): # pylint: disable=E0213 if path is not provided. """ if v is None: - return str( - resource_filename( - ACCESS_CONTROL_BASE_PATH, DEFAULT_MODEL_FILE - ) - ) + with resource_path( + ACCESS_CONTROL_BASE_PATH, + DEFAULT_MODEL_FILE + ) as _path: + return str(_path) model_path = Path(v) if not model_path.is_absolute(): diff --git a/foca/security/access_control/register_access_control.py b/foca/security/access_control/register_access_control.py index 8bea8c9a..92494e07 100644 --- a/foca/security/access_control/register_access_control.py +++ b/foca/security/access_control/register_access_control.py @@ -2,7 +2,7 @@ import logging from functools import wraps -from pkg_resources import resource_filename +from importlib.resources import path as resource_path from pathlib import Path from typing import (Callable, Optional, Tuple) @@ -108,9 +108,10 @@ def register_permission_specs( """ # Check if default, get package path variables for specs. if access_control_config.api_specs is None: - spec_path = str(resource_filename( + with resource_path( ACCESS_CONTROL_BASE_PATH, DEFAULT_API_SPEC_PATH - )) + ) as _path: + spec_path = str(_path) else: spec_path = access_control_config.api_specs diff --git a/setup.py b/setup.py index d6f53f79..c29774bf 100644 --- a/setup.py +++ b/setup.py @@ -58,6 +58,7 @@ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Internet :: WWW/HTTP", "Topic :: System :: Systems Administration", "Topic :: Utilities", diff --git a/tests/security/test_cors.py b/tests/security/test_cors.py index 09779b56..376b120f 100644 --- a/tests/security/test_cors.py +++ b/tests/security/test_cors.py @@ -1,16 +1,15 @@ """Unit test for security.cors.py""" -from foca.security.cors import enable_cors -from flask import Flask +from unittest.mock import patch +from flask import Flask -from unittest.mock import patch +from foca.security.cors import enable_cors -@patch('flask_cors.CORS') -def test_enable_cors(test_patch): - """Test that CORS is called with app as a parameter - """ +def test_enable_cors(): + """Test that CORS is called with app as a parameter.""" app = Flask(__name__) - assert enable_cors(app) is None - assert test_patch.called_with(app) + with patch('foca.security.cors.CORS') as mock_cors: + enable_cors(app) + mock_cors.assert_called_once_with(app)