1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
# SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
name: Build and upload to PyPI
on: [push, pull_request]
# For musllinux support, see note in pyproject.toml
jobs:
wheels_linux:
name: ${{ matrix.os }} - ${{ matrix.platform }}
runs-on: ${{ matrix.os }}
env:
CIBW_BUILD: "*-${{ matrix.platform }}"
strategy:
matrix:
os: [ubuntu-20.04]
platform: [manylinux_x86_64, manylinux_i686]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: "0" # 0=all, needed for setuptools-scm to resolve version tags
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: "3.8"
- name: Set up QEMU
if: matrix.platform == 'manylinux_aarch64'
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Build wheels
uses: joerick/cibuildwheel@v2.9.0
if: matrix.platform != 'manylinux_aarch64'
- name: Build wheels (emulated)
uses: joerick/cibuildwheel@v2.9.0
if: matrix.platform == 'manylinux_aarch64'
env:
CIBW_ARCHS_LINUX: aarch64
- name: Upload built wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: ./wheelhouse/*.whl
if-no-files-found: error
- name: Upload wheel for ReadTheDocs
uses: actions/upload-artifact@v3
if: matrix.platform == 'manylinux_x86_64'
with:
name: rtd-wheel
path: ./wheelhouse/pikepdf-*-cp39-*.manylinux2014_x86_64.whl
if-no-files-found: error
wheels_linux_arm:
name: self-hosted - ${{ matrix.platform }}
runs-on: self-hosted
env:
CIBW_BUILD: "*-${{ matrix.platform }}"
strategy:
matrix:
platform: [manylinux_aarch64]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: "0" # 0=all, needed for setuptools-scm to resolve version tags
# Custom cibuildwheel step since actions doesn't support self-hosted
- name: Build wheels
run: >
pipx run
--python /usr/bin/python3
--spec cibuildwheel==2.9.0
cibuildwheel
.
--output-dir wheelhouse
2>&1
shell: bash
env:
CIBW_ARCHS_LINUX: aarch64
- name: Upload built wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: ./wheelhouse/*.whl
if-no-files-found: error
wheels_macos:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-11]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: "0"
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: "3.8"
- name: Build wheels
uses: joerick/cibuildwheel@v2.9.0
#env:
# CIBW_ARCHS_MACOS: x86_64 universal2 # for Apple Silicon
- uses: actions/upload-artifact@v3
with:
name: wheels
path: ./wheelhouse/*.whl
wheels_windows:
name: ${{ matrix.os }} - ${{ matrix.platform }}
runs-on: ${{ matrix.os }}
env:
CIBW_BUILD: "*-${{ matrix.platform }}"
CIBW_ENVIRONMENT: >-
INCLUDE="$INCLUDE;d:\\qpdf\\include"
LIB="$LIB;d:\\qpdf\\lib"
LIBPATH="$LIBPATH;d:\\qpdf\\lib"
strategy:
matrix:
os: [windows-2019]
platform: [win_amd64, win32]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: "0"
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: "3.8"
- name: Install tomli and read environment from pyproject.toml
run: |
python -m pip install tomli
python build-scripts/environ-from-pyproject.py >> $env:GITHUB_ENV
dir env:
- name: Download QPDF
run: |
build-scripts/win-download-qpdf.ps1 $env:QPDF_VERSION ${{ matrix.platform }}
- name: Build wheels
uses: joerick/cibuildwheel@v2.9.0
- uses: actions/upload-artifact@v3
with:
name: wheels
path: ./wheelhouse/*.whl
sdist:
name: source distribution
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: "0"
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: "3.8"
- name: Install apt packages
run: |
sudo apt-get update
sudo apt-get install -y cmake jbig2dec lcov libexempi8 poppler-utils
- name: Install tomli and read environment from pyproject.toml
run: |
python -m pip install tomli
python build-scripts/environ-from-pyproject.py >> $GITHUB_ENV
- name: Download QPDF
run: build-scripts/linux-download-qpdf.bash $QPDF_MIN_VERSION
- name: Add /usr/local/lib to dynamic linker path
run: echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/local-lib.conf
- name: Build QPDF
run: build-scripts/linux-build-sdist-deps.bash
- name: Build sdist
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools wheel build
python -m build --sdist
- name: Install and test sdist (isolated)
run: |
python -m venv v
source v/bin/activate
SDIST=dist/*.tar.gz
SDIST_EXPANDED=$(echo -n $SDIST)
python -m pip install ${SDIST_EXPANDED}[test] # yes this works
python -m pytest -nauto
deactivate
- name: Install local project as editable
run: |
# pip install with --coverage is broken so we have to do it this horrible hacky way
# https://github.com/pypa/setuptools/issues/3025
# Install it with pip, or else dependencies won't be resolved (*sigh*)
python -m pip install -e .[test]
# Nuke the C++ extension but leave the Python install intact
rm -rf build/ src/pikepdf/_qpdf*.so
# Rebuild the extension inplace with coverage
env CFLAGS="--coverage" CXXFLAGS="--coverage" python setup.py build_ext --inplace
python -m pytest -nauto --cov-report xml --cov=src
- name: Generate C++ coverage reports
run: |
lcov --no-external --capture --directory . --output-file cpp_coverage_all.info
lcov --remove cpp_coverage_all.info '*/pybind11/*' -o cpp_coverage.info
rm cpp_coverage_all.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml,./cpp_coverage.info
- uses: actions/upload-artifact@v3
with:
name: wheels
path: dist/*.tar.gz
upload_pypi:
needs: [wheels_linux, wheels_linux_arm, wheels_macos, wheels_windows, sdist]
runs-on: ubuntu-latest
# upload to PyPI on every tag starting with 'v'
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v3
with:
name: wheels
path: dist
- uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.TOKEN_PYPI }}
# repository_url: https://test.pypi.org/legacy/
trigger_rtd:
name: Trigger ReadTheDocs
runs-on: ubuntu-latest
needs: [upload_pypi]
if: startsWith(github.ref, 'refs/heads/') && !startsWith(github.ref, 'refs/heads/actions')
steps:
- name: Check for secrets
id: setvar
run: |
if [[ "${{ secrets.RTDS_WEBHOOK_URL }}" != "" && \
"${{ secrets.RTDS_WEBHOOK_TOKEN }}" != "" ]]; \
then
echo "Secrets to use trigger ReadTheDocs were configured"
echo "::set-output name=have_secrets::true"
else
echo "Secrets to use trigger ReadTheDocs were not configured"
echo "::set-output name=have_secrets::false"
fi
- name: Get branch name
id: get_branch
run: |
echo "::set-output name=branch::${GITHUB_REF##refs/heads/}"
- name: Trigger ReadTheDocs webhook
run: |
curl -X POST -d "branches=${{ steps.get_branch.outputs.branch }}" \
-d "token=${{ secrets.RTDS_WEBHOOK_TOKEN }}" \
"${{ secrets.RTDS_WEBHOOK_URL }}"
if: ${{ steps.setvar.outputs.have_secrets == 'true' }}
|