Skip to content

Commit b032055

Browse files
authored
Merge pull request #199 from nipy/enh/build_wheels
ENH: Build wheels on GitHub actions
2 parents be154ec + eeba180 commit b032055

File tree

5 files changed

+160
-8
lines changed

5 files changed

+160
-8
lines changed

.github/workflows/wheels.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- "*"
9+
pull_request:
10+
branches:
11+
- master
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
job_metadata:
19+
runs-on: ubuntu-latest
20+
outputs:
21+
commit_message: ${{ steps.get_commit_message.outputs.commit_message }}
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
with:
26+
fetch-depth: 2
27+
- name: Print head git commit message
28+
id: get_commit_message
29+
run: |
30+
if [[ -z "$COMMIT_MSG" ]]; then
31+
COMMIT_MSG=$(git show -s --format=%s $REF)
32+
fi
33+
echo commit_message=$COMMIT_MSG | tee -a $GITHUB_OUTPUT
34+
env:
35+
COMMIT_MSG: ${{ github.event.head_commit.message }}
36+
REF: ${{ github.event.pull_request.head.sha }}
37+
38+
build-sdist:
39+
name: Build sdist
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v3
43+
- name: Build sdist
44+
run: pipx run build -s
45+
- uses: actions/upload-artifact@v3
46+
with:
47+
name: sdist
48+
path: ./dist/*.tar.gz
49+
50+
build-wheel:
51+
name: Build wheel for ${{ matrix.python }}-${{ matrix.buildplat[1] }}
52+
needs: [job_metadata]
53+
runs-on: ${{ matrix.buildplat[0] }}
54+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') || contains(needs.job_metadata.outputs.commit_message, '[build wheels]')
55+
strategy:
56+
fail-fast: false
57+
matrix:
58+
buildplat:
59+
- [ubuntu-20.04, musllinux_x86_64]
60+
- [macos-12, macosx_*]
61+
- [windows-2019, win_amd64]
62+
python: ["cp37", "cp38", "cp39", "cp310", "cp311"]
63+
include:
64+
# Manylinux builds are cheap, do all in one
65+
- { buildplat: ["ubuntu-20.04", "manylinux_x86_64"], python: "*" }
66+
67+
steps:
68+
- uses: actions/checkout@v3
69+
70+
- name: Build wheel(s)
71+
run: pipx run cibuildwheel
72+
env:
73+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
74+
75+
- uses: actions/upload-artifact@v3
76+
with:
77+
name: ${{ matrix.python == '*' && 'all' || matrix.python }}-${{ startsWith(matrix.buildplat[1], 'macosx') && 'macosx' || matrix.buildplat[1] }}
78+
path: ./wheelhouse/*.whl
79+
80+
test-sdist:
81+
name: Test sdist
82+
needs: [build-sdist]
83+
runs-on: ubuntu-latest
84+
steps:
85+
- uses: actions/download-artifact@v3
86+
with:
87+
name: sdist
88+
path: ./dist
89+
- uses: actions/setup-python@v4
90+
with:
91+
python-version: "3.11"
92+
- name: Display Python version
93+
run: python -c "import sys; print(sys.version)"
94+
- name: Install sdist
95+
run: pip install dist/*.tar.gz
96+
- run: python -c 'import nitime; print(nitime.__version__)'
97+
- name: Install pytest
98+
run: pip install pytest
99+
- name: Run tests
100+
run: pytest -v --pyargs nitime
101+
102+
pre-publish:
103+
runs-on: ubuntu-latest
104+
needs: [test-sdist, build-wheel]
105+
steps:
106+
- uses: actions/download-artifact@v3
107+
with:
108+
path: dist/
109+
- name: Check artifacts
110+
run: ls -lR
111+
- name: Consolidate and re-check
112+
run: |
113+
mv dist/*/*.{tar.gz,whl} dist
114+
rmdir dist/*/
115+
ls -lR
116+
- run: pipx run twine check dist/*
117+
118+
publish:
119+
runs-on: ubuntu-latest
120+
environment: "Package deployment"
121+
needs: [pre-publish]
122+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
123+
steps:
124+
- uses: actions/download-artifact@v3
125+
with:
126+
path: dist/
127+
- name: Consolidate artifacts
128+
run: |
129+
mv dist/*/*.{tar.gz,whl} dist
130+
rmdir dist/*/
131+
- uses: pypa/gh-action-pypi-publish@release/v1
132+
with:
133+
user: __token__
134+
password: ${{ secrets.PYPI_API_TOKEN }}

nitime/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@
9696
VERSION = __version__
9797
PACKAGE_DATA = {"nitime": ["LICENSE", "tests/*.txt", "tests/*.npy",
9898
"data/*.nii.gz", "data/*.txt", "data/*.csv"]}
99-
PYTHON_REQUIRES = ">=3.5"
99+
PYTHON_REQUIRES = ">=3.7"

nitime/viz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ def draw_graph(G,
680680

681681
# Build a 'weighted degree' array obtained by adding the (absolute value)
682682
# of the weights for all edges pointing to each node:
683-
amat = nx.adj_matrix(G).A # get a normal array out of it
683+
amat = nx.adjacency_matrix(G).todense() # get a normal array out of it
684684
degarr = abs(amat).sum(0) # weights are sums across rows
685685

686686
# Map the degree to the 0-1 range so we can use it for sizing the nodes.

pyproject.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[build-system]
2+
requires = [
3+
"setuptools",
4+
"cython",
5+
# Newer than NEP29-minimum: compile against oldest numpy available
6+
"numpy==1.24; python_version >= '3.11'",
7+
"numpy==1.22; python_version >= '3.10' and python_version < '3.11'",
8+
# NEP29-minimum as of Jan 31, 2023
9+
"numpy==1.21; python_version >= '3.7' and python_version < '3.10'",
10+
]
11+
build-backend = "setuptools.build_meta"
12+
13+
[tool.cibuildwheel]
14+
# Disable CPython 3.6 here; if project.requires-python gets defined,
15+
# cp36* can be removed
16+
skip = "pp* cp36*"
17+
18+
# 64-bit builds only; 32-bit builds seem pretty niche these days, so
19+
# don't bother unless someone asks
20+
archs = ["auto64"]

setup.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
if os.path.exists('MANIFEST'):
1010
os.remove('MANIFEST')
1111

12-
from setuptools import find_packages
13-
from distutils.core import setup
12+
from setuptools import find_packages, setup
1413

1514
# Get version and release info, which is all stored in nitime/version.py
1615
ver_file = os.path.join('nitime', 'version.py')
@@ -49,14 +48,13 @@
4948
)
5049

5150
try:
52-
from distutils.extension import Extension
53-
from Cython.Distutils import build_ext as build_pyx_ext
51+
from setuptools import Extension
52+
from Cython.Build import cythonize
5453
from numpy import get_include
5554
# add Cython extensions to the setup options
5655
exts = [Extension('nitime._utils', ['nitime/_utils.pyx'],
5756
include_dirs=[get_include()])]
58-
opts['cmdclass'] = dict(build_ext=build_pyx_ext)
59-
opts['ext_modules'] = exts
57+
opts['ext_modules'] = cythonize(exts, language_level='3')
6058
except ImportError:
6159
# no loop for you!
6260
pass

0 commit comments

Comments
 (0)