Skip to content

Commit

Permalink
Move compatibility check from Django template to system check #11114
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jul 15, 2024
1 parent 0a31f77 commit 7a4e1e3
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 90 deletions.
65 changes: 0 additions & 65 deletions arches/app/utils/compatibility.py

This file was deleted.

6 changes: 0 additions & 6 deletions arches/app/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from arches import __version__
from arches.app.models import models
from arches.app.models.system_settings import settings
from arches.app.models.resource import Resource
from arches.app.utils.betterJSONSerializer import JSONSerializer, JSONDeserializer
from arches.app.utils.compatibility import is_compatible_with_arches, CompatibilityError
from django.utils.translation import gettext as _
from django.views.generic import TemplateView
from arches.app.datatypes.datatypes import DataTypeFactory
Expand All @@ -35,10 +33,6 @@


class BaseManagerView(TemplateView):
if is_compatible_with_arches() is False:
message = _("This project is incompatible with Arches {0}.").format(__version__)
raise CompatibilityError(message)

template_name = ""

def get_context_data(self, **kwargs):
Expand Down
66 changes: 66 additions & 0 deletions arches/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import tomllib
import warnings
from importlib.metadata import PackageNotFoundError, requires
from pathlib import Path

from django.apps import apps
from django.conf import settings
from django.core.checks import register, Tags, Error, Warning
from semantic_version import SimpleSpec, Version

from arches import __version__

### GLOBAL DEPRECATIONS ###
FILE_TYPE_CHECKING_MSG = (
Expand Down Expand Up @@ -51,3 +58,62 @@ def check_cache_backend(app_configs, **kwargs):
)
)
return errors


@register(Tags.compatibility)
def check_arches_compatibility(app_configs, **kwargs):
try:
arches_version = Version(__version__)
except ValueError:
arches_version = Version.coerce(__version__)

if app_configs is None:
app_configs = apps.get_app_configs()

errors = []
for config in app_configs:
if not getattr(config, "is_arches_application", False):
continue
try:
project_requirements = requires(config.name)
except PackageNotFoundError:
# Not installed by pip: read pyproject.toml directly
toml_path = Path(config.path).parent / "pyproject.toml"
if not toml_path.exists():
raise ValueError
with open(toml_path, "rb") as f:
data = tomllib.load(f)
try:
project_requirements = data["project"]["dependencies"]
except KeyError:
raise ValueError from None
try:
for requirement in project_requirements:
if requirement.lower().startswith("arches"):
parsed_arches_requirement = SimpleSpec(
requirement.lower().replace("arches", "").lstrip()
)
break
else:
raise ValueError
except ValueError:
errors.append(
Error(
f"Invalid or missing arches requirement",
obj=config.name,
hint=project_requirements,
id="arches.E002",
)
)
continue
if arches_version not in parsed_arches_requirement:
errors.append(
Error(
f"Incompatible arches requirement for Arches version: {arches_version}",
obj=config.name,
hint=requirement,
id="arches.E003",
)
)

return errors
6 changes: 0 additions & 6 deletions arches/install/arches-templates/project_name/settings.py-tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
Django settings for {{ project_name }} project.
"""

import json
import os
import sys
import arches
import inspect
import semantic_version
from datetime import datetime, timedelta
Expand All @@ -19,9 +16,6 @@ except ImportError:
APP_NAME = '{{ project_name }}'
APP_VERSION = semantic_version.Version(major=0, minor=0, patch=0)
APP_ROOT = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
MIN_ARCHES_VERSION = arches.__version__
MAX_ARCHES_VERSION = arches.__version__


WEBPACK_LOADER = {
"DEFAULT": {
Expand Down
7 changes: 2 additions & 5 deletions arches/install/arches-templates/tests/test_settings.py-tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from arches.settings import *
import arches
import os

from arches.settings import *

try:
from django.utils.translation import gettext_lazy as _
except ImportError: # unable to import prior to installing requirements
Expand All @@ -35,9 +35,6 @@ ROOT_URLCONF = '{{ project_name }}.urls'

ARCHES_APPLICATIONS = ()

MIN_ARCHES_VERSION = arches.__version__
MAX_ARCHES_VERSION = arches.__version__

# LOAD_V3_DATA_DURING_TESTS = True will engage the most extensive the of the v3
# data migration tests, which could add over a minute to the test process. It's
# recommended that this setting only be set to True in tests/settings_local.py
Expand Down
2 changes: 0 additions & 2 deletions arches/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,6 @@

APP_NAME = "Arches"
APP_VERSION = None
MIN_ARCHES_VERSION = None
MAX_ARCHES_VERSION = None

APP_TITLE = "Arches | Heritage Data Management"
COPYRIGHT_TEXT = "All Rights Reserved."
Expand Down
3 changes: 2 additions & 1 deletion releases/7.6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Arches 7.6.0 Release Notes
- 10911 Styling fix in resource model manage menu
- 11118 Harden SystemSettings model against too-early access #11118
- 10726 Upgrade openpyxl package to 3.1.2 and fixes ETL modules
- 11114 Implement arches version compatibility check as a Django system check
- 9191 Adds unlocalized string datatype
- 10597 Fix internationalized string/json field entry problems in the Django admin
- 10787 Search Export: data exportable as "system values" (e.g. concept valueids) instead of "display values" (e.g. string preflabel)
Expand Down Expand Up @@ -169,7 +170,7 @@ Minor incompatibilities:
is now a more attractive target for overriding than `run_load_task()`.
- `unzip_file()` moved from `arches.setup` to `arches.app.utils.zip`
- Version-related utils moved from `arches.setup` to `arches.version`

- `arches.app.utils.compatibility` was removed in favor of a Django system check.

### Deprecations

Expand Down
7 changes: 2 additions & 5 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from arches.settings import *
import arches
import os

from arches.settings import *

try:
from django.utils.translation import gettext_lazy as _
except ImportError: # unable to import prior to installing requirements
Expand All @@ -31,9 +31,6 @@

ARCHES_APPLICATIONS = ()

MIN_ARCHES_VERSION = arches.__version__
MAX_ARCHES_VERSION = arches.__version__

# LOAD_V3_DATA_DURING_TESTS = True will engage the most extensive the of the v3
# data migration tests, which could add over a minute to the test process. It's
# recommended that this setting only be set to True in tests/settings_local.py
Expand Down

0 comments on commit 7a4e1e3

Please sign in to comment.