Skip to content

Commit 8e1a271

Browse files
authored
Produce OS-specific wheels (#1166)
* Update releaser.yml to get and publish all .whl files from the Release assets to PyPI, as well as the .tar.gz and .zip sources * Temp save of setup.py * Delete setup.py and declare everything in pyproject.toml * Draft version of setup.cfg * Revert "Delete setup.py and declare everything in pyproject.toml" This reverts commit f1dbb61. * Try setup.cfg with setup.py * Add wheel as build requirement in pyproject.toml * Try build jobs in the CI * Only run build jobs * Add build to requirements_build.txt * Update ci.yml build wheel job * Update ci.yml build wheel job * Create .ci/build_wheel.py script to create platform-specific wheels * Update ci.yml to use .ci/build_wheel.py * Add --wheelhouse argument to .ci/build_wheel.py, switch to pip wheel * Update ci.yml * Update ci.yml * Update ci.Test build wheel during test * Skip build_package action in test.yml * Fix path to wheel * Fix optional dependencies * Upload wheel and test docstrings * Switch back to build when not building a wheelhouse * Test upload of wheelhouse * Do not add plotting optional dependencies when building the wheelhouse * Update wheelhouse name * Update wheelhouse name * Update wheelhouse name * Set back wheelhouse arg to false in ci.yml/tests * Activate tests back in tests.yml * Tests all tests in ci.yml * Update default python version in tests.yml * Update examples.yml * Update pydpf-post.yml * Update docs.yml * Update test_docker.yml * Update examples_docker.yml * Update examples_docker.yml * Update gate.yml * Update ci_release.yml * Add tests_any job * Add tests_any job * Update build_wheel.py to also remove the gatebin folder when any * Update build_wheel.py to also remove the gatebin folder when any * Add timeout to tests.yml * Remove build_any job from ci.yml * Add tests_any job to ci_release.yml * Fix test_load_api_without_awp_root_no_gatebin * Fix test_load_api_without_awp_root_no_gatebin * Update test_service.py/test_load_api_without_awp_root_no_gatebin * Remove gate.yml
1 parent 1dcaaff commit 8e1a271

File tree

17 files changed

+506
-270
lines changed

17 files changed

+506
-270
lines changed

.ci/build_wheel.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# This script generates the different versions of the ansys-dpf-core wheels based on a given input.
2+
# Input can be one of ["any", "win", "manylinux1", "manylinux_2_17"]
3+
4+
import argparse
5+
import pathlib
6+
import subprocess
7+
import os
8+
import sys
9+
import shutil
10+
import tempfile
11+
12+
13+
supported_platforms = {
14+
"any": "any",
15+
"win": "win_amd64",
16+
"manylinux1": "manylinux1_x86_64",
17+
"manylinux_2_17": "manylinux_2_17_x86_64"
18+
}
19+
20+
argParser = argparse.ArgumentParser()
21+
argParser.add_argument("-p", "--platform", help="platform")
22+
argParser.add_argument("-w", "--wheelhouse", help="platform", action='store_true')
23+
24+
args = argParser.parse_args()
25+
26+
if args.platform not in supported_platforms:
27+
raise ValueError(f"Platform {args.platform} is not supported. "
28+
f"Supported platforms are: {list(supported_platforms.keys())}")
29+
else:
30+
requested_platform = supported_platforms[args.platform]
31+
print(requested_platform)
32+
33+
# Move binaries out of the source depending on platform requested
34+
# any: move all binaries out before building
35+
# win: move .so binaries out before building
36+
# lin: move .dll binaries out before building
37+
with tempfile.TemporaryDirectory() as tmpdirname:
38+
print('Created temporary directory: ', tmpdirname)
39+
40+
# Create the temporary build-opts.cfg
41+
build_opts_path = os.path.join(tmpdirname, "build-opts.cfg")
42+
with open(build_opts_path, "w") as build_opts_file:
43+
build_opts_file.write(f"[bdist_wheel]\nplat-name={requested_platform}")
44+
os.environ["DIST_EXTRA_CONFIG"] = build_opts_path
45+
46+
# Move the binaries
47+
gatebin_folder_path = os.path.join(
48+
os.path.curdir,
49+
os.path.join("src", "ansys", "dpf", "gatebin")
50+
)
51+
binaries_to_move = []
52+
moved = []
53+
if "win" in requested_platform or "any" == requested_platform:
54+
# Move linux binaries
55+
binaries_to_move.extend(["libAns.Dpf.GrpcClient.so", "libDPFClientAPI.so"])
56+
if "linux" in requested_platform or "any" == requested_platform:
57+
# Move windows binaries
58+
binaries_to_move.extend(["Ans.Dpf.GrpcClient.dll", "DPFClientAPI.dll"])
59+
if "any" == requested_platform:
60+
binaries_to_move.extend(["_version.py"])
61+
62+
for binary_name in binaries_to_move:
63+
src = os.path.join(gatebin_folder_path, binary_name)
64+
dst = os.path.join(tmpdirname, binary_name)
65+
print(f"Moving {src} to {dst}")
66+
shutil.move(src=src, dst=dst)
67+
moved.append([dst, src])
68+
69+
if "any" == requested_platform:
70+
# Also remove the gatebin folder
71+
os.rmdir(gatebin_folder_path)
72+
73+
# Call the build
74+
if not args.wheelhouse:
75+
cmd = [sys.executable, "-m", "build", "--wheel"]
76+
else:
77+
cmd = [sys.executable, "-m", "pip", "wheel", "-w", "dist", "."]
78+
try:
79+
subprocess.run(cmd, capture_output=False, text=True)
80+
print("Done building the wheel.")
81+
except Exception as e:
82+
print(f"Build failed with error: {e}")
83+
84+
if "any" == requested_platform:
85+
# Recreate the gatebin folder
86+
os.mkdir(gatebin_folder_path)
87+
88+
# Move binaries back
89+
for move_back in moved:
90+
print(f"Moving back {move_back[0]} to {move_back[1]}")
91+
shutil.move(src=move_back[0], dst=move_back[1])
92+
print("Binaries moved back.")
93+
94+
print(f"Done building {requested_platform} wheel for ansys-dpf-core!")

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,32 @@ jobs:
5050
- name: "Run pre-commit"
5151
run: pre-commit run --all-files --show-diff-on-failure
5252

53+
build_linux1:
54+
name: "Build linux1 wheel"
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v3
58+
59+
- name: "Install requirements"
60+
run: pip install -r requirements/requirements_build.txt
61+
62+
- name: "Build the manylinux1 wheel"
63+
shell: bash
64+
id: wheel
65+
run: |
66+
python .ci/build_wheel.py -p manylinux1
67+
cd dist
68+
export name=`ls ansys_dpf_core*.whl`
69+
echo ${name}
70+
echo "wheel_name=${name[0]}" >> $GITHUB_OUTPUT
71+
cd ..
72+
73+
- name: "Upload wheel any as artifact"
74+
uses: actions/upload-artifact@v3
75+
with:
76+
name: ${{ steps.wheel.outputs.wheel_name }}
77+
path: dist/${{ steps.wheel.outputs.wheel_name }}
78+
5379
tests:
5480
uses: ./.github/workflows/tests.yml
5581
with:
@@ -60,6 +86,17 @@ jobs:
6086
standalone_suffix: ${{ github.event.inputs.standalone_branch_suffix || '' }}
6187
secrets: inherit
6288

89+
tests_any:
90+
uses: ./.github/workflows/tests.yml
91+
with:
92+
ANSYS_VERSION: "241"
93+
python_versions: '["3.8"]'
94+
wheel: true
95+
wheelhouse: false
96+
standalone_suffix: ${{ github.event.inputs.standalone_branch_suffix || '' }}
97+
test_any: true
98+
secrets: inherit
99+
63100
docker_tests:
64101
name: "Build and Test on Docker"
65102
uses: ./.github/workflows/test_docker.yml

.github/workflows/ci_release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ jobs:
5454
- name: "Run pre-commit"
5555
run: pre-commit run --all-files --show-diff-on-failure
5656

57+
build_linux1:
58+
name: "Build linux1 wheel"
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v3
62+
63+
- name: "Install requirements"
64+
run: pip install -r requirements/requirements_build.txt
65+
66+
- name: "Build the manylinux1 wheel"
67+
shell: bash
68+
id: wheel
69+
run: |
70+
python .ci/build_wheel.py -p manylinux1
71+
cd dist
72+
export name=`ls ansys_dpf_core*.whl`
73+
echo ${name}
74+
echo "wheel_name=${name[0]}" >> $GITHUB_OUTPUT
75+
cd ..
76+
77+
- name: "Upload wheel any as artifact"
78+
uses: actions/upload-artifact@v3
79+
with:
80+
name: ${{ steps.wheel.outputs.wheel_name }}
81+
path: dist/${{ steps.wheel.outputs.wheel_name }}
82+
5783
tests:
5884
uses: ./.github/workflows/tests.yml
5985
with:
@@ -64,6 +90,17 @@ jobs:
6490
standalone_suffix: ${{ github.event.inputs.standalone_branch_suffix || '.pre0' }}
6591
secrets: inherit
6692

93+
tests_any:
94+
uses: ./.github/workflows/tests.yml
95+
with:
96+
ANSYS_VERSION: "241"
97+
python_versions: '["3.8", "3.9", "3.10"]'
98+
wheel: true
99+
wheelhouse: false
100+
standalone_suffix: ${{ github.event.inputs.standalone_branch_suffix || '.pre0' }}
101+
test_any: true
102+
secrets: inherit
103+
67104
docs:
68105
uses: ./.github/workflows/docs.yml
69106
with:

.github/workflows/docs.yml

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,53 @@ jobs:
6666
echo "ANSYS_DPF_ACCEPT_LA=Y" >> $GITHUB_ENV
6767
echo "ANSYSLMD_LICENSE_FILE=1055@${{ secrets.LICENSE_SERVER }}" >> $GITHUB_ENV
6868
69-
- name: Setup Python
70-
uses: actions/[email protected].0
69+
- name: "Setup Python"
70+
uses: actions/[email protected].1
7171
with:
7272
python-version: ${{ inputs.python_version }}
7373

74-
- name: "Build Package"
75-
id: build-package
76-
uses: ansys/pydpf-actions/[email protected]
74+
- name: "Install requirements"
75+
run: pip install -r requirements/requirements_build.txt
76+
77+
- name: "Build the wheel"
78+
shell: bash
79+
run: |
80+
if [ ${{ matrix.os }} == "ubuntu-latest" ]; then
81+
export platform="manylinux_2_17"
82+
else
83+
export platform="win"
84+
fi
85+
python .ci/build_wheel.py -p $platform -w
86+
87+
- name: "Expose the wheel"
88+
shell: bash
89+
id: wheel
90+
working-directory: dist
91+
run: |
92+
export name=`ls ansys_dpf_core*.whl`
93+
echo ${name}
94+
echo "wheel_name=${name[0]}" >> $GITHUB_OUTPUT
95+
96+
- name: "Install package wheel"
97+
shell: bash
98+
run: |
99+
pip install dist/${{ steps.wheel.outputs.wheel_name }}[plotting]
100+
101+
- name: "Install DPF"
102+
id: set-server-path
103+
uses: ansys/pydpf-actions/[email protected]
77104
with:
78-
python-version: ${{ inputs.python_version }}
79-
ANSYS_VERSION: ${{inputs.ANSYS_VERSION}}
80-
PACKAGE_NAME: ${{env.PACKAGE_NAME}}
81-
MODULE: ${{env.MODULE}}
82105
dpf-standalone-TOKEN: ${{secrets.DPF_PIPELINE}}
83-
install_extras: plotting
84-
wheel: false
85-
wheelhouse: false
86106
standalone_suffix: ${{ inputs.standalone_suffix }}
107+
ANSYS_VERSION : ${{inputs.ANSYS_VERSION}}
108+
109+
- name: "Check licences of packages"
110+
uses: ansys/pydpf-actions/[email protected]
111+
112+
- name: "Test import"
113+
shell: bash
114+
working-directory: tests
115+
run: python -c "from ansys.dpf import core"
87116

88117
- name: "Setup headless display"
89118
uses: pyvista/setup-headless-display-action@v1

.github/workflows/examples.yml

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,53 @@ jobs:
7171
echo "ANSYS_DPF_ACCEPT_LA=Y" >> $GITHUB_ENV
7272
echo "ANSYSLMD_LICENSE_FILE=1055@${{ secrets.LICENSE_SERVER }}" >> $GITHUB_ENV
7373
74-
- name: Setup Python
74+
- name: "Setup Python"
7575
uses: actions/[email protected]
7676
with:
7777
python-version: ${{ matrix.python-version }}
7878

79-
- name: "Build Package"
80-
uses: ansys/pydpf-actions/[email protected]
79+
- name: "Install requirements"
80+
run: pip install -r requirements/requirements_build.txt
81+
82+
- name: "Build the wheel"
83+
shell: bash
84+
run: |
85+
if [ ${{ matrix.os }} == "ubuntu-latest" ]; then
86+
export platform="manylinux_2_17"
87+
else
88+
export platform="win"
89+
fi
90+
python .ci/build_wheel.py -p $platform -w
91+
92+
- name: "Expose the wheel"
93+
shell: bash
94+
id: wheel
95+
working-directory: dist
96+
run: |
97+
export name=`ls ansys_dpf_core*.whl`
98+
echo ${name}
99+
echo "wheel_name=${name[0]}" >> $GITHUB_OUTPUT
100+
101+
- name: "Install package wheel"
102+
shell: bash
103+
run: |
104+
pip install dist/${{ steps.wheel.outputs.wheel_name }}[plotting]
105+
106+
- name: "Install DPF"
107+
id: set-server-path
108+
uses: ansys/pydpf-actions/[email protected]
81109
with:
82-
python-version: ${{ matrix.python-version }}
83-
ANSYS_VERSION: ${{inputs.ANSYS_VERSION}}
84-
PACKAGE_NAME: ${{ env.PACKAGE_NAME }}
85-
MODULE: ${{ env.MODULE }}
86110
dpf-standalone-TOKEN: ${{secrets.DPF_PIPELINE}}
87-
install_extras: plotting
88-
wheelhouse: false
89-
wheel: false
90111
standalone_suffix: ${{ inputs.standalone_suffix }}
112+
ANSYS_VERSION : ${{inputs.ANSYS_VERSION}}
113+
114+
- name: "Check licences of packages"
115+
uses: ansys/pydpf-actions/[email protected]
116+
117+
- name: "Test import"
118+
shell: bash
119+
working-directory: tests
120+
run: python -c "from ansys.dpf import core"
91121

92122
- name: "Prepare Testing Environment"
93123
uses: ansys/pydpf-actions/[email protected]

.github/workflows/examples_docker.yml

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,53 @@ jobs:
6767
steps:
6868
- uses: actions/checkout@v3
6969

70-
- name: Setup Python
71-
uses: actions/[email protected].0
70+
- name: "Setup Python"
71+
uses: actions/[email protected].1
7272
with:
7373
python-version: ${{ matrix.python-version }}
7474

75-
- name: "Build Docker Package"
76-
uses: ansys/pydpf-actions/[email protected]
75+
- name: "Install requirements"
76+
run: pip install -r requirements/requirements_build.txt
77+
78+
- name: "Build the wheel"
79+
shell: bash
80+
run: |
81+
if [ ${{ matrix.os }} == "ubuntu-latest" ]; then
82+
export platform="manylinux_2_17"
83+
else
84+
export platform="win"
85+
fi
86+
python .ci/build_wheel.py -p $platform -w
87+
88+
- name: "Expose the wheel"
89+
shell: bash
90+
id: wheel
91+
working-directory: dist
92+
run: |
93+
export name=`ls ansys_dpf_core*.whl`
94+
echo ${name}
95+
echo "wheel_name=${name[0]}" >> $GITHUB_OUTPUT
96+
97+
- name: "Install package wheel"
98+
shell: bash
99+
run: |
100+
pip install dist/${{ steps.wheel.outputs.wheel_name }}[plotting]
101+
102+
- name: "Install DPF"
103+
id: set-server-path
104+
uses: ansys/pydpf-actions/[email protected]
77105
with:
78-
python-version: ${{ matrix.python-version }}
79-
ANSYS_VERSION: ${{inputs.ANSYS_VERSION}}
80-
PACKAGE_NAME: ${{env.PACKAGE_NAME}}
81-
MODULE: ${{env.MODULE}}
82106
dpf-standalone-TOKEN: ${{secrets.DPF_PIPELINE}}
83-
install_extras: plotting
84-
wheel: false
85-
wheelhouse: false
86107
standalone_suffix: ${{ inputs.standalone_suffix }}
108+
ANSYS_VERSION : ${{inputs.ANSYS_VERSION}}
109+
110+
- name: "Check licences of packages"
111+
uses: ansys/pydpf-actions/[email protected]
112+
113+
- name: "Test import"
114+
shell: bash
115+
working-directory: tests
116+
run: python -c "from ansys.dpf import core"
87117

88118
- name: "Prepare Testing Environment"
89119
uses: ansys/pydpf-actions/[email protected]

0 commit comments

Comments
 (0)