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 bug with test: None #3018

Merged
merged 6 commits into from
Oct 11, 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
47 changes: 44 additions & 3 deletions conda_forge_tick/feedstock_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
from .migrators_types import PackageName, RequirementsTypedDict

from conda_forge_tick.lazy_json_backends import LazyJson, dumps, loads

from .utils import as_iterable, parse_meta_yaml, parse_recipe_yaml
from conda_forge_tick.utils import as_iterable, parse_meta_yaml, parse_recipe_yaml

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -154,9 +153,23 @@
requirements_dict[section].update(
list(as_iterable(req.get(section, []) or [])),
)
test: "TestTypedDict" = block.get("test", {})

test: "TestTypedDict" = block.get("test", {}) or {}
requirements_dict["test"].update(test.get("requirements", []) or [])
requirements_dict["test"].update(test.get("requires", []) or [])

if "tests" in block:
for test in block.get("tests", []):

Check warning on line 162 in conda_forge_tick/feedstock_parser.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/feedstock_parser.py#L162

Added line #L162 was not covered by tests
# only script tests have requirements
if "requirements" in test:
run_reqs = test["requirements"].get("run", [])
build_reqs = test["requirements"].get("build", [])
requirements_dict["test"].update(run_reqs + build_reqs)
if "python" in test:

Check warning on line 168 in conda_forge_tick/feedstock_parser.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/feedstock_parser.py#L164-L168

Added lines #L164 - L168 were not covered by tests
# if pip_check is unset or True, we need pip
if test.get("pip_check", True):
requirements_dict["test"].add("pip")

Check warning on line 171 in conda_forge_tick/feedstock_parser.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/feedstock_parser.py#L170-L171

Added lines #L170 - L171 were not covered by tests

run_exports = (block.get("build", {}) or {}).get("run_exports", {})
if isinstance(run_exports, dict) and run_exports.get("strong"):
strong_exports = True
Expand Down Expand Up @@ -686,3 +699,31 @@
conda_forge_yaml=conda_forge_yaml,
mark_not_archived=mark_not_archived,
)


if __name__ == "__main__":
import json
import os
import sys

Check warning on line 707 in conda_forge_tick/feedstock_parser.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/feedstock_parser.py#L705-L707

Added lines #L705 - L707 were not covered by tests

# Do not use docker when debugging
os.environ["CF_FEEDSTOCK_OPS_IN_CONTAINER"] = "true"

Check warning on line 710 in conda_forge_tick/feedstock_parser.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/feedstock_parser.py#L710

Added line #L710 was not covered by tests

if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} feedstock_name")
sys.exit(1)
feedstock_name = sys.argv[1]

Check warning on line 715 in conda_forge_tick/feedstock_parser.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/feedstock_parser.py#L712-L715

Added lines #L712 - L715 were not covered by tests

graph = {}
load_feedstock_local(

Check warning on line 718 in conda_forge_tick/feedstock_parser.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/feedstock_parser.py#L717-L718

Added lines #L717 - L718 were not covered by tests
"carma",
graph,
)

class SetEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
return json.JSONEncoder.default(self, obj)

Check warning on line 727 in conda_forge_tick/feedstock_parser.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/feedstock_parser.py#L723-L727

Added lines #L723 - L727 were not covered by tests

print(json.dumps(graph, indent=4, cls=SetEncoder))

Check warning on line 729 in conda_forge_tick/feedstock_parser.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/feedstock_parser.py#L729

Added line #L729 was not covered by tests
31 changes: 28 additions & 3 deletions conda_forge_tick/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import os
import pprint
import re
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -349,6 +350,28 @@ def parse_recipe_yaml_local(
return parsed_recipes


def replace_compiler_with_stub(text: str) -> str:
"""
Replace compiler function calls with a stub function call to match the conda-build
output.

Parameters
----------
text : str

Returns
-------
str
"""
pattern = r'\$\{\{\s*compiler\((["\'])(.*?)\1\)\s*\}\}'
text = re.sub(pattern, lambda m: f"{m.group(2)}_compiler_stub", text)

pattern = r'\$\{\{\s*stdlib\((["\'])(.*?)\1\)\s*\}\}'
text = re.sub(pattern, lambda m: f"{m.group(2)}_stdlib_stub", text)

return text


def _render_recipe_yaml(
text: str,
platform_arch: str | None = None,
Expand All @@ -375,13 +398,16 @@ def _render_recipe_yaml(
build_platform_flags = (
[] if platform_arch is None else ["--build-platform", platform_arch]
)

prepared_text = replace_compiler_with_stub(text)

res = subprocess.run(
["rattler-build", "build", "--render-only"]
+ variant_config_flags
+ build_platform_flags,
stdout=subprocess.PIPE,
text=True,
input=text,
input=prepared_text,
check=True,
)
return [output["recipe"] for output in json.loads(res.stdout)]
Expand Down Expand Up @@ -509,8 +535,8 @@ def _parse_recipes(
{
"name": None if package_output is None else package_output.get("name"),
"requirements": requirements_output_data,
"test": None,
"build": build_output_data,
"tests": recipe.get("tests", []),
}
)

Expand All @@ -520,7 +546,6 @@ def _parse_recipes(
"package": package_data,
"requirements": requirements_data,
"source": source_data,
"test": None,
"outputs": output_data,
"extra": first.get("extra"),
}
Expand Down