Skip to content

Commit

Permalink
Add rattler-build support for info_json_from_tar_generator (#54)
Browse files Browse the repository at this point in the history
* Use paths.json instead of files to get all files of a package

* Also check for rattler-build recipe

* remove asserts

* code review

* fix
  • Loading branch information
pavelzw authored Oct 28, 2024
1 parent 13fae09 commit 18af7dc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
35 changes: 32 additions & 3 deletions conda_forge_metadata/artifact_info/info_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ def get_artifact_info_as_json(
"about": the info/about.json file contents
"rendered_recipe": the fully rendered recipe at
either info/recipe/meta.yaml or info/meta.yaml
as a dict
as a dict.
For rattler-build recipes, we use rendered_recipe.yaml.
"raw_recipe": the template recipe as a string from
info/recipe/meta.yaml.template - could be
the rendered recipe as a string if no template was found
the rendered recipe as a string if no template was found.
For rattler-build recipes, we use recipe.yaml.
"conda_build_config": the conda_build_config.yaml used for building
the recipe at info/recipe/conda_build_config.yaml
"files": a list of files in the recipe from info/files with
For rattler-build recipes, we use variant_config.yaml instead.
"files": a list of files in the recipe from info/paths.json
(or fallback to info/files if info/paths.json doesn't exist) with
elements ending in .pyc or .txt filtered out.
"""
if backend == "libcfgraph":
Expand Down Expand Up @@ -138,7 +142,28 @@ def info_json_from_tar_generator(
data["conda_build_config"] = YAML.load(
_extract_read(tar, member, default="{}")
)
elif path.name == "variant_config.yaml":
data["conda_build_config"] = YAML.load(
_extract_read(tar, member, default="{}")
)
elif path.name == "paths.json":
paths = json.loads(_extract_read(tar, member, default="{}"))
paths_version = paths.get("paths_version", 1)
if paths_version != 1:
warnings.warn(
f"Unrecognized paths_version {paths_version} in paths.json",
RuntimeWarning,
)
files = [p.get("_path", "") for p in paths.get("paths", [])]
if skip_files_suffixes:
files = [
f for f in files if not f.lower().endswith(skip_files_suffixes)
]
data["files"] = files
elif path.name == "files":
# prefer files from paths.json if available
if data["files"]:
continue
files = _extract_read(tar, member, default="").splitlines()
if skip_files_suffixes:
files = [
Expand All @@ -153,6 +178,10 @@ def info_json_from_tar_generator(
data["raw_recipe"] = x
else:
data["rendered_recipe"] = YAML.load(x)
elif path.name == "recipe.yaml":
data["raw_recipe"] = _extract_read(tar, member, default="")
elif path.name == "rendered_recipe.yaml":
data["rendered_recipe"] = YAML.load(_extract_read(tar, member, default=""))
if data["name"]:
return data # type: ignore

Expand Down
29 changes: 29 additions & 0 deletions tests/test_info_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,35 @@ def test_info_json_conda(backend: str):
assert "site-packages/abipy/__init__.py" in info["files"]


@pytest.mark.parametrize("backend", info_json.VALID_BACKENDS)
def test_info_json_rattler_build(backend: str):
info = info_json.get_artifact_info_as_json(
"conda-forge",
"linux-64",
"jolt-physics-5.1.0-hff21bea_0.conda",
backend=backend,
)
assert info is not None
assert info["metadata_version"] == 1
assert info["name"] == "jolt-physics"
assert info["version"] == "5.1.0"
assert info["index"]["name"] == "jolt-physics"
assert info["index"]["version"] == "5.1.0"
assert info["index"]["build"] == "hff21bea_0"
assert info["index"]["subdir"] == "linux-64"
assert "libstdcxx >=13" in info["index"]["depends"]
assert "conda_version" not in info["about"]
assert info["rendered_recipe"]["recipe"]["package"]["name"] == "jolt-physics"
assert (
info["rendered_recipe"]["recipe"]["source"][0]["sha256"]
== "10fcc863ae2b9d48c2f22d8b0204034820e57a55f858b7c388ac9579d8cf4095"
)
assert info["raw_recipe"] is not None
assert info["raw_recipe"].startswith("context:\n")
assert info["conda_build_config"]["c_stdlib"] == "sysroot"
assert "include/Jolt/AABBTree/AABBTreeBuilder.h" in info["files"]


@pytest.mark.parametrize("backend", info_json.VALID_BACKENDS)
def test_info_json_conda_unlucky_test_file(backend: str):
"""
Expand Down

0 comments on commit 18af7dc

Please sign in to comment.