diff --git a/.github/workflows/bkpaas-auth.yml b/.github/workflows/bkpaas-auth.yml index 953768d1..ca96cc99 100644 --- a/.github/workflows/bkpaas-auth.yml +++ b/.github/workflows/bkpaas-auth.yml @@ -38,7 +38,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.10", "3.11", "3.12"] os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: diff --git a/sdks/bkpaas-auth/CHANGES.md b/sdks/bkpaas-auth/CHANGES.md index 3ad266bf..5be17533 100644 --- a/sdks/bkpaas-auth/CHANGES.md +++ b/sdks/bkpaas-auth/CHANGES.md @@ -1,5 +1,9 @@ # 版本历史 +## 3.2.0 + +- 增加对 Django 5.x 版本的支持,并移除对 Python 3.9 版本的支持 + ## 3.1.3 - feat: 用户模型增加时区支持,新增 time_zone 属性,由认证服务返回时区 diff --git a/sdks/bkpaas-auth/noxfile.py b/sdks/bkpaas-auth/noxfile.py index f2eb6b29..ae8be97b 100644 --- a/sdks/bkpaas-auth/noxfile.py +++ b/sdks/bkpaas-auth/noxfile.py @@ -2,8 +2,9 @@ import tempfile import nox +from nox.command import CommandFailed -ALL_PYTHON = ["3.9", "3.10", "3.11"] +ALL_PYTHON = ["3.10", "3.11", "3.12"] # ref: https://stackoverflow.com/questions/59768651/how-to-use-nox-with-poetry @@ -49,8 +50,20 @@ def tests(session): install_with_constraints( session, "pytest", - "django", "pytest-django", "pytest-mock", ) - session.run("pytest", *session.posargs) + # Install the SQLite driver manually because some environment's sqlite3 version is too old + # to meet the Django requirement. + try: + session.install("pysqlite3-binary") + except CommandFailed: + print("pysqlite3-binary installation failed, continuing...") + + django_versions = [ + ">=4.2,<5", + ">=5.0,<6", + ] + for django in django_versions: + session.install(f"django{django}") + session.run("pytest", *session.posargs) diff --git a/sdks/bkpaas-auth/poetry.lock b/sdks/bkpaas-auth/poetry.lock index 66f95a9c..9a4b8e38 100644 --- a/sdks/bkpaas-auth/poetry.lock +++ b/sdks/bkpaas-auth/poetry.lock @@ -473,7 +473,7 @@ description = "A lil' TOML parser" optional = false python-versions = ">=3.8" groups = ["dev"] -markers = "python_version < \"3.11\"" +markers = "python_version == \"3.10\"" files = [ {file = "tomli-2.0.2-py3-none-any.whl", hash = "sha256:2ebe24485c53d303f690b0ec092806a085f07af5a5aa1464f3931eec36caaa38"}, {file = "tomli-2.0.2.tar.gz", hash = "sha256:d46d457a85337051c36524bc5349dd91b1877838e2979ac5ced3e710ed8a60ed"}, @@ -529,7 +529,7 @@ files = [ {file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"}, {file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"}, ] -markers = {main = "python_version < \"3.11\""} +markers = {main = "python_version == \"3.10\""} [[package]] name = "tzdata" @@ -564,5 +564,5 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.1" -python-versions = ">=3.9,<4.0" -content-hash = "3948203918bf7df59647d0248a41f3f4c0a99008b4ce9e5a0c36312ea57be1d7" +python-versions = ">=3.10,<4.0" +content-hash = "ef8cca81c2659cb2f3092504412e540f184b7bfa0531e8b616f03c0749cea6b6" diff --git a/sdks/bkpaas-auth/pyproject.toml b/sdks/bkpaas-auth/pyproject.toml index d6a33a58..cdebdce2 100644 --- a/sdks/bkpaas-auth/pyproject.toml +++ b/sdks/bkpaas-auth/pyproject.toml @@ -5,15 +5,15 @@ classifiers = ["License :: OSI Approved :: MIT License"] # PEP 621 project metadata # See https://www.python.org/dev/peps/pep-0621/ name = "bkpaas-auth" -version = "3.1.3" +version = "3.2.0" description = "User authentication django app for blueking internal projects" readme = "README.md" authors = [{ name = "blueking", email = "blueking@tencent.com" }] license = "MIT" # classifiers is dynamic because we want to create Python classifiers automatically dynamic = ["classifiers"] -requires-python = '>=3.9,<4.0' -dependencies = ['django (>=4.2,<5.0)', 'requests', 'six'] +requires-python = '>=3.10,<4.0' +dependencies = ['django (>=4.2,<6.0)', 'requests', 'six'] [project.urls] Homepage = "https://github.com/TencentBlueKing/bkpaas-python-sdk/" diff --git a/sdks/bkpaas-auth/tests/conftest.py b/sdks/bkpaas-auth/tests/conftest.py index adc233f6..c0d1d833 100644 --- a/sdks/bkpaas-auth/tests/conftest.py +++ b/sdks/bkpaas-auth/tests/conftest.py @@ -1,10 +1,30 @@ # -*- coding: utf-8 -*- import logging +import sqlite3 import sys import pytest +def _ensure_sqlite_min_version() -> None: + """Ensure that the sqlite3 module meets the minimum version requirement.""" + minimum_version = (3, 31, 0) + if sqlite3.sqlite_version_info >= minimum_version: + return + + try: + import pysqlite3 + except ImportError: + return + + # Replace sqlite3 module so Django picks up the newer SQLite implementation. + sys.modules["sqlite3"] = pysqlite3 + sys.modules["sqlite3.dbapi2"] = pysqlite3.dbapi2 + + +_ensure_sqlite_min_version() + + def setup_root_logger(level): """Set up the root logger, make it to write messages to stdout""" root = logging.getLogger() @@ -12,7 +32,7 @@ def setup_root_logger(level): handler = logging.StreamHandler(sys.stdout) handler.setLevel(level) - formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") handler.setFormatter(formatter) root.addHandler(handler) @@ -23,36 +43,36 @@ def pytest_configure(): settings.configure( DEBUG_PROPAGATE_EXCEPTIONS=True, DATABASES={ - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': ':memory:', + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": ":memory:", } }, - SECRET_KEY='not very secret in tests', + SECRET_KEY="not very secret in tests", TEMPLATES=[ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'APP_DIRS': True, + "BACKEND": "django.template.backends.django.DjangoTemplates", + "APP_DIRS": True, }, ], USE_TZ=True, - TIME_ZONE='Asia/Shanghai', + TIME_ZONE="Asia/Shanghai", MIDDLEWARE=[], MIDDLEWARE_CLASSES=[], INSTALLED_APPS=( - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'tests', + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "tests", ), # bkauth settings - BKAUTH_BACKEND_TYPE='bk_token', - BKAUTH_TOKEN_APP_CODE='mock_app_code', - BKAUTH_TOKEN_SECRET_KEY='mock_app_key', - BKAUTH_TOKEN_GRANT_ENDPOINT='', - USER_ID='0221dbef87cd', - USER_NAME='user1', - USER_NICKNAME='user1中文名', + BKAUTH_BACKEND_TYPE="bk_token", + BKAUTH_TOKEN_APP_CODE="mock_app_code", + BKAUTH_TOKEN_SECRET_KEY="mock_app_key", + BKAUTH_TOKEN_GRANT_ENDPOINT="", + USER_ID="0221dbef87cd", + USER_NAME="user1", + USER_NICKNAME="user1中文名", AUTHENTICATION_BACKENDS=["bkpaas_auth.backends.UniversalAuthBackend"], )