Skip to content

Commit d598fd2

Browse files
committed
add conda-forge workflow
1 parent 75a4627 commit d598fd2

File tree

5 files changed

+444
-0
lines changed

5 files changed

+444
-0
lines changed
Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
name: Conda package
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
permissions: read-all
10+
11+
env:
12+
PACKAGE_NAME: mkl-service
13+
MODULE_NAME: mkl
14+
TEST_ENV_NAME: test_mkl_service
15+
VER_SCRIPT1: "import json; f = open('ver.json', 'r'); j = json.load(f); f.close(); "
16+
VER_SCRIPT2: "d = j['mkl-service'][0]; print('='.join((d[s] for s in ('version', 'build'))))"
17+
18+
jobs:
19+
build_linux:
20+
runs-on: ubuntu-latest
21+
22+
strategy:
23+
matrix:
24+
python: ['3.10', '3.11', '3.12', '3.13', '3.14']
25+
26+
steps:
27+
- name: Cancel Previous Runs
28+
uses: styfle/cancel-workflow-action@3155a141048f8f89c06b4cdae32e7853e97536bc # 0.13.0
29+
with:
30+
access_token: ${{ github.token }}
31+
32+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
33+
with:
34+
fetch-depth: 0
35+
36+
- name: Set pkgs_dirs
37+
run: |
38+
echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc
39+
40+
- name: Cache conda packages
41+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
42+
env:
43+
CACHE_NUMBER: 0 # Increase to reset cache
44+
with:
45+
path: ~/.conda/pkgs
46+
key:
47+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('**/meta.yaml') }}
48+
restore-keys: |
49+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
50+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
51+
52+
- name: Add conda to system path
53+
run: echo "$CONDA/bin" >> "$GITHUB_PATH"
54+
55+
- name: Install conda-build
56+
run: conda install conda-build
57+
58+
- name: Store conda paths as envs
59+
shell: bash -el {0}
60+
run: |
61+
echo "CONDA_BLD=/usr/share/miniconda/conda-bld/linux-64/" >> "$GITHUB_ENV"
62+
echo "WHEELS_OUTPUT_FOLDER=$GITHUB_WORKSPACE/" >> "$GITHUB_ENV"
63+
64+
- name: Build conda package
65+
run: |
66+
CHANNELS=(-c conda-forge -c conda-forge/label/python_rc --override-channels)
67+
VERSIONS=(--python "${{ matrix.python }}")
68+
TEST=(--no-test)
69+
70+
conda build \
71+
"${TEST[@]}" \
72+
"${VERSIONS[@]}" \
73+
"${CHANNELS[@]}" \
74+
conda-recipe
75+
76+
- name: Upload artifact
77+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
78+
with:
79+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
80+
path: ${{ env.CONDA_BLD }}${{ env.PACKAGE_NAME }}-*.conda
81+
82+
- name: Upload wheels artifact
83+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
84+
with:
85+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Wheels Python ${{ matrix.python }}
86+
path: ${{ env.WHEELS_OUTPUT_FOLDER }}mkl_service-*.whl
87+
88+
build_windows:
89+
runs-on: windows-latest
90+
91+
strategy:
92+
matrix:
93+
python: ['3.10', '3.11', '3.12', '3.13', '3.14']
94+
95+
steps:
96+
- name: Cancel Previous Runs
97+
uses: styfle/cancel-workflow-action@3155a141048f8f89c06b4cdae32e7853e97536bc # 0.13.0
98+
with:
99+
access_token: ${{ github.token }}
100+
101+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
102+
with:
103+
fetch-depth: 0
104+
- uses: conda-incubator/setup-miniconda@fc2d68f6413eb2d87b895e92f8584b5b94a10167 # v3.3.0
105+
with:
106+
miniforge-version: latest
107+
use-mamba: 'true'
108+
conda-remove-defaults: 'true'
109+
activate-environment: 'build'
110+
python-version: '3.13' # no python 3.14 support by conda-build
111+
112+
- name: Cache conda packages
113+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
114+
env:
115+
CACHE_NUMBER: 3 # Increase to reset cache
116+
with:
117+
path: /home/runner/conda_pkgs_dir
118+
key:
119+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('**/meta.yaml') }}
120+
restore-keys: |
121+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
122+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
123+
124+
- name: Install conda-build
125+
run: conda install conda-build
126+
127+
- name: Store conda paths as envs
128+
shell: bash -el {0}
129+
run: |
130+
echo "CONDA_BLD=$CONDA_PREFIX\\conda-bld\\win-64\\" >> "$GITHUB_ENV"
131+
echo "WHEELS_OUTPUT_FOLDER=$GITHUB_WORKSPACE\\" >> "$GITHUB_ENV"
132+
133+
- name: Build conda package
134+
run: conda build --no-test --python ${{ matrix.python }} -c conda-forge -c conda-forge/label/python_rc --override-channels conda-recipe
135+
136+
- name: Upload artifact
137+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
138+
with:
139+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
140+
path: ${{ env.CONDA_BLD }}${{ env.PACKAGE_NAME }}-*.conda
141+
142+
- name: Upload wheels artifact
143+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
144+
with:
145+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Wheels Python ${{ matrix.python }}
146+
path: ${{ env.WHEELS_OUTPUT_FOLDER }}mkl_service-*.whl
147+
148+
test_linux:
149+
needs: build_linux
150+
runs-on: ${{ matrix.runner }}
151+
152+
strategy:
153+
matrix:
154+
python: ['3.10', '3.11', '3.12', '3.13', '3.14']
155+
experimental: [false]
156+
runner: [ubuntu-latest]
157+
continue-on-error: ${{ matrix.experimental }}
158+
env:
159+
CHANNELS: -c conda-forge -c conda-forge/label/python_rc --override-channels
160+
161+
steps:
162+
- name: Download artifact
163+
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
164+
with:
165+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
166+
167+
- name: Add conda to system path
168+
run: echo "$CONDA/bin" >> "$GITHUB_PATH"
169+
170+
- name: Install conda-build
171+
run: conda install conda-build
172+
173+
- name: Create conda channel
174+
run: |
175+
mkdir -p "$GITHUB_WORKSPACE/channel/linux-64"
176+
conda index "$GITHUB_WORKSPACE/channel" || exit 1
177+
mv "${PACKAGE_NAME}"-*.conda "$GITHUB_WORKSPACE/channel/linux-64" || exit 1
178+
conda index "$GITHUB_WORKSPACE/channel" || exit 1
179+
# Test channel
180+
conda search "$PACKAGE_NAME" -c "$GITHUB_WORKSPACE/channel" --override-channels --info --json > "$GITHUB_WORKSPACE/ver.json"
181+
cat ver.json
182+
183+
- name: Collect dependencies
184+
run: |
185+
. "$CONDA/etc/profile.d/conda.sh"
186+
CHANNELS=(-c "$GITHUB_WORKSPACE/channel" -c conda-forge -c conda-forge/label/python_rc --override-channels)
187+
PACKAGE_VERSION="$(python -c "${VER_SCRIPT1} ${VER_SCRIPT2}")"
188+
export PACKAGE_VERSION
189+
conda create -n "${{ env.TEST_ENV_NAME }}" "$PACKAGE_NAME=$PACKAGE_VERSION" "python=${{ matrix.python }}" "${CHANNELS[@]}" --only-deps --dry-run > lockfile
190+
cat lockfile
191+
192+
- name: Set pkgs_dirs
193+
run: |
194+
echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc
195+
196+
- name: Cache conda packages
197+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
198+
env:
199+
CACHE_NUMBER: 0 # Increase to reset cache
200+
with:
201+
path: ~/.conda/pkgs
202+
key:
203+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }}
204+
restore-keys: |
205+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
206+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
207+
208+
- name: Install mkl-service
209+
run: |
210+
. "$CONDA/etc/profile.d/conda.sh"
211+
CHANNELS=(-c "$GITHUB_WORKSPACE/channel" -c conda-forge -c conda-forge/label/python_rc --override-channels)
212+
PACKAGE_VERSION="$(python -c "${VER_SCRIPT1} ${VER_SCRIPT2}")"
213+
export PACKAGE_VERSION
214+
conda create -n "${{ env.TEST_ENV_NAME }}" "$PACKAGE_NAME=$PACKAGE_VERSION" pytest "python=${{ matrix.python }}" "${CHANNELS[@]}"
215+
# Test installed packages
216+
conda list
217+
218+
- name: Run tests
219+
run: |
220+
. "$CONDA/etc/profile.d/conda.sh"
221+
conda activate ${{ env.TEST_ENV_NAME }}
222+
pytest -vv --pyargs ${{ env.MODULE_NAME }}
223+
224+
test_windows:
225+
needs: build_windows
226+
runs-on: ${{ matrix.runner }}
227+
228+
strategy:
229+
matrix:
230+
python: ['3.10', '3.11', '3.12', '3.13', '3.14']
231+
experimental: [false]
232+
runner: [windows-latest]
233+
continue-on-error: ${{ matrix.experimental }}
234+
env:
235+
CHANNELS: -c conda-forge -c conda-forge/label/python_rc --override-channels
236+
237+
steps:
238+
- name: Download artifact
239+
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
240+
with:
241+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
242+
- uses: conda-incubator/setup-miniconda@fc2d68f6413eb2d87b895e92f8584b5b94a10167 # v3.3.0
243+
with:
244+
miniforge-version: latest
245+
use-mamba: 'true'
246+
conda-remove-defaults: 'true'
247+
activate-environment: 'test'
248+
python-version: '3.13' # no python 3.14 support by conda-index
249+
250+
- name: Install conda-index
251+
run: conda install conda-index
252+
253+
- name: Create conda channel
254+
run: |
255+
mkdir ${{ env.GITHUB_WORKSPACE }}/channel/win-64
256+
move ${{ env.PACKAGE_NAME }}-*.conda ${{ env.GITHUB_WORKSPACE }}/channel/win-64
257+
python -m conda_index "${{ env.GITHUB_WORKSPACE }}/channel"
258+
259+
# Test channel
260+
conda search ${{ env.PACKAGE_NAME }} -c ${{ env.GITHUB_WORKSPACE }}/channel --override-channels --info --json > ${{ env.GITHUB_WORKSPACE }}/ver.json
261+
more ${{ env.GITHUB_WORKSPACE }}/ver.json
262+
263+
- name: Collect dependencies
264+
shell: cmd
265+
run: |
266+
@ECHO ON
267+
copy /Y ${{ env.GITHUB_WORKSPACE }}\ver.json .
268+
set "SCRIPT=%VER_SCRIPT1% %VER_SCRIPT2%"
269+
FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "%SCRIPT%"`) DO (
270+
SET PACKAGE_VERSION=%%F
271+
)
272+
conda create -n ${{ env.TEST_ENV_NAME }} ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% python=${{ matrix.python }} -c ${{ env.GITHUB_WORKSPACE }}/channel ${{ env.CHANNELS }} --only-deps --dry-run > lockfile
273+
more lockfile
274+
275+
- name: Cache conda packages
276+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
277+
env:
278+
CACHE_NUMBER: 3 # Increase to reset cache
279+
with:
280+
path: /home/runner/conda_pkgs_dir
281+
key:
282+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }}
283+
restore-keys: |
284+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
285+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
286+
287+
- name: Install mkl-service
288+
shell: cmd
289+
run: |
290+
@ECHO ON
291+
copy /Y ${{ env.GITHUB_WORKSPACE }}\ver.json .
292+
set "SCRIPT=%VER_SCRIPT1% %VER_SCRIPT2%"
293+
FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "%SCRIPT%"`) DO (
294+
SET PACKAGE_VERSION=%%F
295+
)
296+
conda create -n ${{ env.TEST_ENV_NAME }} ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% pytest python=${{ matrix.python }} -c ${{ env.GITHUB_WORKSPACE }}/channel ${{ env.CHANNELS }}
297+
# Test installed packages
298+
conda list
299+
300+
- name: Run tests
301+
run: |
302+
conda activate -n ${{ env.TEST_ENV_NAME }}
303+
pytest -v --pyargs ${{ env.MODULE_NAME }}

conda-recipe-cf/bld.bat

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
echo on
2+
rem set CFLAGS=-I%PREFIX%\Library\include %CFLAGS%
3+
rem set LDFLAGS=/LIBPATH:%PREFIX% %LDFLAGS%
4+
5+
set MKLROOT=%CONDA_PREFIX%
6+
7+
"%PYTHON%" setup.py clean --all
8+
9+
:: Make CMake verbose
10+
set "VERBOSE=1"
11+
12+
:: -wnx flags mean: --wheel --no-isolation --skip-dependency-check
13+
%PYTHON% -m build -w -n -x
14+
if %ERRORLEVEL% neq 0 exit 1
15+
16+
:: wheel file was renamed
17+
for /f %%f in ('dir /b /S .\dist') do (
18+
%PYTHON% -m pip install %%f ^
19+
--no-build-isolation ^
20+
--no-deps ^
21+
--only-binary :all: ^
22+
--no-index ^
23+
--prefix %PREFIX% ^
24+
-vv
25+
if %ERRORLEVEL% neq 0 exit 1
26+
)
27+
28+
:: Copy wheel package
29+
if NOT "%WHEELS_OUTPUT_FOLDER%"=="" (
30+
copy dist\mkl_service*.whl %WHEELS_OUTPUT_FOLDER%
31+
if %ERRORLEVEL% neq 0 exit 1
32+
)

conda-recipe-cf/build.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
export MKLROOT=$CONDA_PREFIX
5+
6+
read -r GLIBC_MAJOR GLIBC_MINOR <<<"$(conda list '^sysroot_linux-64$' \
7+
| tail -n 1 | awk '{print $2}' | grep -oP '\d+' | head -n 2 | tr '\n' ' ')"
8+
9+
${PYTHON} setup.py clean --all
10+
11+
# Make CMake verbose
12+
export VERBOSE=1
13+
14+
# -wnx flags mean: --wheel --no-isolation --skip-dependency-check
15+
${PYTHON} -m build -w -n -x
16+
17+
${PYTHON} -m wheel tags --remove \
18+
--platform-tag "manylinux_${GLIBC_MAJOR}_${GLIBC_MINOR}_x86_64" \
19+
dist/mkl_service*.whl
20+
21+
${PYTHON} -m pip install dist/mkl_service*.whl \
22+
--no-build-isolation \
23+
--no-deps \
24+
--only-binary :all: \
25+
--no-index \
26+
--prefix "${PREFIX}" \
27+
-vv
28+
29+
# Copy wheel package
30+
if [[ -d "${WHEELS_OUTPUT_FOLDER}" ]]; then
31+
cp dist/mkl_service*.whl "${WHEELS_OUTPUT_FOLDER[@]}"
32+
fi
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
c_compiler: # [linux]
2+
- gcc # [linux]
3+
cxx_compiler: # [linux]
4+
- gxx # [linux]
5+
cxx_compiler_version: # [linux]
6+
- '14' # [linux]
7+
c_stdlib: # [linux]
8+
- sysroot # [linux]
9+
c_stdlib_version: # [linux]
10+
- '2.28' # [linux]
11+
c_stdlib: # [win]
12+
- vs # [win]
13+
cxx_compiler: # [win]
14+
- vs2022 # [win]
15+
c_compiler: # [win]
16+
- vs2022 # [win]

0 commit comments

Comments
 (0)