conda-forge / conda-forge-ci-setup-feedstock

A conda-smithy repository for conda-forge-ci-setup.
BSD 3-Clause "New" or "Revised" License
13 stars 52 forks source link

Do not raise an exception if 'defaults' is not in the config #149

Closed mrakitin closed 3 years ago

mrakitin commented 3 years ago

This is a proposed fix for the case when ~/.condarc does not have the defaults channel and only has the conda-forge one (or any other). The problem was originally observed on the OSX build for https://github.com/nsls-ii-forge/hunter-feedstock/pull/8:

Setting up the condarc and mangling the compiler.
+ setup_conda_rc ./ ./recipe ./.ci_support/osx_64_python3.7.yaml

CondaKeyError: 'channels': 'defaults' is not in the 'channels' key of the config file

Traceback (most recent call last):
  File "/Users/runner/miniforge3/bin/setup_conda_rc", line 11, in <module>
    sys.exit(setup_conda_rc())
  File "/Users/runner/miniforge3/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/runner/miniforge3/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/runner/miniforge3/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/runner/miniforge3/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/runner/miniforge3/lib/python3.8/site-packages/conda_forge_ci_setup/build_utils.py", line 106, in setup_conda_rc
    call(["conda", "config", "--remove", "channels", "defaults"])
  File "/Users/runner/miniforge3/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['conda', 'config', '--remove', 'channels', 'defaults']' returned non-zero exit status 1.

That exception breaks the execution flow, and the channels list is not propagated to the ~/.condarc file.

For OSX builds the default configuration contains only the conda-forge channel, which comes from https://github.com/conda-forge/miniforge/blob/ab5909ba786461b79a8e57c227da51d1e8155e54/Miniforge3/construct.yaml#L12 I believe.

It does not happen on Linux builds as it's done via a different code path: https://github.com/nsls-ii-forge/hunter-feedstock/blob/bb6d2285eecbdc6c358e9a9cff2926515e29124c/.scripts/build_steps.sh#L21-L32. That code block generates the ~/.condarc file without channels at all, so the step passes. I haven't looked at how it's done for Windows, but I guess the corresponding .condarc file does not contain the channel list in it.

Steps to reproduce:

I tested the implemented fix with the locally installed version of conda-forge-ci-setup:

$ cat ~/.condarc
channels:
  - conda-forge
$ setup_conda_rc ./ ./recipe ./.ci_support/osx_64_python3.7.yaml

CondaKeyError: 'channels': 'defaults' is not in the 'channels' key of the config file

$ cat ~/.condarc
channels:
  - nsls2forge
  - defaults
  - conda-forge
show_channel_urls: true
conda-forge-linter commented 3 years ago

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

mrakitin commented 3 years ago

Thanks for accepting the fix, @isuruf!

mrakitin commented 3 years ago

@isuruf, what's the procedure for releasing this fix? Just bumping a version or build number in meta.yaml?

jakirkham commented 3 years ago

Bumping the version (should be a patch version bump). Can you please send a PR and link it here?

mrakitin commented 3 years ago

@jakirkham, sure, done via https://github.com/conda-forge/conda-forge-ci-setup-feedstock/pull/150. I should have added that commit to this PR. It's a bit unusual to have the code and feedstock infra in the same repo 🙂. Will do it next time.

mrakitin commented 3 years ago

I'm confirming that the fix did its job, and now there is no exception raised: https://dev.azure.com/nsls2forge/nsls2forge/_build/results?buildId=8010&view=logs&j=9c5ef928-2cd6-52e5-dbe6-9d173a7d951b&t=20c71c51-4b27-578b-485d-06ade2de1d00&l=316 (it's the build log for https://github.com/nsls-ii-forge/hunter-feedstock/pull/8). There is only this output (which is OK):

CondaKeyError: 'channels': 'defaults' is not in the 'channels' key of the config file