Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobellei-eai authored Sep 11, 2024
2 parents 5b7144c + 23b2777 commit 83e4042
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Hi!
Thank you for making an admin request on this repo. We strive to make a decision
on these requests within 24 hours.
on these requests within 24 hours.
Please use the text below to add context about this PR, especially if:
- You want to mark packages as broken
Expand Down Expand Up @@ -53,6 +53,10 @@ What will happen when a package is marked broken?
* [ ] Posted a link to the conda artifacts
* [ ] Posted a link to the build logs

* [ ] I want to add a package output to a feedstock:
* [ ] Pinged the relevant feedstock team(s)
* [ ] Added a small description of why the output is being added.

<!--
For example if you are trying to mark a `foo` conda package as broken.
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ submit a PR adding your feedstock name to a new `.yml` file in `requests` folder
Available opt-in resources:

- Travis CI: See `examples/example-travis.yml`
- [`open-gpu-server`](https://github.com/Quansight/open-gpu-server) (includes GPU CI and long-running builds): See `examples/example-open-gpu-server.yml`.
- [`open-gpu-server`](https://github.com/Quansight/open-gpu-server) (includes GPU CI and long-running builds): See `examples/example-open-gpu-server.yml`.

## Request a CFEP-3 copy to conda-forge

Expand All @@ -72,3 +72,12 @@ This workflow allows users to request a copy once the manual review has been pas
To do so, please create a new `.yml` file in the `requests` folder. Check `examples/example-cfep-3.yml` for the required metadata.

For provenance and transparency, the PR description must include a link to the original PR and the logs, along with the artifact(s) to be reviewed.

## Add a package output to a feedstock

By default, `conda-forge` feedstocks cannot push packages to our channel that another feedstock makes. If you encountered an error
when building your package indicating that the given package was not allowed for your feedstock (e.g., you moved a package
build from one feedstock to another), you should request the output be added to the new feedstock via this repository. An example request
is located in [examples/example-add-feedstock-output.yml](examples/example-add-feedstock-output.yml). You can add both glob patterns
and package names. We support the glob syntax of the Python `fnmatch` module. Make a PR putting your
`.yml` request file in the `requests` directory and the `conda-forge/core` team will review it.
3 changes: 2 additions & 1 deletion conda_forge_admin_requests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import importlib
import pkgutil
from . import archive_feedstock, mark_broken, token_reset, access_control, cfep3_copy
from . import archive_feedstock, mark_broken, token_reset, access_control, cfep3_copy, feedstock_outputs

actions = {}

Expand All @@ -22,6 +22,7 @@ def register_actions():
register_action("travis", access_control)
register_action("cirun", access_control)
register_action("cfep3_copy", cfep3_copy)
register_action("add_feedstock_output", feedstock_outputs)
for pkg in pkgutil.iter_modules():
if pkg.name.startswith("conda_forge_admin_requests_"):
spec = importlib.util.find_spec(pkg.name)
Expand Down
111 changes: 111 additions & 0 deletions conda_forge_admin_requests/feedstock_outputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import io
import json
import os
import requests

import ruamel.yaml
from conda_forge_metadata.feedstock_outputs import sharded_path as _get_sharded_path
import github


def _add_feedstock_output(
feedstock,
pkg_name,
):
gh_token = os.environ['GITHUB_TOKEN']
gh = github.Github(auth=github.Auth.Token(gh_token))
repo = gh.get_repo("conda-forge/feedstock-outputs")
try:
contents = repo.get_contents(_get_sharded_path(pkg_name))
except github.UnknownObjectException:
contents = None

if contents is None:
data = {"feedstocks": [feedstock]}
repo.create_file(
_get_sharded_path(pkg_name),
f"[cf admin skip] ***NO_CI*** add output {pkg_name} for conda-forge/{feedstock}-feedstock",
json.dumps(data),
)
print(f" output {pkg_name} added for feedstock conda-forge/{feedstock}-feedstock", flush=True)
else:
data = json.loads(contents.decoded_content.decode("utf-8"))
if feedstock not in data["feedstocks"]:
data["feedstocks"].append(feedstock)
repo.update_file(
contents.path,
f"[cf admin skip] ***NO_CI*** add output {pkg_name} for conda-forge/{feedstock}-feedstock",
json.dumps(data),
contents.sha,
)
print(f" output {pkg_name} added for feedstock conda-forge/{feedstock}-feedstock", flush=True)
else:
print(f" output {pkg_name} already exists for feedstock conda-forge/{feedstock}-feedstock", flush=True)


def _add_feedstock_output_glob(
feedstock,
glob_str,
):
gh_token = os.environ['GITHUB_TOKEN']
gh = github.Github(auth=github.Auth.Token(gh_token))
repo = gh.get_repo("conda-forge/feedstock-outputs")
contents = repo.get_contents("feedstock_outputs_autoreg_allowlist.yml")

yaml = ruamel.yaml.YAML(typ="rt") # use round-trip to preserve comments
data = yaml.load(contents.decoded_content.decode("utf-8"))
current_globs = data.get(feedstock, [])
if glob_str not in current_globs:
current_globs.append(glob_str)
data[feedstock] = current_globs
fp = io.StringIO()
yaml.dump(data, fp)
repo.update_file(
contents.path,
f"[cf admin skip] ***NO_CI*** add glob {glob_str} for conda-forge/{feedstock}-feedstock",
fp.getvalue(),
contents.sha,
)
print(f" glob {glob_str} added for feedstock conda-forge/{feedstock}-feedstock", flush=True)


def check(request):
action = request["action"]
assert action == "add_feedstock_output"

assert request.get("feedstock_to_output_mapping")
for req in request["feedstock_to_output_mapping"]:
for feedstock, _ in req.items():
if feedstock.endswith("-feedstock"):
feedstock = feedstock[:-10]

r = requests.head(
f"https://github.com/conda-forge/{feedstock}-feedstock"
)
r.raise_for_status()


def run(request):
action = request["action"]
assert action == "add_feedstock_output"

assert request.get("feedstock_to_output_mapping")
items_to_keep = []
for req in request["feedstock_to_output_mapping"]:
for feedstock, pkg_name in req.items():
try:
if feedstock.endswith("-feedstock"):
feedstock = feedstock[:-10]
if any(_c in pkg_name for _c in ["*", "?", "[", "]", "!"]):
_add_feedstock_output_glob(feedstock, pkg_name)
else:
_add_feedstock_output(feedstock, pkg_name)
except Exception as e:
print(f" could not add output {pkg_name} for feedstock conda-forge/{feedstock}-feedstock: {e}", flush=True)
items_to_keep.append({feedstock: pkg_name})

if items_to_keep:
request["feedstock_to_output_mapping"] = items_to_keep
return request
else:
return None
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ dependencies:
- pydantic
- cirun
- conda-smithy >=3.30.1
- conda-forge-metadata >=0.9.1
- ruamel.yaml
6 changes: 6 additions & 0 deletions examples/example-add-feedstock-output.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
action: add_feedstock_output
feedstock_to_output_mapping:
# this entry adds a package name
- clang-compiler-activation: clang_impl_osx-64
# this entry adds an allowed glob pattern
- llvmdev: "libllvm*"

0 comments on commit 83e4042

Please sign in to comment.