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

fix: use copy(v) which works also on str, instead of v.copy() which doesn't #5417

Merged
merged 12 commits into from
Nov 26, 2024
Merged
2 changes: 1 addition & 1 deletion .github/workflows/cla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check CLA
uses: conda/actions/check-cla@15f883f14f4232f83658e3609c3316d58905138f # v24.8.0
uses: conda/actions/check-cla@6e72e0db87e72f0020e493aeb02f864363bd9258 # v24.11.1
with:
# [required]
# A token with ability to comment, label, and modify the commit status
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
days-before-issue-stale: 90
days-before-issue-close: 21
steps:
- uses: conda/actions/read-yaml@15f883f14f4232f83658e3609c3316d58905138f # v24.8.0
- uses: conda/actions/read-yaml@6e72e0db87e72f0020e493aeb02f864363bd9258 # v24.11.1
id: read_yaml
with:
path: https://raw.githubusercontent.com/conda/infra/main/.github/messages.yml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ jobs:
git config --global user.name 'Conda Bot'
git config --global user.email '[email protected]'

- uses: conda/actions/combine-durations@15f883f14f4232f83658e3609c3316d58905138f # v24.8.0
- uses: conda/actions/combine-durations@6e72e0db87e72f0020e493aeb02f864363bd9258 # v24.11.1
id: durations
continue-on-error: true

- uses: conda/actions/template-files@15f883f14f4232f83658e3609c3316d58905138f # v24.8.0
- uses: conda/actions/template-files@6e72e0db87e72f0020e493aeb02f864363bd9258 # v24.11.1
id: templates
continue-on-error: true

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ repos:
# auto format Python codes within docstrings
- id: blacken-docs
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
rev: v0.7.4
hooks:
# lint & attempt to correct failures (e.g. pyupgrade)
- id: ruff
Expand Down
27 changes: 20 additions & 7 deletions conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1597,21 +1597,34 @@ def ms_depends(self, typ="run"):
try:
ms = MatchSpec(spec)
except AssertionError:
raise RuntimeError(f"Invalid package specification: {spec!r}")
if len(self.undefined_jinja_vars) == 0:
raise RuntimeError(f"Invalid package specification: {spec!r}")
else:
continue
except (AttributeError, ValueError) as e:
raise RuntimeError(
"Received dictionary as spec. Note that pip requirements are "
"not supported in conda-build meta.yaml. Error message: " + str(e)
)
if len(self.undefined_jinja_vars) == 0:
raise RuntimeError(
"Received dictionary as spec. Note that pip requirements are "
"not supported in conda-build meta.yaml. Error message: "
+ str(e)
)
else:
continue

if ms.name == self.name() and not (
typ == "build" and self.config.host_subdir != self.config.build_subdir
):
raise RuntimeError(f"{self.name()} cannot depend on itself")

# TODO: IDK what this does since AFAIK the inner continue applies only
# to the inner loop
for name, ver in name_ver_list:
if ms.name == name:
if self.noarch:
continue

# TODO: the validation here appears to be a waste of time since MatchSpec
# appears to validate?
for c in "=!@#$%^&*:;\"'\\|<>?/":
if c in ms.name:
sys.exit(
Expand Down Expand Up @@ -2579,7 +2592,7 @@ def get_output_metadata_set(
ref_metadata.parse_until_resolved(
allow_no_other_outputs=True, bypass_env_check=True
)
except SystemExit:
except (SystemExit, CondaBuildUserError):
pass
outputs = get_output_dicts_from_metadata(ref_metadata)

Expand Down Expand Up @@ -2611,7 +2624,7 @@ def get_output_metadata_set(
ref_metadata.other_outputs = out_metadata.other_outputs = (
all_output_metadata
)
except SystemExit:
except (SystemExit, CondaBuildUserError):
if not permit_undefined_jinja:
raise
output_tuples = []
Expand Down
4 changes: 2 additions & 2 deletions conda_build/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

from . import environ, exceptions, source, utils
from .config import CondaPkgFormat
from .exceptions import DependencyNeedsBuildingError
from .exceptions import CondaBuildUserError, DependencyNeedsBuildingError
from .index import get_build_index
from .metadata import MetaData, MetaDataTuple, combine_top_level_metadata_with_output
from .utils import (
Expand Down Expand Up @@ -894,7 +894,7 @@ def distribute_variants(
allow_no_other_outputs=allow_no_other_outputs,
bypass_env_check=bypass_env_check,
)
except SystemExit:
except (SystemExit, CondaBuildUserError):
pass
need_source_download = not mv.needs_source_for_render or not mv.source_provided

Expand Down
2 changes: 1 addition & 1 deletion conda_build/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def _combine_spec_dictionaries(
) != len(ensure_list(v)):
break
else:
values[k] = v.copy()
values[k] = copy(v)
missing_subvalues = [
subvalue
for subvalue in ensure_list(v)
Expand Down
19 changes: 19 additions & 0 deletions news/5417-fix-str-copy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Fixed a bug where ``.copy()`` was used on a string instead of ``copy()`` when processing variants. (#5417)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
20 changes: 20 additions & 0 deletions news/5538-sysexit-vs-cdusererror
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Enhancements

* <news item>

### Bug fixes

* Fixed a bug where some ``CondaBuildUserError`` exceptions that were formally ``SystemExit`` exceptions
were not being caught properly. (#5538)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
19 changes: 19 additions & 0 deletions news/5555-skip-bad-specs-while-still-parsing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Fixed a bug where bad match specs from intermediate parsing results would cause parsing to fail. (#5555)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
2 changes: 1 addition & 1 deletion tests/test_api_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,7 @@ def test_conda_build_script_errors_without_conda_info_handlers(tmp_path, recipe,

def test_api_build_inject_jinja2_vars_on_first_pass(testing_config):
recipe_dir = os.path.join(metadata_dir, "_inject_jinja2_vars_on_first_pass")
with pytest.raises(RuntimeError):
with pytest.raises((RuntimeError, CondaBuildUserError)):
api.build(recipe_dir, config=testing_config)

testing_config.variant = {"python_min": "3.12"}
Expand Down
45 changes: 45 additions & 0 deletions tests/test_api_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os
import re
import textwrap
from itertools import count, islice

import pytest
Expand All @@ -15,6 +16,7 @@
from conda.common.compat import on_win

from conda_build import api, render
from conda_build.exceptions import CondaBuildUserError
from conda_build.variants import validate_spec

from .utils import metadata_dir, variants_dir
Expand Down Expand Up @@ -341,3 +343,46 @@ def create_variants():
recipe, config=testing_config, channels=[], variants=create_variants()
)
assert len(metadata_tuples) == 11 - 3 # omits libarrow-all, pyarrow, pyarrow-tests


def test_api_render_missing_jinja2(testing_config, testing_workdir):
with open(os.path.join(testing_workdir, "meta.yaml"), "w") as f:
f.write(
textwrap.dedent(
"""
package:
name: blah-{{ foo }}
version: 0.1

build:
number: 0

requirements:
host:
- python {{ python_min }}
run:
- python
"""
)
)

meta = api.render(
testing_workdir,
finalize=False,
bypass_env_check=True,
trim_skip=False,
)
assert meta is not None
assert any("python" in val for val in meta[0][0].get_value("requirements/host"))
assert not any(
"{{ python_min }}" in val for val in meta[0][0].get_value("requirements/run")
)
assert meta[0][0].get_value("package/name") == "blah-"

with pytest.raises(CondaBuildUserError):
api.render(
testing_workdir,
finalize=True,
bypass_env_check=True,
trim_skip=False,
)
53 changes: 53 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,56 @@ def test_parse_until_resolved_skip_avoids_undefined_jinja(
pytest.fail(
"Undefined variable caused error, even though this build is skipped"
)


@pytest.mark.parametrize("have_variant", [True, False])
def test_parse_until_resolved_missing_jinja_in_spec(
testing_metadata: MetaData,
tmp_path: Path,
have_variant: bool,
) -> None:
(recipe := tmp_path / (name := "meta.yaml")).write_text(
"""
package:
name: dummy
version: 1.0.0

build:
noarch: python
number: 0

requirements:
host:
- python ={{ python_min }}
run:
- python >={{ python_min }}
"""
)
(tmp_path / "conda_build_config.yaml").write_text(
"""
python_min:
- 3.6
"""
)
testing_metadata._meta_path = recipe
testing_metadata._meta_name = name
if have_variant:
testing_metadata.config.variant = {"python_min": "3.6"}
else:
delattr(testing_metadata.config, "variant")
delattr(testing_metadata.config, "variant_config_files")
delattr(testing_metadata.config, "variants")

try:
testing_metadata.parse_until_resolved()
if not have_variant:
pytest.fail("Undefined variable did NOT cause spec parsing error!")
else:
print("parsed OK!")
except (Exception, SystemExit):
if have_variant:
pytest.fail(
"Undefined variable caused spec parsing error even if we have the variant!"
)
else:
print("did not parse OK!")
Loading
Loading