Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rerenders: do not raise on validation errors #1885

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions conda_smithy/configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import pprint
import textwrap
import time
import jsonschema
import yaml
import warnings
from collections import Counter, OrderedDict, namedtuple
Expand Down Expand Up @@ -1999,11 +1998,15 @@ def _read_forge_config(forge_dir, forge_yml=None):

# Validate loaded configuration against a JSON schema.
validate_lints, validate_hints = validate_json_schema(file_config)
for err in validate_lints:
raise ExceptionGroup("lints", [*map(ValueError, validate_lints)])

for hint in validate_hints:
logger.info(hint.message)
for err in chain(validate_lints, validate_hints):
logger.warn(
"%s: %s = %s -> %s",
os.path.relpath(forge_yml, forge_dir),
err.json_path,
err.instance,
err.message,
)
logger.debug("Relevant schema:\n%s", json.dumps(err.schema, indent=2))

# The config is just the union of the defaults, and the overridden
# values.
Expand Down
6 changes: 4 additions & 2 deletions conda_smithy/validate_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from pathlib import Path

from typing import Tuple, List
from jsonschema import Draft202012Validator, validators
from jsonschema.exceptions import ValidationError

Expand Down Expand Up @@ -36,7 +36,9 @@ def get_validator_class():
_VALIDATOR_CLASS = get_validator_class()


def validate_json_schema(config, schema_file: str = None):
def validate_json_schema(
config, schema_file: str = None
) -> Tuple[List[ValidationError], List[ValidationError]]:
# Validate the merged configuration against a JSON schema
if not schema_file:
schema_file = CONDA_FORGE_YAML_SCHEMA_FILE
Expand Down
23 changes: 23 additions & 0 deletions news/1885-do-not-raise-on-validation-errors.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* Do not raise on ``conda-forge.yml`` validation errors during rerender. A warning will be printed instead. (#1879 via #1885)

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
20 changes: 11 additions & 9 deletions tests/test_configure_feedstock.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import copy
import logging
import os

from conda_smithy import configure_feedstock
import textwrap

import pytest
import copy
import yaml
import textwrap

from conda_smithy import configure_feedstock


def test_noarch_skips_appveyor(noarch_recipe, jinja_env):
Expand Down Expand Up @@ -762,7 +763,7 @@ def test_conda_forge_yaml_empty(config_yaml):
assert load_forge_config()["recipe_dir"] == "recipe"


def test_noarch_platforms_bad_yaml(config_yaml):
def test_noarch_platforms_bad_yaml(config_yaml, caplog):
load_forge_config = lambda: configure_feedstock._load_forge_config( # noqa
config_yaml,
exclusive_config_file=os.path.join(
Expand All @@ -773,10 +774,10 @@ def test_noarch_platforms_bad_yaml(config_yaml):
with open(os.path.join(config_yaml, "conda-forge.yml"), "a+") as fp:
fp.write("noarch_platforms: [eniac, zx80]")

with pytest.raises(configure_feedstock.ExceptionGroup) as excinfo:
with caplog.at_level(logging.WARNING):
load_forge_config()

assert "eniac" in repr(excinfo.value)
assert "eniac" in caplog.text


def test_forge_yml_alt_path(config_yaml):
Expand Down Expand Up @@ -867,7 +868,7 @@ def test_cuda_enabled_render(cuda_enabled_recipe, jinja_env):
del os.environ["CF_CUDA_ENABLED"]


def test_conda_build_tools(config_yaml):
def test_conda_build_tools(config_yaml, caplog):
load_forge_config = lambda: configure_feedstock._load_forge_config( # noqa
config_yaml,
exclusive_config_file=os.path.join(
Expand Down Expand Up @@ -900,8 +901,9 @@ def test_conda_build_tools(config_yaml):
fp.write(unmodified)
fp.write("conda_build_tool: does-not-exist")

with pytest.raises(configure_feedstock.ExceptionGroup):
with caplog.at_level(logging.WARNING):
assert load_forge_config()
assert "does-not-exist" in caplog.text


def test_remote_ci_setup(config_yaml):
Expand Down
Loading