Skip to content

Commit fa0fb82

Browse files
authored
Build wheels with numpy 1.25+ (#4198)
* Build wheels with numpy 1.25+ * Update CI to: * Use pip install -e * Optionally use build isolation
1 parent b21478f commit fa0fb82

File tree

7 files changed

+74
-27
lines changed

7 files changed

+74
-27
lines changed

.github/actions/build-src/action.yaml

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,40 @@ inputs:
99
description: 'build MDA docs'
1010
required: true
1111
default: false
12+
isolation:
13+
# Details on build isolation can be found here:
14+
# https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/#build-isolation
15+
#
16+
# A short description of how this works in pratice is provided here:
17+
# * If build isolation is on, pip will create wheels for MDAnalysis in a
18+
# fully isolated temporary environment hence making sure that build
19+
# requirements are handled independently of the runtime environment
20+
# (whatever is already in your Python PATH at the time of install).
21+
# For example, with build isolation on, you could have an old version
22+
# of NumPy available in your current Python environment, but build with
23+
# a much newer one.
24+
# * If build isolation is off (through the --no-build-isolation flag), the
25+
# pip build system depends on what is currently avaiable in your Python
26+
# environment. So if NumPy is necessary and you have a version already
27+
# installed, it will just use that directly. There is a massive potential
28+
# for breaking an environment if misused, so this is very much advised
29+
# only in cases where you know exactly what your enviroment does / has
30+
# (such as the tests we run here).
31+
#
32+
# In practice we use build isolation in MDAnalysis CI when:
33+
# * We are trying to test MDAnalysis with a different / older runtime
34+
# version of a key build dependency (e.g. NumPy).
35+
# We don't use build isolation when:
36+
# * We know we have already installed the required dependencies earlier
37+
# and we want to make sure that we use those dependnecies for the build
38+
# (e.g. we want to check that the packages we pulled for conda-forge
39+
# work for the build, not the ones from PyPi).
40+
# * We want to test the build & runtime with a sepecial version of a
41+
# build dependency that won't get picked up by the pip install. For
42+
# example, when we use nightly wheels of NumPy.
43+
descriptions: 'Use build isolation for pip installs, if false `--no-build-isolation` is used. '
44+
required: true
45+
default: false
1246

1347

1448
runs:
@@ -19,6 +53,7 @@ runs:
1953
run: |
2054
echo ${{ inputs.build-tests }}
2155
echo ${{ inputs.build-docs }}
56+
echo ${{ inputs.isolation }}
2257
2358
- name: check_setup
2459
shell: bash -l {0}
@@ -34,14 +69,20 @@ runs:
3469
- name: build_mda_main
3570
shell: bash -l {0}
3671
run: |
72+
if [ "${{ inputs.isolation }}" == "false" ]; then
73+
BUILD_FLAGS="--no-build-isolation"
74+
fi
3775
# install instead of develop would reduce coverage (for .pyx files)
38-
cd package/ && python setup.py develop
76+
python -m pip install ${BUILD_FLAGS} -v -e ./package
3977
4078
- name: build_mda_tests
4179
if: ${{ inputs.build-tests == 'true' }}
4280
shell: bash -l {0}
4381
run: |
44-
cd testsuite/ && python setup.py install
82+
if [ "${{ inputs.isolation }}" == "false" ]; then
83+
BUILD_FLAGS="--no-build-isolation"
84+
fi
85+
python -m pip install ${BUILD_FLAGS} -v -e ./testsuite
4586
4687
- name: build_docs
4788
if: ${{ inputs.build-docs == 'true' }}

.github/workflows/deploy.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,18 @@ jobs:
241241
micromamba: true
242242
full-deps: true
243243

244-
- name: install_min_deps
245-
if: "matrix.type == 'MIN'"
246-
run: |
247-
pip install pytest pytest-xdist pytest-timeout
248-
249244
- name: pip_install_mda
250245
run: |
251246
awk '/__version__ =/ {print $3; exit}' package/MDAnalysis/version.py | tr -d \" > version.dat
252247
ver=$(python maintainer/norm_version.py --file version.dat)
253248
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple MDAnalysis==$ver
254249
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple MDAnalysisTests==$ver
255250
251+
- name: install_min_deps
252+
if: "matrix.type == 'MIN'"
253+
run: |
254+
pip install pytest-xdist pytest-timeout
255+
256256
- name: run_tests
257257
run: |
258258
pytest --timeout=200 -n auto --pyargs MDAnalysisTests

.github/workflows/gh-ci-cron.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ jobs:
6969
with:
7070
build-tests: true
7171
build-docs: false
72+
isolation: false
7273

7374
- name: run_tests
7475
run: |
@@ -112,11 +113,13 @@ jobs:
112113
run: |
113114
sed -i "s/#extra_cflags =/extra_cflags = -march=native -mtune=native/g" package/setup.cfg
114115
cat package/setup.cfg
116+
115117
- name: build_srcs
116118
uses: ./.github/actions/build-src
117119
with:
118120
build-tests: true
119121
build-docs: false
122+
isolation: false
120123

121124
- name: run_tests
122125
run: |
@@ -164,6 +167,7 @@ jobs:
164167
with:
165168
build-tests: true
166169
build-docs: false
170+
isolation: false
167171

168172
- name: run_tests
169173
run: |

.github/workflows/gh-ci.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ jobs:
8888
with:
8989
build-tests: true
9090
build-docs: false
91+
# If we specifically define an old NumPy version then we isolate the
92+
# the build, i.e. make sure that we build with NumPy 1.25+ but we keep
93+
# the old version of NumPy as what we use for runtime testing
94+
isolation: ${{ matrix.numpy != '' }}
95+
96+
- name: check_deps
97+
run: |
98+
micromamba list
99+
pip list
91100
92101
- name: run_tests
93102
if: contains(matrix.name, 'asv_check') != true
@@ -152,6 +161,7 @@ jobs:
152161
with:
153162
build-tests: true
154163
build-docs: true
164+
isolation: false
155165

156166
- name: doctests
157167
if: github.event_name == 'pull_request'

azure-pipelines.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,12 @@ jobs:
120120
pip list
121121
displayName: 'List of installed dependencies'
122122
- powershell: |
123-
cd package
124-
python setup.py install
125-
cd ..
126-
cd testsuite
127-
python setup.py install
128-
cd ..
123+
python -m pip install ./package
124+
python -m pip install ./testsuite
129125
displayName: 'Build MDAnalysis'
130126
condition: and(succeeded(), eq(variables['BUILD_TYPE'], 'normal'))
127+
- powershell: pip list
128+
displayName: 'Check installed packages'
131129
- powershell: |
132130
cd testsuite
133131
pytest MDAnalysisTests --disable-pytest-warnings -n auto --timeout=200 -rsx --cov=MDAnalysis

package/CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Enhancements
3535
(Issue #3546)
3636

3737
Changes
38+
* Package builds are now made using NumPy 1.25 or higher. This provides
39+
backwards runtime compatibility with older NumPy builds within the limit
40+
of NEP29 (PR #4108).
3841
* Removed `-ffast-math` compiler flag to avoid potentially incorrect
3942
floating point results in MDAnalysis *and* other codes when
4043
MDAnalysis shared libraries are loaded --- see

package/pyproject.toml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,11 @@
33
requires = [
44
"Cython>=0.28",
55
"packaging",
6-
# lowest NumPy we can use for a given Python,
7-
# In part adapted from: https://github.com/scipy/oldest-supported-numpy/blob/main/setup.cfg
8-
# except for more exotic platform (Mac Arm flavors)
9-
# aarch64, AIX, s390x, and arm64 all support 1.21 so we can safely pin to this
10-
# Note: MDA does not build with PyPy so we do not support it in the build system
11-
# Scipy: On windows avoid 1.21.6, 1.22.0, and 1.22.1 because they were built on vc142
12-
# Let's set everything to this version to make things clean, also avoids other issues
13-
# on other archs
14-
"numpy==1.22.3; python_version=='3.9' and platform_python_implementation != 'PyPy'",
15-
"numpy==1.22.3; python_version=='3.10' and platform_python_implementation != 'PyPy'",
16-
"numpy==1.23.2; python_version=='3.11' and platform_python_implementation != 'PyPy'",
17-
# For unreleased versions of Python there is currently no known supported
18-
# NumPy version. In that case we just let it be a bare NumPy install
19-
"numpy<2.0; python_version>='3.12'",
6+
# NumPy 1.25+ offers backwards compatibility that tracks with greater
7+
# than NEP29 (see: https://numpy.org/doc/stable/dev/depending_on_numpy.html#adding-a-dependency-on-numpy)
8+
# We pin our wheel installation to that and a maximum of numpy 2.0 since
9+
# this will likely involve several breaking changes
10+
"numpy>=1.25,<2.0; python_version>='3.9'",
2011
"setuptools",
2112
"wheel",
2213
]

0 commit comments

Comments
 (0)