Skip to content

Commit 00ecadc

Browse files
committed
use selectors and get rid of conda_build_config indirection
1 parent a893f82 commit 00ecadc

File tree

1 file changed

+23
-44
lines changed

1 file changed

+23
-44
lines changed

src/maintainer/knowledge_base.rst

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,19 +1043,15 @@ Noarch packages with OS-specific dependencies
10431043

10441044
It is possible to build ``noarch`` packages with runtime requirements that depend on the target OS
10451045
(Linux, Windows, MacOS), regardless the architecture (amd64, ARM, PowerPC, etc). This approach
1046-
relies on four concepts:
1046+
relies on three concepts:
10471047

10481048
1. `Virtual packages <https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-virtual.html>`__.
10491049
Prefixed with a double underscore, they are used by conda to represent system properties as
10501050
constraints for the solver at install-time. We will use ``__linux``, ``__win`` or ``__osx``,
10511051
which are only present when the running platform is Linux, Windows, or MacOS, respectively.
10521052
``__unix`` is present in both Linux and MacOS. Note that this feature is **only fully available
10531053
on conda 4.10 or above**.
1054-
2. Jinja ``{% if ... %}`` conditionals, which can be used to mimic platform selectors.
1055-
3. ``conda-forge.ymls``'s :ref:`noarch_platforms` option.
1056-
4. `conda-build variants <https://docs.conda.io/projects/conda-build/en/latest/resources/variants.html>`__.
1057-
We can use ``conda_build_config.yaml`` to create a matrix build that depends on the
1058-
``noarch_platforms`` values.
1054+
2. ``conda-forge.ymls``'s :ref:`noarch_platforms` option.
10591055

10601056
The idea is to generate different noarch packages for each OS needing different dependencies.
10611057
Let's say you have a pure Python package, perfectly eligible for ``noarch: python``, but on Windows
@@ -1088,32 +1084,25 @@ to two outputs if replace it with this other approach!
10881084
# ...
10891085
build:
10901086
number: 0
1091-
# You can include target_os in the build string for easier identification of builds
1092-
string: "{{ target_os }}_pyh{{ PKG_HASH }}_{{ PKG_BUILDNUM }}"
1087+
# You NEED to include the platform in the build string to avoid hash collisions
1088+
string: "unix_pyh{{ PKG_HASH }}_{{ PKG_BUILDNUM }}" # [unix]
1089+
string: "win_pyh{{ PKG_HASH }}_{{ PKG_BUILDNUM }}" # [win]
10931090
noarch: python
10941091
requirements:
10951092
# ...
10961093
run:
10971094
- python
10981095
- numpy
1099-
- __{{ target_os }}
1100-
{% if target_os == 'win' %}
1101-
- windows-only-dependency
1102-
{% endif %}
1103-
1104-
Cool! Where does ``target_os`` come from? We need to define it in ``conda_build_config.yaml``.
1105-
Note how the values have been chosen carefully so they match the virtual packages names:
1106-
1107-
.. code-block:: yaml
1108-
:caption: recipe/conda_build_config.yaml
1096+
- __unix # [unix]
1097+
- __win # [win]
1098+
- windows-only-dependency # [win]
11091099

1110-
target_os:
1111-
- unix # [unix]
1112-
- win # [win]
1100+
Do not forget to specify the platform virtual packages with their selectors!
1101+
Otherwise, the solver will not be able to choose the variants correctly.
11131102

1114-
By default, conda-forge will only build ``noarch`` packages on a ``linux-64`` CI runner, so
1115-
the ``target_os`` matrix would only provide the ``unix`` value (because the ``# [win]`` selector
1116-
would never be true). Fortunately, we can change the default behaviour in ``conda-forge.yml``:
1103+
By default, conda-forge will only build ``noarch`` packages on a ``linux_64`` CI runner, so
1104+
only the ``# [unix]`` selectors would be true. However, we can change this behaviour using
1105+
the ``noarch_platforms`` option in ``conda-forge.yml``:
11171106

11181107
.. code-block:: yaml
11191108
:caption: conda-forge.yml
@@ -1122,12 +1111,10 @@ would never be true). Fortunately, we can change the default behaviour in ``cond
11221111
- linux_64
11231112
- win_64
11241113
1125-
This will provide two runners per package! But since we are using selectors in
1126-
``conda_build_config.yaml``, only one is true at a time. Perfect! All these changes require a
1114+
This will provide two runners per package! Perfect! All these changes require a
11271115
feedstock rerender to be applied. See :ref:`dev_update_rerender`.
11281116

1129-
Last but not least, what if you need conditional dependencies on all three operating systems? Do it
1130-
like this:
1117+
If you need conditional dependencies on all three operating systems, this is how you do it:
11311118

11321119
.. code-block:: yaml+jinja
11331120
:caption: recipe/meta.yaml
@@ -1137,28 +1124,20 @@ like this:
11371124
# ...
11381125
build:
11391126
number: 0
1127+
# You NEED to include the platform in the build string to avoid hash collisions
1128+
string: "{{ SUBDIR.split('-')[0] }}_pyh{{ PKG_HASH }}_{{ PKG_BUILDNUM }}"
11401129
noarch: python
11411130
requirements:
11421131
# ...
11431132
run:
11441133
- python
11451134
- numpy
1146-
- __{{ target_os }}
1147-
{% if target_os == 'osx' %}
1148-
- osx-only-dependency
1149-
{% elif target_os == 'win' %}
1150-
- windows-only-dependency
1151-
{% else %}
1152-
- linux-only-dependency
1153-
{% endif %}
1154-
1155-
.. code-block:: yaml
1156-
:caption: recipe/conda_build_config.yaml
1157-
1158-
target_os:
1159-
- linux # [linux]
1160-
- osx # [osx]
1161-
- win # [win]
1135+
- __linux # [linux]
1136+
- __osx # [osx]
1137+
- __win # [win]
1138+
- linux-only-dependency # [linux]
1139+
- osx-only-dependency # [osx]
1140+
- windows-only-dependency # [win]
11621141

11631142
.. code-block:: yaml
11641143
:caption: conda-forge.yml

0 commit comments

Comments
 (0)