Skip to content

Commit 18af7dc

Browse files
authored
Add rattler-build support for info_json_from_tar_generator (#54)
* Use paths.json instead of files to get all files of a package * Also check for rattler-build recipe * remove asserts * code review * fix
1 parent 13fae09 commit 18af7dc

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

conda_forge_metadata/artifact_info/info_json.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,17 @@ def get_artifact_info_as_json(
5858
"about": the info/about.json file contents
5959
"rendered_recipe": the fully rendered recipe at
6060
either info/recipe/meta.yaml or info/meta.yaml
61-
as a dict
61+
as a dict.
62+
For rattler-build recipes, we use rendered_recipe.yaml.
6263
"raw_recipe": the template recipe as a string from
6364
info/recipe/meta.yaml.template - could be
64-
the rendered recipe as a string if no template was found
65+
the rendered recipe as a string if no template was found.
66+
For rattler-build recipes, we use recipe.yaml.
6567
"conda_build_config": the conda_build_config.yaml used for building
6668
the recipe at info/recipe/conda_build_config.yaml
67-
"files": a list of files in the recipe from info/files with
69+
For rattler-build recipes, we use variant_config.yaml instead.
70+
"files": a list of files in the recipe from info/paths.json
71+
(or fallback to info/files if info/paths.json doesn't exist) with
6872
elements ending in .pyc or .txt filtered out.
6973
"""
7074
if backend == "libcfgraph":
@@ -138,7 +142,28 @@ def info_json_from_tar_generator(
138142
data["conda_build_config"] = YAML.load(
139143
_extract_read(tar, member, default="{}")
140144
)
145+
elif path.name == "variant_config.yaml":
146+
data["conda_build_config"] = YAML.load(
147+
_extract_read(tar, member, default="{}")
148+
)
149+
elif path.name == "paths.json":
150+
paths = json.loads(_extract_read(tar, member, default="{}"))
151+
paths_version = paths.get("paths_version", 1)
152+
if paths_version != 1:
153+
warnings.warn(
154+
f"Unrecognized paths_version {paths_version} in paths.json",
155+
RuntimeWarning,
156+
)
157+
files = [p.get("_path", "") for p in paths.get("paths", [])]
158+
if skip_files_suffixes:
159+
files = [
160+
f for f in files if not f.lower().endswith(skip_files_suffixes)
161+
]
162+
data["files"] = files
141163
elif path.name == "files":
164+
# prefer files from paths.json if available
165+
if data["files"]:
166+
continue
142167
files = _extract_read(tar, member, default="").splitlines()
143168
if skip_files_suffixes:
144169
files = [
@@ -153,6 +178,10 @@ def info_json_from_tar_generator(
153178
data["raw_recipe"] = x
154179
else:
155180
data["rendered_recipe"] = YAML.load(x)
181+
elif path.name == "recipe.yaml":
182+
data["raw_recipe"] = _extract_read(tar, member, default="")
183+
elif path.name == "rendered_recipe.yaml":
184+
data["rendered_recipe"] = YAML.load(_extract_read(tar, member, default=""))
156185
if data["name"]:
157186
return data # type: ignore
158187

tests/test_info_json.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,35 @@ def test_info_json_conda(backend: str):
6767
assert "site-packages/abipy/__init__.py" in info["files"]
6868

6969

70+
@pytest.mark.parametrize("backend", info_json.VALID_BACKENDS)
71+
def test_info_json_rattler_build(backend: str):
72+
info = info_json.get_artifact_info_as_json(
73+
"conda-forge",
74+
"linux-64",
75+
"jolt-physics-5.1.0-hff21bea_0.conda",
76+
backend=backend,
77+
)
78+
assert info is not None
79+
assert info["metadata_version"] == 1
80+
assert info["name"] == "jolt-physics"
81+
assert info["version"] == "5.1.0"
82+
assert info["index"]["name"] == "jolt-physics"
83+
assert info["index"]["version"] == "5.1.0"
84+
assert info["index"]["build"] == "hff21bea_0"
85+
assert info["index"]["subdir"] == "linux-64"
86+
assert "libstdcxx >=13" in info["index"]["depends"]
87+
assert "conda_version" not in info["about"]
88+
assert info["rendered_recipe"]["recipe"]["package"]["name"] == "jolt-physics"
89+
assert (
90+
info["rendered_recipe"]["recipe"]["source"][0]["sha256"]
91+
== "10fcc863ae2b9d48c2f22d8b0204034820e57a55f858b7c388ac9579d8cf4095"
92+
)
93+
assert info["raw_recipe"] is not None
94+
assert info["raw_recipe"].startswith("context:\n")
95+
assert info["conda_build_config"]["c_stdlib"] == "sysroot"
96+
assert "include/Jolt/AABBTree/AABBTreeBuilder.h" in info["files"]
97+
98+
7099
@pytest.mark.parametrize("backend", info_json.VALID_BACKENDS)
71100
def test_info_json_conda_unlucky_test_file(backend: str):
72101
"""

0 commit comments

Comments
 (0)