Skip to content

Commit

Permalink
Merge pull request #1752 from jaimergp/readme-channels
Browse files Browse the repository at this point in the history
Populate README with channels from conda_build_config.yaml
  • Loading branch information
isuruf authored Oct 18, 2023
2 parents 08e6829 + 97a2c1f commit 2a082a7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 22 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ out of by specifying `--without-anaconda-token`, as such execpted package upload
```
github:
user_or_org: YOUR_GITHUB_USER_OR_ORG
channels:
targets:
-
- YOUR_ANACONDA_CHANNEL
```

6. **Re-render the feedstock:** ``conda smithy rerender --feedstock_directory ./foo-feedstock``
Expand Down
2 changes: 1 addition & 1 deletion conda_smithy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __call__(self, args):
)

print(
"\nRepository created, please edit conda-forge.yml to configure the upload channels\n"
"\nRepository created, please edit recipe/conda_build_config.yaml to configure the upload channels\n"
"and afterwards call 'conda smithy register-github'"
)

Expand Down
29 changes: 22 additions & 7 deletions conda_smithy/configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,9 @@ def _render_ci_provider(
if os.path.exists(_recipe_cbc):
os.rename(_recipe_cbc, _recipe_cbc + ".conda.smithy.bak")

channel_sources = migrated_combined_variant_spec.get(
"channel_sources", [""]
)[0].split(",")
metas = conda_build.api.render(
os.path.join(forge_dir, forge_config["recipe_dir"]),
platform=platform,
Expand All @@ -742,9 +745,7 @@ def _render_ci_provider(
permit_undefined_jinja=True,
finalize=False,
bypass_env_check=True,
channel_urls=forge_config.get("channels", {}).get(
"sources", []
),
channel_urls=channel_sources,
)
finally:
if os.path.exists(_recipe_cbc + ".conda.smithy.bak"):
Expand Down Expand Up @@ -1612,11 +1613,23 @@ def render_README(jinja_env, forge_config, forge_dir, render_info=None):

ci_support_path = os.path.join(forge_dir, ".ci_support")
variants = []
channel_targets = []
if os.path.exists(ci_support_path):
for filename in os.listdir(ci_support_path):
if filename.endswith(".yaml"):
variant_name, _ = os.path.splitext(filename)
variants.append(variant_name)
with open(os.path.join(ci_support_path, filename)) as fh:
data = yaml.safe_load(fh)
for channel in data.get("channel_targets", ()):
# channel_targets are in the form of "channel_name label"
channel_targets.append(channel.split(" "))
if not channel_targets:
# default to conda-forge if no channel_targets are specified (shouldn't happen)
channel_targets = ["conda-forge main"]
else:
# de-duplicate in-order
channel_targets = list(dict.fromkeys(channel_targets))

subpackages_metas = OrderedDict((meta.name(), meta) for meta in metas)
subpackages_about = [(package_name, package_about)]
Expand Down Expand Up @@ -1648,6 +1661,7 @@ def render_README(jinja_env, forge_config, forge_dir, render_info=None):
)
)
)
forge_config["channel_targets"] = channel_targets

if forge_config["azure"].get("build_id") is None:

Expand Down Expand Up @@ -1824,10 +1838,6 @@ def _load_forge_config(forge_dir, exclusive_config_file, forge_yml=None):
"max_py_ver": "37",
"min_r_ver": "34",
"max_r_ver": "34",
"channels": {
"sources": ["conda-forge"],
"targets": [["conda-forge", "main"]],
},
"github": {
"user_or_org": "conda-forge",
"repo_name": "",
Expand Down Expand Up @@ -1902,6 +1912,11 @@ def _load_forge_config(forge_dir, exclusive_config_file, forge_yml=None):
"Setting docker image in conda-forge.yml is removed now."
" Use conda_build_config.yaml instead"
)
if file_config.get("channels"):
raise ValueError(
"Setting channels in conda-forge.yml is removed now."
" Use conda_build_config.yaml instead"
)

for plat in ["linux", "osx", "win"]:
if config["azure"]["timeout_minutes"] is not None:
Expand Down
2 changes: 1 addition & 1 deletion conda_smithy/templates/README.md.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- set channel_name = channels.targets[0][0] -%}
{%- set channel_name = channel_targets[0] -%}
{#-
# -*- mode: jinja -*-
-#}
Expand Down
23 changes: 23 additions & 0 deletions news/1752-readme-channels.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* Use the channels defined in `conda_build_config.yaml` (instead of those in `conda-forge.yml`) to render `README.md`. (#897 via #752)

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
12 changes: 3 additions & 9 deletions tests/test_configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,19 +750,15 @@ def test_conda_forge_yaml_empty(config_yaml):
),
)

assert ["conda-forge", "main"] in load_forge_config()["channels"][
"targets"
]
assert load_forge_config()["recipe_dir"] == "recipe"

os.unlink(os.path.join(config_yaml, "conda-forge.yml"))
with pytest.raises(RuntimeError):
load_forge_config()

with open(os.path.join(config_yaml, "conda-forge.yml"), "w"):
pass
assert ["conda-forge", "main"] in load_forge_config()["channels"][
"targets"
]
assert load_forge_config()["recipe_dir"] == "recipe"


def test_noarch_platforms_bad_yaml(config_yaml):
Expand Down Expand Up @@ -804,9 +800,7 @@ def test_forge_yml_alt_path(config_yaml):
with pytest.raises(RuntimeError):
load_forge_config(None)

assert ["conda-forge", "main"] in load_forge_config(forge_yml_alt)[
"channels"
]["targets"]
assert load_forge_config(forge_yml_alt)["recipe_dir"] == "recipe"


def test_cos7_env_render(py_recipe, jinja_env):
Expand Down

0 comments on commit 2a082a7

Please sign in to comment.