@@ -1043,19 +1043,15 @@ Noarch packages with OS-specific dependencies
1043
1043
1044
1044
It is possible to build ``noarch `` packages with runtime requirements that depend on the target OS
1045
1045
(Linux, Windows, MacOS), regardless the architecture (amd64, ARM, PowerPC, etc). This approach
1046
- relies on four concepts:
1046
+ relies on three concepts:
1047
1047
1048
1048
1. `Virtual packages <https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-virtual.html >`__.
1049
1049
Prefixed with a double underscore, they are used by conda to represent system properties as
1050
1050
constraints for the solver at install-time. We will use ``__linux ``, ``__win `` or ``__osx ``,
1051
1051
which are only present when the running platform is Linux, Windows, or MacOS, respectively.
1052
1052
``__unix `` is present in both Linux and MacOS. Note that this feature is **only fully available
1053
1053
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.
1059
1055
1060
1056
The idea is to generate different noarch packages for each OS needing different dependencies.
1061
1057
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!
1088
1084
# ...
1089
1085
build:
1090
1086
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]
1093
1090
noarch: python
1094
1091
requirements:
1095
1092
# ...
1096
1093
run:
1097
1094
- python
1098
1095
- 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]
1109
1099
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.
1113
1102
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 ``:
1117
1106
1118
1107
.. code-block :: yaml
1119
1108
:caption : conda-forge.yml
@@ -1122,12 +1111,10 @@ would never be true). Fortunately, we can change the default behaviour in ``cond
1122
1111
- linux_64
1123
1112
- win_64
1124
1113
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
1127
1115
feedstock rerender to be applied. See :ref: `dev_update_rerender `.
1128
1116
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:
1131
1118
1132
1119
.. code-block :: yaml+jinja
1133
1120
:caption: recipe/meta.yaml
@@ -1137,28 +1124,20 @@ like this:
1137
1124
# ...
1138
1125
build:
1139
1126
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 }}"
1140
1129
noarch: python
1141
1130
requirements:
1142
1131
# ...
1143
1132
run:
1144
1133
- python
1145
1134
- 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]
1162
1141
1163
1142
.. code-block :: yaml
1164
1143
:caption : conda-forge.yml
0 commit comments