Skip to content

Commit b6b6dfb

Browse files
committed
ENH: Handle input parameter for Python minor version
Allows the user to specify `python3-minor-versions` to set Python 3.x targets for module wheel packaging. Python versions 3.7 through 3.11 are set as default according to Python maintenance schedule. Notebook tests are also updated to test the x64 module wheel corresponding to the first specified Python version. https://devguide.python.org/versions/
1 parent c49dd39 commit b6b6dfb

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

.github/workflows/build-test-package-python.yml

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ on:
3030
# example: InsightSoftwareConsortium/ITKMeshToPolyData@3ad8f08:InsightSoftwareConsortium/ITKBSplineGradient@0.3.0
3131
required: false
3232
type: string
33+
python3-minor-versions:
34+
description: 'JSON-formatted array of Python 3.x minor version wheel targets'
35+
required: false
36+
type: string
37+
default: '["7","8","9","10","11"]'
3338
manylinux-platforms:
3439
description: 'JSON-formatted array of "<manylinux-image>-<arch>" specializations'
3540
required: false
@@ -51,7 +56,7 @@ jobs:
5156
strategy:
5257
max-parallel: 2
5358
matrix:
54-
python-version: ["37", "38", "39", "310", "311"]
59+
python3-minor-version: ${{ fromJSON(inputs.python3-minor-versions) }}
5560
manylinux-platform: ${{ fromJSON(inputs.manylinux-platforms) }}
5661

5762
steps:
@@ -94,9 +99,10 @@ jobs:
9499
export MANYLINUX_VERSION=`(echo ${MANYLINUX_PLATFORM} | cut -d '-' -f 1)`
95100
export TARGET_ARCH=`(echo ${MANYLINUX_PLATFORM} | cut -d '-' -f 2)`
96101
echo "Building for manylinux specialization ${MANYLINUX_VERSION} and target architecture ${TARGET_ARCH}"
97-
./dockcross-manylinux-download-cache-and-build-module-wheels.sh cp${{ matrix.python-version }} $CMAKE_OPTIONS
98102
99-
- name: Set up Python 3.10
103+
./dockcross-manylinux-download-cache-and-build-module-wheels.sh cp3${{ matrix.python3-minor-version }} $CMAKE_OPTIONS
104+
105+
- name: Set up Python 3.10 for Validation
100106
uses: actions/setup-python@v4
101107
with:
102108
python-version: "3.10"
@@ -113,23 +119,23 @@ jobs:
113119
if [[ ${TARGET_ARCH_NAME} == "x64" ]]; then
114120
TARGET_ARCH_NAME="x86_64" # Match auditwheel naming convention
115121
fi
116-
WHEEL_PATTERN="dist/itk_*cp${{ matrix.python-version }}*manylinux${MANYLINUX_VERSION}*${TARGET_ARCH_NAME}.whl"
122+
WHEEL_PATTERN="dist/itk_*cp3${{ matrix.python3-minor-version }}*manylinux${MANYLINUX_VERSION}*${TARGET_ARCH_NAME}.whl"
117123
118124
echo "Searching for wheels matching pattern ${WHEEL_PATTERN}"
119125
python -m twine check ${WHEEL_PATTERN}
120126
121127
- name: Publish Python package as GitHub Artifact
122128
uses: actions/upload-artifact@v3
123129
with:
124-
name: LinuxWheel${{ matrix.python-version }}
130+
name: LinuxWheel3${{ matrix.python3-minor-version }}
125131
path: dist/*.whl
126132

127133
build-macos-py:
128134
runs-on: macos-12
129135
strategy:
130136
max-parallel: 2
131137
matrix:
132-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
138+
python3-minor-version: ${{ fromJSON(inputs.python3-minor-versions) }}
133139

134140
steps:
135141
- uses: actions/checkout@v3
@@ -163,9 +169,9 @@ jobs:
163169
else
164170
CMAKE_OPTIONS="--cmake_options ${{ inputs.cmake-options }}"
165171
fi
166-
./macpython-download-cache-and-build-module-wheels.sh $CMAKE_OPTIONS "${{ matrix.python-version }}"
172+
./macpython-download-cache-and-build-module-wheels.sh $CMAKE_OPTIONS "3.${{ matrix.python3-minor-version }}"
167173
168-
- name: Set up Python 3.10
174+
- name: Set up Python 3.10 for Validation
169175
uses: actions/setup-python@v4
170176
with:
171177
python-version: "3.10"
@@ -190,15 +196,15 @@ jobs:
190196
- name: Publish Python package as GitHub Artifact
191197
uses: actions/upload-artifact@v3
192198
with:
193-
name: MacOSWheels
199+
name: MacOSWheel3${{ matrix.python3-minor-version }}
194200
path: dist/*.whl
195201

196202
build-windows-python-packages:
197203
runs-on: windows-2022
198204
strategy:
199205
max-parallel: 2
200206
matrix:
201-
python-version-minor: ["7", "8", "9", "10", "11"]
207+
python3-minor-version: ${{ fromJSON(inputs.python3-minor-versions) }}
202208

203209
steps:
204210
- name: Get specific version of CMake, Ninja
@@ -237,31 +243,32 @@ jobs:
237243
$env:ITKPYTHONPACKAGE_TAG = "${{ inputs.itk-python-package-tag }}"
238244
$env:ITKPYTHONPACKAGE_ORG = "${{ inputs.itk-python-package-org }}"
239245
$env:ITK_MODULE_PREQ = "${{ inputs.itk-module-deps }}"
240-
./windows-download-cache-and-build-module-wheels.ps1 "${{ matrix.python-version-minor }}" -cmake_options "${{ inputs.cmake-options }}"
246+
247+
./windows-download-cache-and-build-module-wheels.ps1 "${{ matrix.python3-minor-version }}" -cmake_options "${{ inputs.cmake-options }}"
241248
242249
mkdir -p '${{ github.workspace }}\dist'
243250
cp 'dist\*.whl' '${{ github.workspace }}\dist'
244251
245-
- name: Set up Python 3.10
252+
- name: Set up Python 3.10 for Validation
246253
uses: actions/setup-python@v4
247254
with:
248255
python-version: "3.10"
249256

250257
- name: Validate build output
251-
shell: bash
258+
shell: pwsh
252259
run: |
253260
python -m pip install twine
254261
ls dist/
255262
256-
WHEEL_PATTERN="dist/itk_*cp3${{ matrix.python-version-minor }}*win*.whl"
263+
$WHEEL_PATTERN = "dist/itk_*cp3${{ matrix.python3-minor-version }}*win*.whl"
257264
echo "Searching for wheels matching pattern ${WHEEL_PATTERN}"
258265
259266
python -m twine check ${WHEEL_PATTERN}
260267
261268
- name: Publish Python package as GitHub Artifact
262269
uses: actions/upload-artifact@v3
263270
with:
264-
name: WindowsWheel3.${{ matrix.python-version-minor }}
271+
name: WindowsWheel3${{ matrix.python3-minor-version }}
265272
path: dist/*.whl
266273

267274
test-linux-notebooks:
@@ -275,7 +282,7 @@ jobs:
275282

276283
- uses: actions/setup-python@v4
277284
with:
278-
python-version: '3.10'
285+
python-version: "3.${{ fromJSON(inputs.python3-minor-versions)[0] }}"
279286

280287
- name: Install build dependencies
281288
shell: bash
@@ -290,12 +297,12 @@ jobs:
290297
- name: Download Python Package Artifacts
291298
uses: actions/download-artifact@v3
292299
with:
293-
name: LinuxWheel310
300+
name: LinuxWheel3${{ fromJSON(inputs.python3-minor-versions)[0] }}
294301

295302
- name: Install Python Package Artifact
296303
run: |
297304
ls .
298-
wheel_name_full=`(find . -name "*cp310-manylinux_2_28_x86_64.whl")`
305+
wheel_name_full=`(find . -name "*cp3${{ fromJSON(inputs.python3-minor-versions)[0] }}*-manylinux_2_28_x86_64.whl")`
299306
echo "wheel_name_full ${wheel_name_full}"
300307
# extract wheel name which may be an abbreviation of the module name
301308
# ex. ./itk_splitcomponents-cp310..._64.whl -> itk-splitcomponents

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ to direct workflow execution.
283283
itk-module-deps: 'InsightSoftwareConsortium/ITKMeshToPolyData@3ad8f08:InsightSoftwareConsortium/ITKBSplineGradient@0.3.0'
284284
```
285285

286+
- `python3-minor-versions`: Array of Python 3.x wheel minor versions to target for building.
287+
The array follows [JavaScript Object Notation (JSON)](https://www.json.org/json-en.html) syntax
288+
and GHA jobs will launch in the order provided. One wheel is built per Python version and
289+
target platform. The first listed Python version may also be used for running Linux notebook tests
290+
if enabled. The default value is a list of [currently supported Python versions](https://devguide.python.org/versions/)
291+
ascending from oldest to newest.
292+
293+
```yaml
294+
with:
295+
python3-minor-versions: '["7","8","9","10","11"]` # Builds for Python 3.7 through 3.11
296+
```
297+
286298
- `manylinux-platforms`: Array of [manylinux](https://github.com/pypa/manylinux)
287299
specialization build targets for Linux Python module wheels. Manylinux "provides
288300
a convenient way to distribute binary Python extensions as wheels on Linux";
@@ -304,7 +316,9 @@ to direct workflow execution.
304316
- `test-notebooks`: Boolean option to test Jupyter Notebook examples located in the
305317
`examples/` directory of the external module. A `requirements.txt` file
306318
should be provided in either the external module root or `binder/` directories
307-
to indicate notebook prerequisites for testing. Default value is `false`, notebook
319+
to indicate notebook prerequisites for testing. The first Python version listed in
320+
`python3-minor-versions` will be used, i.e. if "9" is listed first then notebook
321+
tests will be run with Python 3.9. Default value is `false`, notebook
308322
tests may be enabled for a repository containing notebook examples by setting
309323
the value to `true`.
310324

0 commit comments

Comments
 (0)