Skip to content

Commit

Permalink
fix: add tests and clarify output typing
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr committed Sep 9, 2024
1 parent 6ec77f4 commit ffb48c0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
25 changes: 15 additions & 10 deletions conda_forge_metadata/feedstock_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def sharded_path(name: CondaPackageName) -> str:
return f"{outputs_path}/{'/'.join(chars)}/{name}.json"


@lru_cache(maxsize=1)
def _fetch_allowed_autoreg_feedstock_globs(time_int):
r = requests.get(
"https://raw.githubusercontent.com/conda-forge/feedstock-outputs/"
Expand All @@ -76,7 +77,7 @@ def fetch_allowed_autoreg_feedstock_globs():


@lru_cache(maxsize=1024)
def package_to_feedstock(name: CondaPackageName, **request_kwargs: Any) -> set(str):
def package_to_feedstock(name: CondaPackageName, **request_kwargs: Any) -> list[str]:
"""Map a package name to the feedstock name(s).
Parameters
Expand All @@ -88,26 +89,30 @@ def package_to_feedstock(name: CondaPackageName, **request_kwargs: Any) -> set(s
Returns
-------
feedstock : set of str
feedstock : list of str
The name of the feedstock, without the ``-feedstock`` suffix.
"""
assert name, "name must not be empty"

feedstocks = set()
fs_pats = fetch_allowed_autoreg_feedstock_globs()
for autoreg_feedstock, pats in fs_pats.items():
for pat in pats:
if fnmatch(name, pat):
feedstocks.add(autoreg_feedstock)

ref = "main"
path = sharded_path(name)
req = requests.get(
f"https://raw.githubusercontent.com/conda-forge/feedstock-outputs/{ref}/{path}",
**request_kwargs,
)
req.raise_for_status()
feedstocks = set(req.json()["feedstocks"])
fs_pats = fetch_allowed_autoreg_feedstock_globs()
for autoreg_feedstock, pats in fs_pats.items():
for pat in pats:
if fnmatch(name, pat):
feedstocks.add(autoreg_feedstock)
if not feedstocks:
req.raise_for_status()
if req.status_code == 200:
feedstocks |= set(req.json()["feedstocks"])

return feedstocks
return list(feedstocks)


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions tests/test_feedstock_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ def test_feedstock_outputs():
assert package_to_feedstock("conda-forge-pinning") == ["conda-forge-pinning"]
assert package_to_feedstock("tk") == ["tk"]
assert "python" in package_to_feedstock("python")


def test_feedstock_outputs_autoreg():
assert package_to_feedstock("libllvm29") == ["llvmdev"]

0 comments on commit ffb48c0

Please sign in to comment.