Skip to content

Commit ab212ac

Browse files
committed
wheel setup
1 parent 1ca5b1d commit ab212ac

File tree

5 files changed

+179
-16
lines changed

5 files changed

+179
-16
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Build wheel and sdist for a non-pure Python package
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
build_sdist:
8+
defaults:
9+
run:
10+
shell: bash -l {0}
11+
12+
name: Build sdist
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out
16+
uses: actions/checkout@v4
17+
18+
- name: Initialize miniconda
19+
uses: conda-incubator/setup-miniconda@v3
20+
with:
21+
activate-environment: sdist
22+
channels: conda-forge
23+
auto-update-conda: true
24+
auto-activate-base: false
25+
python-version: 3.13
26+
27+
- name: Conda config
28+
run: >-
29+
conda config --set always_yes yes
30+
--set changeps1 no
31+
32+
- name: Build sdist
33+
run: |
34+
pip install --upgrade build
35+
python -m build --sdist
36+
37+
- uses: actions/upload-artifact@v4
38+
with:
39+
name: cibw-sdist
40+
path: ./dist/*.tar.gz
41+
42+
build-wheels:
43+
needs: [build_sdist]
44+
defaults:
45+
run:
46+
shell: bash -l {0}
47+
48+
name: cibw-wheels-${{ matrix.python }}-${{ matrix.buildplat }}
49+
runs-on: ${{ matrix.buildplat }}
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
buildplat:
54+
- ubuntu-latest
55+
- macos-13
56+
- macos-14
57+
- windows-latest
58+
python:
59+
- "3.11"
60+
- "3.12"
61+
- "3.13"
62+
63+
steps:
64+
- name: Check out
65+
uses: actions/checkout@v4
66+
67+
- name: Initialize miniconda
68+
uses: conda-incubator/setup-miniconda@v3
69+
with:
70+
activate-environment: build
71+
channels: conda-forge
72+
auto-update-conda: true
73+
auto-activate-base: false
74+
python-version: ${{ matrix.python }}
75+
76+
- name: Conda config
77+
run: >-
78+
conda config --set always_yes yes
79+
--set changeps1 no
80+
81+
- name: Install requirements
82+
run: |
83+
conda install --file requirements/conda.txt
84+
conda install --file requirements/pip.txt
85+
pip install --upgrade build
86+
python -m pip wheel --no-deps --wheel-dir ./dist .
87+
88+
- name: Upload wheels to GitHub
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: ${{ matrix.python }}-${{ matrix.buildplat }}.whl
92+
path: ./dist/*.whl
93+
94+
test-wheels:
95+
needs: [build-wheels]
96+
defaults:
97+
run:
98+
shell: bash -l {0}
99+
100+
name: test-wheels-${{ matrix.python }}-${{ matrix.buildplat }}
101+
runs-on: ${{ matrix.buildplat }}
102+
strategy:
103+
fail-fast: false
104+
matrix:
105+
buildplat:
106+
- ubuntu-latest
107+
- macos-13
108+
- macos-14
109+
- windows-latest
110+
python:
111+
- "3.11"
112+
- "3.12"
113+
- "3.13"
114+
115+
steps:
116+
- name: Check out
117+
uses: actions/checkout@v4
118+
119+
- name: Download wheels
120+
uses: actions/download-artifact@v4
121+
with:
122+
name: ${{ matrix.python }}-${{ matrix.buildplat }}.whl
123+
path: ./dist
124+
125+
- name: Initialize miniconda
126+
uses: conda-incubator/setup-miniconda@v3
127+
with:
128+
activate-environment: test
129+
channels: conda-forge
130+
auto-update-conda: true
131+
auto-activate-base: false
132+
python-version: ${{ matrix.python }}
133+
134+
- name: Conda config
135+
run: >-
136+
conda config --set always_yes yes
137+
--set changeps1 no
138+
139+
- name: Install requirements
140+
run: |
141+
conda install --file requirements/conda.txt
142+
conda install --file requirements/tests.txt
143+
144+
- name: Install wheel and test
145+
run: |
146+
pip install ./dist/*.whl
147+
pytest

.github/workflows/build-wheel-release-upload.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name: Release (GitHub/PyPI) and Deploy Docs
33
on:
44
workflow_dispatch:
55
push:
6-
branches:
7-
- "**"
86
tags:
97
- "*" # Trigger on all tags initially, but tag and release privilege are verified in _build-wheel-release-upload.yml
108

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ global-exclude .DS_Store # Exclude Mac filesystem artifacts.
1111
global-exclude __pycache__ # Exclude Python cache directories.
1212
global-exclude .git* # Exclude git files and directories.
1313
global-exclude .idea # Exclude PyCharm project settings.
14+
global-exclude SConscript.configure SConscript # SCons build scripts

requirements/pip.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
setuptools
12
numpy

setup.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,31 @@
2020

2121

2222
def get_boost_libraries():
23-
base_lib = "boost_python"
24-
major, minor = str(sys.version_info[0]), str(sys.version_info[1])
25-
tags = [f"{major}{minor}", major, ""]
26-
mttags = ["", "-mt"]
27-
candidates = [base_lib + tag for tag in tags for mt in mttags] + [base_lib]
28-
for lib in candidates:
29-
if find_library(lib):
30-
return [lib]
23+
# the names we'll search for
24+
major, minor = sys.version_info[:2]
25+
candidates = [
26+
f"boost_python{major}{minor}",
27+
f"boost_python{major}",
28+
"boost_python",
29+
]
30+
31+
conda_prefix = os.environ.get("CONDA_PREFIX")
32+
if conda_prefix:
33+
libdir = os.path.join(conda_prefix, "lib")
34+
for name in candidates:
35+
so = f"lib{name}.so"
36+
if os.path.isfile(os.path.join(libdir, so)):
37+
# return the plain "boost_python311" etc (no "lib" prefix or ".so")
38+
return [name]
39+
40+
# fallback to ldconfig
41+
for name in candidates:
42+
found = find_library(name)
43+
if found:
44+
# find_library may return "libboost_python3.so.1.74.0" etc
45+
# strip off lib*.so.* if you like, or just return name
46+
return [name]
47+
3148
raise RuntimeError("Cannot find a suitable Boost.Python library.")
3249

3350

@@ -91,11 +108,10 @@ def create_extensions():
91108
)
92109
return [ext]
93110

94-
95-
setup_args = dict(
96-
ext_modules=[],
97-
)
111+
def ext_modules():
112+
if set(sys.argv) & {"build_ext", "bdist_wheel", "install"}:
113+
return create_extensions()
114+
return []
98115

99116
if __name__ == "__main__":
100-
setup_args["ext_modules"] = create_extensions()
101-
setup(**setup_args)
117+
setup(ext_modules=ext_modules())

0 commit comments

Comments
 (0)