Skip to content

Commit 0aee3cf

Browse files
author
Vahid Tavanashad
committed
add a new workflow
1 parent 13967b9 commit 0aee3cf

File tree

6 files changed

+445
-77
lines changed

6 files changed

+445
-77
lines changed

.github/workflows/build_pip.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Editable build using pip and pre-release NumPy
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
permissions: read-all
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
defaults:
15+
run:
16+
shell: bash -el {0}
17+
18+
strategy:
19+
matrix:
20+
python: ['3.9', '3.10', '3.11', '3.12']
21+
use_pre: ["", "--pre"]
22+
23+
steps:
24+
- name: Install jq
25+
shell: bash -l {0}
26+
run: |
27+
sudo apt-get install jq
28+
29+
- uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- uses: conda-incubator/setup-miniconda@v3
34+
with:
35+
use-mamba: true
36+
miniforge-version: latest
37+
channels: conda-forge
38+
conda-remove-defaults: true
39+
activate-environment: test
40+
python-version: ${{ matrix.python }}
41+
42+
- name: Install Compiler and MKL
43+
run: |
44+
conda install mkl-devel mkl-service dpcpp_linux-64
45+
python -c "import sys; print(sys.executable)"
46+
which python
47+
python -c "import mkl; print(mkl.__file__)"
48+
49+
- name: Build conda package
50+
run: |
51+
pip install --no-cache-dir scikit-build cmake ninja cython
52+
pip install --no-cache-dir numpy ${{ matrix.use_pre }}
53+
echo "CONDA_PREFFIX is '${CONDA_PREFIX}'"
54+
export MKLROOT=${CONDA_PREFIX}
55+
pip install .[test] --no-build-isolation --verbose
56+
pip list
57+
python -m pytest -v mkl_umath/tests
Lines changed: 311 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
name: Conda package with conda-forge channel only
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
permissions: read-all
10+
11+
env:
12+
PACKAGE_NAME: mkl_umath
13+
TEST_ENV_NAME: test_mkl_umath
14+
VER_SCRIPT1: "import json; f = open('ver.json', 'r'); j = json.load(f); f.close(); d = j['mkl_umath'][0];"
15+
VER_SCRIPT2: "print('='.join((d[s] for s in ('version', 'build'))))"
16+
17+
jobs:
18+
build_linux:
19+
runs-on: ubuntu-latest
20+
21+
strategy:
22+
matrix:
23+
python: ['3.9', '3.10', '3.11', '3.12']
24+
25+
steps:
26+
- name: Cancel Previous Runs
27+
uses: styfle/[email protected]
28+
with:
29+
access_token: ${{ github.token }}
30+
31+
- name: Checkout repo
32+
uses: actions/[email protected]
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/[email protected]
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: Build conda package with NumPy 2.0
59+
run: |
60+
CHANNELS="-c conda-forge --override-channels"
61+
VERSIONS="--python ${{ matrix.python }} --numpy 2.0"
62+
TEST="--no-test"
63+
echo "CONDA_BLD=${CONDA}/conda-bld/linux-64" >> $GITHUB_ENV
64+
65+
conda build \
66+
$TEST \
67+
$VERSIONS \
68+
$CHANNELS \
69+
conda-recipe-cf
70+
71+
- name: Upload artifact
72+
uses: actions/[email protected]
73+
with:
74+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
75+
path: ${{ env.CONDA_BLD }}/${{ env.PACKAGE_NAME }}-*.conda
76+
77+
test_linux:
78+
needs: build_linux
79+
runs-on: ${{ matrix.runner }}
80+
81+
strategy:
82+
matrix:
83+
python: ['3.9', '3.10', '3.11', '3.12']
84+
numpy: ['numpy"<2"', 'numpy">=2"']
85+
experimental: [false]
86+
runner: [ubuntu-latest]
87+
continue-on-error: ${{ matrix.experimental }}
88+
env:
89+
CHANNELS: -c conda-forge --override-channels
90+
91+
steps:
92+
- name: Download artifact
93+
uses: actions/[email protected]
94+
with:
95+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
96+
97+
- name: Add conda to system path
98+
run: echo $CONDA/bin >> $GITHUB_PATH
99+
100+
- name: Install conda-build
101+
run: conda install conda-build
102+
103+
- name: Create conda channel
104+
run: |
105+
mkdir -p $GITHUB_WORKSPACE/channel/linux-64
106+
mv ${PACKAGE_NAME}-*.conda $GITHUB_WORKSPACE/channel/linux-64
107+
conda index $GITHUB_WORKSPACE/channel
108+
# Test channel
109+
conda search $PACKAGE_NAME -c $GITHUB_WORKSPACE/channel --override-channels
110+
111+
- name: Collect dependencies
112+
run: |
113+
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
114+
conda create -n ${{ env.TEST_ENV_NAME }} $PACKAGE_NAME python=${{ matrix.python }} ${{ matrix.numpy }} $CHANNELS --only-deps --dry-run > lockfile
115+
116+
- name: Display lockfile
117+
run: cat lockfile
118+
119+
- name: Set pkgs_dirs
120+
run: |
121+
echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc
122+
123+
- name: Cache conda packages
124+
uses: actions/[email protected]
125+
env:
126+
CACHE_NUMBER: 0 # Increase to reset cache
127+
with:
128+
path: ~/.conda/pkgs
129+
key:
130+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }}
131+
restore-keys: |
132+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
133+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
134+
135+
- name: Install mkl_umath
136+
run: |
137+
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
138+
conda create -n ${{ env.TEST_ENV_NAME }} python=${{ matrix.python }} ${{ matrix.numpy }} $PACKAGE_NAME pytest $CHANNELS
139+
# Test installed packages
140+
conda list -n ${{ env.TEST_ENV_NAME }}
141+
142+
- name: Run tests
143+
run: |
144+
source $CONDA/etc/profile.d/conda.sh
145+
conda activate ${{ env.TEST_ENV_NAME }}
146+
pytest -v --pyargs ${{ env.PACKAGE_NAME }}
147+
148+
build_windows:
149+
runs-on: windows-2019
150+
151+
strategy:
152+
matrix:
153+
python: ['3.9', '3.10', '3.11', '3.12']
154+
steps:
155+
- name: Cancel Previous Runs
156+
uses: styfle/[email protected]
157+
with:
158+
access_token: ${{ github.token }}
159+
160+
- name: checkout repo
161+
uses: actions/[email protected]
162+
with:
163+
fetch-depth: 0
164+
165+
- uses: conda-incubator/setup-miniconda@v3
166+
with:
167+
miniforge-version: latest
168+
activate-environment: build
169+
python-version: ${{ matrix.python }}
170+
channels: conda-forge
171+
conda-remove-defaults: 'true'
172+
173+
- name: Install conda-build
174+
run: conda install -n base conda-build
175+
176+
- name: Cache conda packages
177+
uses: actions/[email protected]
178+
env:
179+
CACHE_NUMBER: 3 # Increase to reset cache
180+
with:
181+
path: /home/runner/conda_pkgs_dir
182+
key:
183+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('**/meta.yaml') }}
184+
restore-keys: |
185+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
186+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
187+
188+
- name: Build conda package with NumPy 2.0
189+
run: |
190+
conda activate
191+
conda build --no-test --python ${{ matrix.python }} --numpy 2.0 -c conda-forge --override-channels conda-recipe-cf
192+
193+
- name: Store conda paths as envs
194+
shell: bash -l {0}
195+
run: |
196+
echo "CONDA_BLD=$CONDA/conda-bld/win-64/" | tr "\\\\" '/' >> $GITHUB_ENV
197+
198+
- name: Upload artifact
199+
uses: actions/[email protected]
200+
with:
201+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
202+
path: ${{ env.CONDA_BLD }}${{ env.PACKAGE_NAME }}-*.conda
203+
204+
test_windows:
205+
needs: build_windows
206+
runs-on: ${{ matrix.runner }}
207+
defaults:
208+
run:
209+
shell: cmd /C CALL {0}
210+
211+
strategy:
212+
matrix:
213+
python: ['3.9', '3.10', '3.11', '3.12']
214+
numpy: ['numpy"<2"', 'numpy">=2"']
215+
experimental: [false]
216+
runner: [windows-2019]
217+
continue-on-error: ${{ matrix.experimental }}
218+
env:
219+
workdir: '${{ github.workspace }}'
220+
CHANNELS: -c conda-forge --override-channels
221+
222+
steps:
223+
- name: Download artifact
224+
uses: actions/[email protected]
225+
with:
226+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
227+
228+
- uses: conda-incubator/setup-miniconda@v3
229+
with:
230+
miniforge-version: latest
231+
activate-environment: ${{ env.TEST_ENV_NAME }}
232+
python-version: ${{ matrix.python }}
233+
channels: conda-forge
234+
conda-remove-defaults: 'true'
235+
236+
- name: Create conda channel with the artifact bit
237+
run: |
238+
echo ${{ env.workdir }}
239+
mkdir ${{ env.workdir }}\channel\
240+
mkdir ${{ env.workdir }}\channel\win-64
241+
move ${{ env.PACKAGE_NAME }}-*.conda ${{ env.workdir }}\channel\win-64
242+
dir ${{ env.workdir }}\channel\win-64
243+
244+
- name: Install conda index
245+
run: conda install -n base conda-index
246+
247+
- name: Index the channel
248+
run: conda index ${{ env.workdir }}\channel
249+
250+
- name: Dump mkl_umath version info from created channel into ver.json
251+
run: |
252+
conda search ${{ env.PACKAGE_NAME }} -c ${{ env.workdir }}/channel --override-channels --info --json > ${{ env.workdir }}\ver.json
253+
254+
- name: Output content of produced ver.json
255+
shell: pwsh
256+
run: Get-Content -Path ${{ env.workdir }}\ver.json
257+
258+
- name: Collect dependencies
259+
run: |
260+
@ECHO ON
261+
IF NOT EXIST ver.json (
262+
copy /Y ${{ env.workdir }}\ver.json .
263+
)
264+
SET "SCRIPT=%VER_SCRIPT1% %VER_SCRIPT2%"
265+
FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "%SCRIPT%"`) DO (
266+
SET PACKAGE_VERSION=%%F
267+
)
268+
conda install -n ${{ env.TEST_ENV_NAME }} ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% python=${{ matrix.python }} ${{ matrix.numpy }} -c ${{ env.workdir }}/channel ${{ env.CHANNELS }} --only-deps --dry-run > lockfile
269+
270+
- name: Display lockfile content
271+
shell: pwsh
272+
run: Get-Content -Path .\lockfile
273+
274+
- name: Cache conda packages
275+
uses: actions/[email protected]
276+
env:
277+
CACHE_NUMBER: 0 # Increase to reset cache
278+
with:
279+
path: /home/runner/conda_pkgs_dir
280+
key:
281+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }}
282+
restore-keys: |
283+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
284+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
285+
286+
# add intel-openmp as an explicit dependency
287+
# to avoid it being missed when package version is specified exactly
288+
- name: Install mkl_umath
289+
run: |
290+
@ECHO ON
291+
IF NOT EXIST ver.json (
292+
copy /Y ${{ env.workdir }}\ver.json .
293+
)
294+
set "SCRIPT=%VER_SCRIPT1% %VER_SCRIPT2%"
295+
FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "%SCRIPT%"`) DO (
296+
SET PACKAGE_VERSION=%%F
297+
)
298+
SET "TEST_DEPENDENCIES=pytest pytest-cov"
299+
SET "WORKAROUND_DEPENDENCIES=intel-openmp"
300+
SET "DEPENDENCIES=%TEST_DEPENDENCIES% %WORKAROUND_DEPENDENCIES%"
301+
conda install -n ${{ env.TEST_ENV_NAME }} ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% %DEPENDENCIES% python=${{ matrix.python }} ${{ matrix.numpy }} -c ${{ env.workdir }}/channel ${{ env.CHANNELS }}
302+
303+
- name: Report content of test environment
304+
run: |
305+
echo "Value of CONDA environment variable was: " %CONDA%
306+
echo "Value of CONDA_PREFIX environment variable was: " %CONDA_PREFIX%
307+
conda info && conda list -n ${{ env.TEST_ENV_NAME }}
308+
309+
- name: Run tests
310+
run: |
311+
conda activate ${{ env.TEST_ENV_NAME }} && python -m pytest -v -s --pyargs ${{ env.PACKAGE_NAME }}

0 commit comments

Comments
 (0)