-
Notifications
You must be signed in to change notification settings - Fork 193
505 lines (450 loc) · 18.4 KB
/
python_bindings.yml
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
name: Python Bindings
on:
push:
branches: [ master, actions_pypi ]
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
pull_request:
branches: [ master ]
env:
BUILD_TYPE: Release
BUILD_CLI: OFF
BUILD_RUBY_BINDINGS: OFF
MAKE_SPACE: false
jobs:
python_bindings:
name: Build ${{ matrix.name }}
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.allow_failure }}
strategy:
# fail-fast: Default is true, switch to false to allow one platform to fail and still run others
fail-fast: false
matrix:
name: [Ubuntu, macOS, macOS_arm64, Windows_py37, Windows_py38, Windows_py39, Windows_py310, Windows_py311, Windows_py312, Windows_py313]
include:
- name: Ubuntu
os: ubuntu-22.04
python-version: 3.8
allow_failure: false
- name: macOS
os: macos-12
python-version: 3.8
allow_failure: false
MACOSX_DEPLOYMENT_TARGET: 10.15
SDKROOT: /Applications/Xcode_13.2.1.app
- name: macOS_arm64
os: macos-14
python-version: 3.8
allow_failure: false
MACOSX_DEPLOYMENT_TARGET: 12.1
SDKROOT: /Applications/Xcode_15.2.app
- name: Windows_py37
os: windows-2019
python-version: 3.7
allow_failure: false
- name: Windows_py38
os: windows-2019
python-version: 3.8
allow_failure: false
- name: Windows_py39
os: windows-2019
python-version: 3.9
allow_failure: false
- name: Windows_py310
os: windows-2019
python-version: '3.10'
allow_failure: false
- name: Windows_py311
os: windows-2019
python-version: '3.11'
allow_failure: false
- name: Windows_py312
os: windows-2019
python-version: '3.12'
allow_failure: false
- name: Windows_py313
os: windows-2019
python-version: '3.13'
allow_failure: true # Possible this fails, don't care yet
steps:
- uses: actions/checkout@v4
# with:
# ref: develop
- name: Set up Python ${{ matrix.python-version }}
if: runner.os == 'macOS'
id: setup-python-macos
# 3.10 is the first one to have a prebuilt binary for macos-14 (arm64) on the actions/setup-python, so I forked it and actions/python-versions to add 3.8
uses: jmarrec/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-version }}
if: runner.os != 'macOS'
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install System dependencies
shell: bash
run: |
set -x
if [ "$RUNNER_OS" == "Linux" ]; then
echo "Using Apt to install ninja"
sudo apt update
sudo apt install ninja-build
# Weirdly enough, ninja makes ubuntu unresponsive...
#echo CMAKE_GENERATOR='Ninja' >> $GITHUB_ENV
# Use preinstalled gcc-10 to support C++20
#echo CC=gcc-10 >> $GITHUB_ENV
#echo CXX=g++-10 >> $GITHUB_ENV
elif [ "$RUNNER_OS" == "macOS" ]; then
echo "Setting up MACOSX_DEPLOYMENT_TARGET and SDKROOT"
sudo xcode-select -switch "${{ matrix.SDKROOT }}"
sdk_path=$(xcrun --sdk macosx --show-sdk-path)
echo "sdk_path=$sdk_path"
# The MACOSX_DEPLOYMENT_TARGET environment variable sets the default value for the CMAKE_OSX_DEPLOYMENT_TARGET variable.
echo MACOSX_DEPLOYMENT_TARGET=${{ matrix.MACOSX_DEPLOYMENT_TARGET }} >> $GITHUB_ENV
echo "Using brew to install ninja"
brew install ninja
echo CMAKE_GENERATOR='Ninja' >> $GITHUB_ENV
elif [ "$RUNNER_OS" == "Windows" ]; then
#echo "Setting CMAKE_GENERATOR options equivalent to ='-G \"Visual Studio 16 2019\" -A x64'"
#echo CMAKE_GENERATOR='Visual Studio 16 2019' >> $GITHUB_ENV
#echo CMAKE_GENERATOR_PLATFORM=x64 >> $GITHUB_ENV
echo "Using chocolatey to install ninja"
choco install ninja
# C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise
MSVC_DIR=$(vswhere -products '*' -requires Microsoft.Component.MSBuild -property installationPath -latest)
echo "Latest is: $MSVC_DIR"
echo "MSVC_DIR=$MSVC_DIR" >> $GITHUB_ENV
# add folder containing vcvarsall.bat
echo "$MSVC_DIR\VC\Auxiliary\Build" >> $GITHUB_PATH
fi;
if [[ "$GITHUB_REF" == *"refs/tags"* ]]; then
PYTHON_PIP_REPOSITORY=pypi
else
PYTHON_PIP_REPOSITORY=testpypi
fi;
echo "PYTHON_PIP_REPOSITORY=$PYTHON_PIP_REPOSITORY" >> $GITHUB_ENV
- name: Install Conan
shell: bash
run: |
begin_group() { echo -e "::group::\033[93m$1\033[0m"; }
begin_group "Install other python dependencies"
python -m pip install --upgrade pip
pip install setuptools wheel twine requests packaging
echo -e "::endgroup::"
set -x
begin_group "Install conan 2"
python --version
pip install 'conan>2'
conan --version
echo -e "::endgroup::"
begin_group "Default profile"
if [ "$RUNNER_OS" == "Windows" ]; then
DIR_SEP="\\"
else
DIR_SEP="/"
fi
echo DIR_SEP=$DIR_SEP >> $GITHUB_ENV
export CONAN_USER_HOME="${{ github.workspace }}${DIR_SEP}conan-cache"
echo CONAN_USER_HOME="$CONAN_USER_HOME" >> $GITHUB_ENV
export CONAN_HOME="$CONAN_USER_HOME${DIR_SEP}.conan2"
echo CONAN_HOME="$CONAN_HOME" >> $GITHUB_ENV
export CONAN_PROFILE_DEFAULT="$CONAN_HOME${DIR_SEP}profiles${DIR_SEP}default"
echo CONAN_PROFILE_DEFAULT="$CONAN_PROFILE_DEFAULT" >> $GITHUB_ENV
conan profile detect --force --name default
cat $CONAN_PROFILE_DEFAULT
# Mac has the FreeBSD flavor of sed and MUST take a backup suffix...
sed -i.bak 's/cppstd=.*$/cppstd=20/g' $CONAN_PROFILE_DEFAULT
sed -i.bak 's/build_type=.*$/build_type=${{ env.BUILD_TYPE }}/g' $CONAN_PROFILE_DEFAULT
# Windows only
sed -i.bak 's/compiler.runtime_type=.*$/compiler.runtime_type=${{ env.BUILD_TYPE }}/g' $CONAN_PROFILE_DEFAULT
rm -Rf $CONAN_PROFILE_DEFAULT.bak || true
conan profile show
echo -e "::endgroup::"
begin_group "Global.conf"
echo "core:non_interactive = True" >> $CONAN_HOME/global.conf
echo "core.download:parallel = {{os.cpu_count() - 2}}" >> $CONAN_HOME/global.conf
echo "core.sources:download_cache = $CONAN_USER_HOME/.conan-download-cache" >> $CONAN_HOME/global.conf
cat $CONAN_HOME/global.conf
echo -e "::endgroup::"
begin_group "Remotes"
conan remote add --force nrel-v2 https://conan.openstudio.net/artifactory/api/conan/conan-v2
conan remote list
echo -e "::endgroup::"
- name: Create Build Directory
run: cmake -E make_directory ./build/
- name: Clean up some stuff to avoid running out of disk space
if: env.MAKE_SPACE == 'true'
shell: bash
run: |
set -x
df -h || true
if [ "$RUNNER_OS" == "Windows" ]; then
# du -sh /c/Program\ Files/* | sort -rh || true
# 20G /c/Program Files/dotnet
# 959M /c/Program Files/Java
# 830M /c/Program Files/Azure Cosmos DB Emulator
# 702M /c/Program Files/MongoDB
# 619M /c/Program Files/PostgreSQL
# 472M /c/Program Files/Microsoft Service Fabric
# 448M /c/Program Files/Google
# 309M /c/Program Files/Microsoft SDKs
# 272M /c/Program Files/Amazon
# 268M /c/Program Files/R
# 267M /c/Program Files/Microsoft SQL Server
# 266M /c/Program Files/Git
# 243M /c/Program Files/PowerShell
# 238M /c/Program Files/Docker
# 205M /c/Program Files/Mozilla Firefox
# 202M /c/Program Files/Unity Hub
# 147M /c/Program Files/Android
/bin/rm -Rf /c/Program\ Files/dotnet || true
/bin/rm -Rf /c/Program\ Files/Amazon/ || true
/bin/rm -Rf /c/Program\ Files/Azure\ Cosmos\ DB\ Emulator/ || true
/bin/rm -Rf /c/Program\ Files/Android/ || true
/bin/rm -Rf /c/Program\ Files/Google/ || true
/bin/rm -Rf /c/Program\ Files/Java/ || true
/bin/rm -Rf /c/Program\ Files/Microsoft\ Service\ Fabric || true
/bin/rm -Rf /c/Program\ Files/Microsoft\ SQL\ Server || true
/bin/rm -Rf /c/Program\ Files/PostgreSQL || true
/bin/rm -Rf /c/Program\ Files/Unity\ Hub/ || true
echo $BOOST_ROOT_1_72_0
/bin/rm -Rf $BOOST_ROOT_1_72_0 || true
elif [ "$RUNNER_OS" == "Linux" ]; then
sudo apt remove -y '^ghc-8.*'
sudo apt remove -y '^dotnet-.*'
sudo apt remove -y '^llvm-.*'
sudo apt remove -y 'php.*'
sudo apt remove -y azure-cli google-cloud-sdk hhvm google-chrome-stable firefox powershell mono-devel
sudo apt autoremove -y
sudo apt clean
sudo rm -rf /usr/local/share/boost/
sudo rm -rf /usr/share/dotnet/
fi;
df -h || true
- name: Configure CMake & build (Windows)
if: runner.os == 'Windows'
shell: cmd
run: |
echo "::group::Conan Install"
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=Release -o with_testing=False -o with_benchmark=False
echo "::engroup::"
echo "::group::CMake Configure"
call ./build/conanbuild.bat
cmake --preset conan-release ^
-DBUILD_PYTHON_BINDINGS:BOOL=ON -DBUILD_PYTHON_PIP_PACKAGE:BOOL=ON -DPYTHON_PIP_REPOSITORY:STRING=${{ env.PYTHON_PIP_REPOSITORY }} ^
-DPYTHON_VERSION:STRING=${{ steps.setup-python.outputs.python-version }} ^
-DBUILD_TESTING:BOOL=OFF -DBUILD_RUBY_BINDINGS:BOOL=${{ env.BUILD_RUBY_BINDINGS }} -DBUILD_CLI:BOOL=${{ env.BUILD_CLI }}
echo "::engroup::"
echo "::group::Build"
cmake --build --preset conan-release
echo "::engroup::"
- name: Configure CMake & build (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
begin_group() { echo -e "::group::\033[93m$1\033[0m"; }
set -x
begin_group "Conan install"
PYTHON_ARCH=x64
if [ "$RUNNER_OS" == "macOS" ]; then
PYTHON_VERSION=${{ steps.setup-python-macos.outputs.python-version }}
if [ "${{ matrix.name }}" == "macOS_arm64" ]; then
PYTHON_ARCH=arm64
# Avoid "builtin __has_nothrow_assign is deprecated; use __is_nothrow_assignable instead" in boost/1.79 with recent clang
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=Release -o with_testing=False -o with_benchmark=False -c tools.build:cxxflags="['-D_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION -Wno-enum-constexpr-conversion']"
else
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=Release -o with_testing=False -o with_benchmark=False -c tools.build:cxxflags="['-D_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']"
fi
else
PYTHON_VERSION=${{ steps.setup-python.outputs.python-version }}
conan install . --output-folder=./build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=Release -o with_testing=False -o with_benchmark=False
fi
echo -e "::endgroup::"
begin_group "CMake Configure"
cmake --preset conan-release \
-DBUILD_PYTHON_BINDINGS:BOOL=ON -DBUILD_PYTHON_PIP_PACKAGE:BOOL=ON -DPYTHON_PIP_REPOSITORY:STRING=${{ env.PYTHON_PIP_REPOSITORY }} \
-DPYTHON_VERSION:STRING=$PYTHON_VERSION \
-DPython_ROOT_DIR:PATH=$RUNNER_TOOL_CACHE/Python/$PYTHON_VERSION/$PYTHON_ARCH/ \
-DBUILD_TESTING:BOOL=OFF -DBUILD_RUBY_BINDINGS:BOOL=${{ env.BUILD_RUBY_BINDINGS }} -DBUILD_CLI:BOOL=${{ env.BUILD_CLI }}
echo -e "::endgroup::"
begin_group "Build"
cmake --build --preset conan-release
echo -e "::endgroup::"
# We always upload to testpypi
- name: Build python wheel
shell: bash
working-directory: ./build
run: |
cmake --build --preset conan-release --target python_package
cd Products/python_package/
python setup.py bdist_wheel
- name: Zip the wheel to maintain case sensitivy and file permissions
working-directory: ./build/Products/python_package/
shell: bash
run: |
tar -cvzf openstudio-${{ matrix.name }}.tar.gz dist/
- name: Upload .whl to artifact
uses: actions/upload-artifact@v4
with:
name: openstudio-${{ matrix.name }} # something like openstudio-Windows_py37
path: ./build/Products/python_package/openstudio-${{ matrix.name }}.tar.gz
# Only upload if all builds succeed
upload_python_bindings_to_testpypi:
needs: python_bindings
name: Upload to TestPyPi
runs-on: ubuntu-22.04
steps:
- name: Set up Python
uses: actions/setup-python@v5
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
# urllib3 2.0 breaks
pip install urllib3==1.26.15
pip install setuptools wheel twine requests packaging
mkdir wheels
- name: Download ALL wheels
uses: actions/download-artifact@v4
with:
path: ./wheels
- name: Display structure of downloaded files
working-directory: ./wheels
run: |
ls -R
- name: Extract all tar.gz, then upload
working-directory: ./wheels
env:
TWINE_USERNAME: __token__
TWINE_REPOSITORY: testpypi
# Go to repo on github > Settings > Secrets and add it
TWINE_PASSWORD: ${{ secrets.TESTPYPI_TOKEN }}
shell: bash
run: |
for f in **/*.tar.gz; do
mv $f .
done;
for f in *.tar.gz; do
tar -xzvf "$f";
done;
ls -R
python -m twine upload --verbose --skip-existing --repository testpypi dist/*
test_python_bindings:
needs: upload_python_bindings_to_testpypi
name: Test ${{ matrix.name }}
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.allow_failure }}
strategy:
# fail-fast: Default is true, switch to false to allow one platform to fail and still run others
fail-fast: false
matrix:
name: [Ubuntu, macOS, macOS_arm64, Windows_py37, Windows_py38, Windows_py39, Windows_py310, Windows_py311, Windows_py312, Windows_py313]
include:
- name: Ubuntu
os: ubuntu-22.04
python-version: 3.11 # Voluntarily using a newer version than built with for Unix
allow_failure: false
- name: macOS
os: macos-12
python-version: 3.11
allow_failure: false
- name: macOS_arm64
os: macos-14
python-version: 3.11
allow_failure: false
- name: Windows_py37
os: windows-2019
python-version: 3.7
allow_failure: false
- name: Windows_py38
os: windows-2019
python-version: 3.8
allow_failure: false
- name: Windows_py39
os: windows-2019
python-version: 3.9
allow_failure: false
- name: Windows_py310
os: windows-2019
python-version: '3.10'
allow_failure: false
- name: Windows_py311
os: windows-2019
python-version: '3.11'
allow_failure: false
- name: Windows_py312
os: windows-2019
python-version: '3.12'
allow_failure: false
- name: Windows_py313
os: windows-2019
python-version: '3.13'
allow_failure: true # Possible this fails, don't care yet
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install openstudio bindings from testpypi
shell: bash
run: |
set -x
python -m pip install --upgrade pip
# Note: if we choose to do ALL or nothing, remove setuptools wheel twine (not needed unless trying to upload within this step)
pip install requests packaging setuptools wheel twine
if [[ "$GITHUB_REF" == *"refs/tags"* ]]; then
bindings_v=$(python ./python/module/find_pypi_tag.py --pypi)
else
bindings_v=$(python ./python/module/find_pypi_tag.py --current)
fi;
pip install -i https://test.pypi.org/simple/ openstudio==$bindings_v
mkdir wheel
- name: Test the bindings
shell: python
run: |
import openstudio
m = openstudio.model.exampleModel()
print(m)
# if python_bindings succeeds but test_python_bindings fails and this is a release,
# remove that version from testpypi
upload_python_bindings_to_pypi:
if: contains(github.ref, 'refs/tags')
needs: test_python_bindings
name: Upload to PyPi
runs-on: ubuntu-22.04
steps:
- name: Set up Python
uses: actions/setup-python@v5
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine requests packaging
mkdir wheels
- name: Download ALL wheels
uses: actions/download-artifact@v4
with:
path: ./wheels
- name: Display structure of downloaded files
working-directory: ./wheels
run: |
ls -R
- name: Extract all tar.gz, then upload
working-directory: ./wheels
env:
TWINE_USERNAME: __token__
TWINE_REPOSITORY: pypi
# Go to repo on github > Settings > Secrets and add it
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
shell: bash
run: |
for f in **/*.tar.gz; do
mv $f .
done;
for f in *.tar.gz; do
tar -xzvf "$f";
done;
ls -R
python -m twine upload --verbose --skip-existing --repository pypi dist/*