diff --git a/.coveragerc b/.coveragerc index 5d18877..00d6b92 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,4 @@ [run] include = edc_sites/* omit = edc_sites/tests/*,edc_sites/migrations/* -branch = 1 \ No newline at end of file +branch = 1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 60620ab..950e9aa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,9 +12,10 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.12'] - django-version: ['4.2', '5.0', '5.1', 'dev'] + python-version: ['3.12', '3.13'] + django-version: ['5.1', 'dev'] database-engine: ["mysql", "postgres"] + services: mysql: image: mysql:latest @@ -68,7 +69,6 @@ jobs: python -m pip install --upgrade pip python -m pip install -r https://raw.githubusercontent.com/clinicedc/edc/develop/requirements.tests/tox.txt - - name: Tox tests run: | tox -v diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a32918b..bace820 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,20 +3,20 @@ exclude: tests/etc/user-* repos: - repo: https://github.com/PyCQA/bandit - rev: 1.7.7 + rev: 1.7.10 hooks: - id: bandit args: - "-x *test*.py" - repo: https://github.com/psf/black - rev: 24.2.0 + rev: 24.10.0 hooks: - id: black - language_version: python3.11 + language_version: python3.12 - repo: https://github.com/pycqa/flake8 - rev: 7.0.0 + rev: 7.1.1 hooks: - id: flake8 args: @@ -28,21 +28,24 @@ repos: - id: isort - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - - id: requirements-txt-fixer - files: requirements/.*\.txt$ - - id: trailing-whitespace - id: check-added-large-files - - id: fix-byte-order-marker - id: check-docstring-first - id: check-executables-have-shebangs - id: check-merge-conflict + - id: check-toml + - id: check-yaml - id: debug-statements - id: detect-private-key + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: requirements-txt-fixer + files: requirements/.*\.txt$ + - id: trailing-whitespace - repo: https://github.com/adrienverge/yamllint - rev: v1.34.0 + rev: v1.35.1 hooks: - id: yamllint args: diff --git a/AUTHORS b/AUTHORS index 3bc0afa..eb5e7d3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1 +1 @@ -Erik van Widenfelt \ No newline at end of file +Erik van Widenfelt diff --git a/CHANGES b/CHANGES index f2f7429..aae0dc1 100644 --- a/CHANGES +++ b/CHANGES @@ -5,4 +5,3 @@ - feature to limit to related site in FK and M2M - filter queryset by site - check for site attr - diff --git a/README.rst b/README.rst index 14b5256..01919bc 100644 --- a/README.rst +++ b/README.rst @@ -226,4 +226,3 @@ For example: .. _sites_framework: https://docs.djangoproject.com/en/dev/ref/contrib/sites/ __ sites_framework_ - diff --git a/edc_sites/modelform_mixins.py b/edc_sites/modelform_mixins.py index 6e296c3..92bab53 100644 --- a/edc_sites/modelform_mixins.py +++ b/edc_sites/modelform_mixins.py @@ -1,7 +1,12 @@ from __future__ import annotations +from typing import TYPE_CHECKING, Type + from django import forms -from django.contrib.sites.models import Site +from django.apps import apps as django_apps + +if TYPE_CHECKING: + from django.contrib.sites.models import Site __all__ = ["SiteModelFormMixin"] @@ -26,12 +31,18 @@ def clean(self) -> dict: self.validate_with_current_site() return cleaned_data + @property + def site_model_cls(self) -> Type[Site]: + return django_apps.get_model("sites.site") + @property def site(self) -> Site: if related_visit := getattr(self, "related_visit", None): return related_visit.site return ( - self.cleaned_data.get("site") or self.instance.site or Site.objects.get_current() + self.cleaned_data.get("site") + or self.instance.site + or self.site_model_cls.objects.get_current() ) def validate_with_current_site(self) -> None: diff --git a/pyproject.toml b/pyproject.toml index cd9712f..6a581d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,17 +1,18 @@ [build-system] requires = ["setuptools>=60", "setuptools-scm>=8.0"] +build-backend = "setuptools.build_meta" [tool.setuptools_scm] -version_file="_version.py" +version_file = "_version.py" [tool.black] line-length = 95 -target-version = ["py311"] +target-version = ["py312"] extend-exclude = '''^(.*\/)*\b(migrations)\b($|\/.*$)''' [tool.isort] profile = "black" -py_version = "311" +py_version = "312" skip = [".tox", ".eggs", "migrations"] [tool.coverage.run] @@ -35,35 +36,33 @@ exclude_lines = [ legacy_tox_ini = """ [tox] envlist = - py{311}-dj{42,50,dev}, - py{312}-dj{50}, + py{312,313}-dj{51,dev}, lint + pre-commit isolated_build = true [gh-actions] python = - 3.11: py311, lint - 3.12: py312 + 3.12: py312, lint, pre-commit + 3.13: py313 [gh-actions:env] DJANGO = - 4.2: dj42, lint - 5.0: dj50 - dev: djdev + 5.1: dj51 + dev: djdev, lint, pre-commit [testenv] deps = -r https://raw.githubusercontent.com/clinicedc/edc/develop/requirements.tests/tox.txt -r https://raw.githubusercontent.com/clinicedc/edc/develop/requirements.tests/test_utils.txt -r https://raw.githubusercontent.com/clinicedc/edc/develop/requirements.tests/edc.txt - -r https://raw.githubusercontent.com/clinicedc/edc/develop/requirements.tests/third_party_dev.txt - dj42: Django>=4.2,<5.0 - dj50: Django>=5.0 + dj51: Django>=5.1,<5.2 djdev: https://github.com/django/django/tarball/main commands = - pip install -U pip coverage[toml] + pip install -U pip + python --version pip --version pip freeze coverage run -a runtests.py @@ -72,7 +71,19 @@ commands = [testenv:lint] deps = -r https://raw.githubusercontent.com/clinicedc/edc/develop/requirements.tests/lint.txt commands = + python --version + pip --version + pip freeze isort --profile=black --check --diff . black --check --diff . flake8 . + +[testenv:pre-commit] +deps = pre-commit +commands = + python --version + pip --version + pip freeze + pre-commit autoupdate + pre-commit run --all-files """ diff --git a/setup.cfg b/setup.cfg index 66ae399..1517c3a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,16 +12,15 @@ keywords = django Edc sites, clinicedc, clinical trials classifiers= Environment :: Web Environment Framework :: Django - Framework :: Django :: 4.2 + Framework :: Django :: 5.1 Intended Audience :: Developers Intended Audience :: Science/Research Operating System :: OS Independent - Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 License :: OSI Approved :: GNU General Public License v3 (GPLv3) - [options] -python_requires = >=3.11 +python_requires = >=3.12 zip_safe = False include_package_data = True packages = find: