Skip to content

Commit

Permalink
nits re #11114
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored and chiatt committed Aug 6, 2024
1 parent 86ab445 commit f24f987
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
45 changes: 29 additions & 16 deletions arches/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,31 @@ def read_project_requirements_from_toml_file(config: AppConfig):
if not getattr(config, "is_arches_application", False):
continue
project_requirements = ["No project requirements found."]

try:
try:
project_requirements = requires(config.name)
except PackageNotFoundError:
# Not installed by pip: read pyproject.toml directly
project_requirements = read_project_requirements_from_toml_file(config)
for requirement in project_requirements:
if requirement.lower().split()[0] == "arches":
to_parse = requirement.lower().replace("arches", "").lstrip()
# Some arches tags didn't use hyphens, so provide them.
to_parse = re.sub(r"0(a|b|rc)", r"0-\1", to_parse)
parsed_arches_requirement = SimpleSpec(to_parse)
break
project_requirements = requires(config.name)
except PackageNotFoundError:
# Not installed by pip: read pyproject.toml directly
project_requirements = read_project_requirements_from_toml_file(config)

for requirement in project_requirements:
to_parse = requirement.lower()
# Normalize "arches" [requires() output] to "arches " [raw toml file]
# So we can split on a consistent separator (space)
to_parse = to_parse.replace("arches", "arches ")
if to_parse.split()[0] == "arches":
to_parse = requirement.lower().replace("arches", "").lstrip()
else:
raise ValueError
except ValueError:
continue
# Some arches tags didn't use hyphens, so provide them.
to_parse = re.sub(r"0(a|b|rc)", r"0-\1", to_parse)
try:
parsed_arches_requirement = SimpleSpec(to_parse)
except ValueError:
# might have been arches-for-x==3 -> for-x==3, not valid; keep searching.
continue
break
else:
errors.append(
Error(
f"Invalid or missing arches requirement",
Expand All @@ -125,6 +134,7 @@ def read_project_requirements_from_toml_file(config: AppConfig):
)
)
continue

if arches_version not in parsed_arches_requirement:
errors.append(
CheckMessage(
Expand All @@ -141,13 +151,16 @@ def read_project_requirements_from_toml_file(config: AppConfig):

@register(Tags.compatibility)
def warn_old_compatibility_settings(app_configs, **kwargs):
errors = []

if getattr(settings, "MIN_ARCHES_VERSION", None) or getattr(
settings, "MAX_ARCHES_VERSION", None
):
return [
errors.append(
Warning(
msg=f"MIN_ARCHES_VERSION and MAX_ARCHES_VERSION have no effect.",
hint="Migrate your version range to pyproject.toml.",
id="arches.W002",
)
]
)
return errors
3 changes: 2 additions & 1 deletion tests/utils/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.apps import apps
from django.core.management import call_command
from django.core.management.base import SystemCheckError
from django.test import SimpleTestCase
from django.test import SimpleTestCase, override_settings


# these tests can be run from the command line via
Expand All @@ -16,6 +16,7 @@ def raise_package_not_found_error(name):


class SystemCheckTests(SimpleTestCase):
@override_settings(DEBUG=False)
def test_compatibility(self):
"""Patch core arches to be an "arches application" so we can check
its range of compatible arches version, which it won't have.
Expand Down

0 comments on commit f24f987

Please sign in to comment.