Repository: conda-forge/conda-smithy

Issue:
mpich not showing up in ci support file
### Solution to issue cannot be found in the documentation.

- [X] I checked the documentation.

### Issue

This recipe doesn't appear to be rendered properly or our docs on mpi are wrong:

```
{% set name = "cosmosis" %}
{% set version = "0.5.16" %}

package:
  name: {{ name|lower }}
  version: {{ version }}

source:
  url:  https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz
  sha256: bfab54a67338b2db80017b69ca60728893d8622cfe3933b1dc7539cb0cd35d09

build:
  number: 2
  skip: True  # [(py < 36) or win]
  script:   "{{ PYTHON }} -m pip install . -vv"


requirements:
  build:
    - {{ compiler('c') }}
    - {{ compiler('fortran') }}
    - {{ compiler('cxx') }}
    - make
    - llvm-openmp  # [osx]
    - libgomp      # [linux]    
  host:
    - python
    - pip
    - wheel
    - {{ mpi }}
    - liblapack
    - libblas
    - minuit2_standalone
  run:
    # core
    - python
    - mpi4py
    - matplotlib-base
    - future
    - numpy
    - pip
    - pybind11
    - pyyaml
    - scipy
    - setuptools
    - threadpoolctl
    - git
    # for samplers
    - emcee
    - dynesty
    - minuit2_standalone
    - zeus-mcmc

test:
  imports:
    - cosmosis
  commands:
    - test -f ${SP_DIR}/cosmosis/samplers/multinest/multinest_src/libnest3.so
    - test -f ${SP_DIR}/cosmosis/samplers/multinest/multinest_src/libnest3_mpi.so
    - test -f ${SP_DIR}/cosmosis/samplers/polychord/polychord_src/libchord.so
    - test -f ${SP_DIR}/cosmosis/samplers/polychord/polychord_src/libchord_mpi.so
    - source cosmosis-configure && pytest --pyargs cosmosis
  requires:
    - pytest

about:
  home: https://github.com/joezuntz/cosmosis
  license: BSD-2-Clause AND LicenseRef-non-commerical-use-only
  license_family: BSD
  license_file:
    - LICENSE
    - cosmosis/samplers/multinest/multinest_src/LICENCE
    - cosmosis/samplers/polychord/polychord_src/LICENCE

  summary: The Cosmological Survey Inference System
  description: |
    CosmoSIS is a framework designed primarily for cosmological
    parameter estimation.
  doc_url: https://cosmosis.readthedocs.io/
  dev_url: https://github.com/joezuntz/cosmosis

extra:
  recipe-maintainers:
    - joezuntz

```

The ci support file is 

```
c_compiler:
- gcc
c_compiler_version:
- '10'
cdt_name:
- cos6
channel_sources:
- conda-forge
channel_targets:
- conda-forge main
cxx_compiler:
- gxx
cxx_compiler_version:
- '10'
docker_image:
- quay.io/condaforge/linux-anvil-cos7-x86_64
fortran_compiler:
- gfortran
fortran_compiler_version:
- '10'
libblas:
- 3.8 *netlib
liblapack:
- 3.8 *netlib
mpi:
- mpich
pin_run_as_build:
  python:
    min_pin: x.x
    max_pin: x.x
python:
- 3.10.* *_cpython
target_platform:
- linux-64
zip_keys:
- - c_compiler_version
  - cxx_compiler_version
  - fortran_compiler_version
```

I don't see the mpich pin at 3 there and I think it should be. We haven't shipped a new major MPI version in a long time and so this bug has been silent. 

### Installed packages

```shell
https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=467822&view=logs&j=4f922444-fdfe-5dcf-b824-02f86439ef14&t=b2a8456a-fb11-5506-ca32-5ccd32538dc0&l=169
```


### Environment info

```shell
https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=467822&view=logs&j=4f922444-fdfe-5dcf-b824-02f86439ef14&t=b2a8456a-fb11-5506-ca32-5ccd32538dc0&l=350
```



Discussion:
conda render works correctly if the pin in present, so this is a bug in smithy itself. 
According to @isuruf we need to change smithy to take two passes at recipes to pull out all pins, variables, etc. instead of the one pass it does now. IDK exactly where to make the change yet. 
I think this is as simple as adding `mpich` and `openmpi` to the `all_used_vars` set if `meta.get_used_vars()` include `mpi`. See https://github.com/conda-forge/conda-smithy/blob/main/conda_smithy/configure_feedstock.py#L273

Resolving patch:
diff --git a/conda_smithy/configure_feedstock.py b/conda_smithy/configure_feedstock.py
--- a/conda_smithy/configure_feedstock.py
+++ b/conda_smithy/configure_feedstock.py
@@ -271,6 +271,13 @@ def _collapse_subpackage_variants(
 
     for meta in list_of_metas:
         all_used_vars.update(meta.get_used_vars())
+        # this is a hack to work around the fact that we specify mpi variants
+        # via an `mpi` variable in the CBC but we do not parse our recipes
+        # twice to ensure the pins given by the variant also show up in the
+        # smithy CI support scripts
+        # future MPI variants have to be added here
+        if "mpi" in all_used_vars:
+            all_used_vars.update(["mpich", "openmpi"])
         all_variants.update(
             conda_build.utils.HashableDict(v) for v in meta.config.variants
         )


Test patch: