Skip to content

Commit 5d5aaca

Browse files
authored
Add CI (#16)
1 parent 10d3011 commit 5d5aaca

18 files changed

+456
-48
lines changed

.ci/azure-pipelines.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# azure pipelines build and test DPF-Post
2+
3+
variables:
4+
ALLOW_PLOTTING: true
5+
package_name: ansys-dpf-post
6+
SHELLOPTS: 'errexit:pipefail'
7+
8+
trigger:
9+
branches:
10+
include:
11+
- '*'
12+
exclude:
13+
- gh-pages
14+
tags:
15+
include:
16+
- '*'
17+
18+
pr:
19+
branches:
20+
exclude:
21+
- '*'
22+
23+
jobs:
24+
- job: Windows
25+
variables:
26+
python.version: '3.8'
27+
DISPLAY: ':99.0'
28+
PYANSYS_OFF_SCREEN: True
29+
DPF_PORT: 32772
30+
DPF_START_SERVER: False
31+
pool:
32+
vmImage: 'windows-2019'
33+
34+
steps:
35+
- powershell: |
36+
powershell .ci/install_opengl.ps1
37+
.ci/setup_headless_display.sh
38+
pip install -r .ci/requirements_test_xvfb.txt
39+
python .ci/display_test.py
40+
displayName: Install and start a virtual framebuffer
41+
42+
- task: UsePythonVersion@0
43+
inputs:
44+
versionSpec: $(python.version)
45+
addToPath: true
46+
47+
- task: PipAuthenticate@1
48+
inputs:
49+
artifactFeeds: 'pyansys'
50+
onlyAddExtraIndex: true
51+
52+
- script: |
53+
pip install -r requirements_build.txt
54+
python setup.py bdist_wheel
55+
pip install --find-links=dist ansys_dpf_post
56+
cd tests
57+
python -c "from ansys.dpf import post; print(post.Report(gpu=False))"
58+
displayName: Install ansys-dpf-post
59+
60+
- task: UniversalPackages@0
61+
inputs:
62+
command: 'download'
63+
downloadDirectory: '$(System.DefaultWorkingDirectory)'
64+
feedsToUse: 'internal'
65+
vstsFeed: '705e121a-9631-49f5-8aaf-c7142856f923'
66+
vstsFeedPackage: 'f913c1d3-1fe4-404c-8c28-15a234e56803'
67+
vstsPackageVersion: '21.1.4'
68+
69+
- script: |
70+
@echo on
71+
dir $(System.DefaultWorkingDirectory)
72+
set THISDIR=$(System.DefaultWorkingDirectory)
73+
set PATH=%THISDIR%\server\v211\tp\IntelMKL\2020.0.166\winx64\;%THISDIR%\server\v211\tp\hdf5\1.8.14\winx64\;%THISDIR%\server\v211\tp\CFFSDK\lib\winx64;%THISDIR%\res_files\;%PATH%
74+
cd %THISDIR%\server\v211\aisol\bin\winx64
75+
START /B Ans.Dpf.Grpc.exe --address 127.0.0.1 --port %DPF_PORT% > log.txt 2>&1
76+
python -c "from ansys.dpf import core; core.connect_to_server(port=$(DPF_PORT)); print('Python Connected')"
77+
displayName: Start DPF Server
78+
79+
- script: |
80+
pip install -r requirements_test.txt
81+
cd tests
82+
pytest -v --junitxml=junit/test-results.xml --cov ansys.dpf.post --cov-report=xml
83+
displayName: Test Post API
84+
85+
- script: |
86+
type $(System.DefaultWorkingDirectory)\server\v211\aisol\bin\winx64\log.txt
87+
displayName: 'Show DPF Server Logs'
88+
condition: always()
89+
90+
- job: Linux
91+
variables:
92+
python.version: '3.7' # due to VTK 8.1.2 requirement for docbuild
93+
DISPLAY: ':99.0'
94+
PYANSYS_OFF_SCREEN: True
95+
DPF_PORT: 32772
96+
DPF_START_SERVER: False
97+
DPF_IMAGE: docker.pkg.github.com/pyansys/dpf-core/dpf:v2021.1
98+
DPF_DOCKER: True
99+
pool:
100+
vmImage: 'ubuntu-20.04'
101+
steps:
102+
- task: UsePythonVersion@0
103+
inputs:
104+
versionSpec: '$(python.version)'
105+
displayName: 'Use Python $(python.version)'
106+
107+
- script: |
108+
ls -lh .ci
109+
chmod +x .ci/setup_headless_display.sh
110+
.ci/setup_headless_display.sh
111+
pip install -r .ci/requirements_test_xvfb.txt
112+
python .ci/display_test.py
113+
displayName: Install and start a virtual framebuffer
114+
115+
- script: |
116+
pip install -r requirements_build.txt
117+
python setup.py bdist_wheel
118+
pip install --find-links=dist ansys_dpf_post
119+
cd tests
120+
python -c "from ansys.dpf import post; print(post.Report())"
121+
displayName: Install ansys-dpf-post
122+
123+
# this step is necessary as we're running in docker and the
124+
# examples directory must be local to the docker enviornment
125+
- script: |
126+
EXAMPLES_DIR=$(python -c "from ansys.dpf.core import examples; import os; print(os.path.dirname(examples.__file__))")
127+
mkdir -p ansys/dpf/core
128+
cp -r $EXAMPLES_DIR ansys/dpf/core
129+
displayName: Copy ansys.dpf.core examples to local directory
130+
131+
- script: |
132+
set -ex
133+
echo $(PAT) | docker login -u $(GH_USERNAME) --password-stdin docker.pkg.github.com
134+
docker pull $(DPF_IMAGE)
135+
docker run --restart always --name dpf -v `pwd`:/dpf -v /tmp:/dpf/_cache -p $(DPF_PORT):50054 $(DPF_IMAGE) > log.txt &
136+
grep -q 'server started on ip' <(timeout 60 tail -f log.txt)
137+
python -c "from ansys.dpf import core as dpf; dpf.connect_to_server(port=$(DPF_PORT)); print('Python Connected')"
138+
displayName: Pull, launch, and validate DPF service
139+
140+
- script: |
141+
pip install -r requirements_test.txt
142+
pip install pytest-azurepipelines
143+
cd tests
144+
pytest -v --junitxml=junit/test-results.xml --cov ansys.dpf.post --cov-report=xml --cov-report=html
145+
displayName: Test Post API
146+
147+
- script: |
148+
pip install twine
149+
python setup.py sdist
150+
twine upload --skip-existing dist/*
151+
displayName: 'Upload to PyPi'
152+
condition: contains(variables['Build.SourceBranch'], 'refs/tags/')
153+
env:
154+
TWINE_USERNAME: __token__
155+
TWINE_PASSWORD: $(PYPI_TOKEN)
156+
TWINE_REPOSITORY_URL: "https://upload.pypi.org/legacy/"

.ci/display_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""Quickly check if VTK off screen plotting works."""
2+
import pyvista
3+
from pyvista.plotting import system_supports_plotting
4+
5+
print('system_supports_plotting', system_supports_plotting())
6+
pyvista.OFF_SCREEN = True
7+
pyvista.plot(pyvista.Sphere())

.ci/install_opengl.ps1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Sample script to install Python and pip under Windows
2+
# Authors: Olivier Grisel, Jonathan Helmus and Kyle Kastner
3+
# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
4+
5+
# Adapted from VisPy
6+
7+
$MESA_GL_URL = "https://github.com/vispy/demo-data/raw/master/mesa/"
8+
9+
# Mesa DLLs found linked from:
10+
# http://qt-project.org/wiki/Cross-compiling-Mesa-for-Windows
11+
# to:
12+
# http://sourceforge.net/projects/msys2/files/REPOS/MINGW/x86_64/mingw-w64-x86_64-mesa-10.2.4-1-any.pkg.tar.xz/download
13+
14+
function DownloadMesaOpenGL ($architecture) {
15+
[Net.ServicePointManager]::SecurityProtocol = 'Ssl3, Tls, Tls11, Tls12'
16+
$webclient = New-Object System.Net.WebClient
17+
# Download and retry up to 3 times in case of network transient errors.
18+
$url = $MESA_GL_URL + "opengl32_mingw_" + $architecture + ".dll"
19+
if ($architecture -eq "32") {
20+
$filepath = "C:\Windows\SysWOW64\opengl32.dll"
21+
} else {
22+
$filepath = "C:\Windows\system32\opengl32.dll"
23+
}
24+
takeown /F $filepath /A
25+
icacls $filepath /grant "${env:ComputerName}\${env:UserName}:F"
26+
Remove-item -LiteralPath $filepath
27+
Write-Host "Downloading" $url
28+
$retry_attempts = 2
29+
for($i=0; $i -lt $retry_attempts; $i++){
30+
try {
31+
$webclient.DownloadFile($url, $filepath)
32+
break
33+
}
34+
Catch [Exception]{
35+
Start-Sleep 1
36+
}
37+
}
38+
if (Test-Path $filepath) {
39+
Write-Host "File saved at" $filepath
40+
} else {
41+
# Retry once to get the error message if any at the last try
42+
$webclient.DownloadFile($url, $filepath)
43+
}
44+
}
45+
46+
47+
function main () {
48+
DownloadMesaOpenGL "64"
49+
}
50+
51+
main

.ci/requirements_test_xvfb.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pyvista>=0.27.2

.ci/setup_headless_display.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -x
3+
4+
sudo apt-get update && sudo apt-get install -y libgl1-mesa-glx xvfb
5+
which Xvfb
6+
Xvfb $DISPLAY -screen 0 1024x768x24 > /dev/null 2>&1 &
7+
sleep 3
8+
set +x

.github/workflows/ci-build.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Build documentation
2+
name: Documentation Build
3+
4+
on: [push, pull_request, workflow_dispatch]
5+
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-20.04
10+
11+
env:
12+
DISPLAY: ':99.0'
13+
DPF_IMAGE: 'docker.pkg.github.com/pyansys/dpf-core/dpf:v2021.1'
14+
DPF_PORT: 32772
15+
DPF_START_SERVER: FALSE
16+
DPF_DOCKER: True
17+
PYANSYS_OFF_SCREEN: True
18+
19+
steps:
20+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
21+
- uses: actions/checkout@v2
22+
23+
- name: Setup Python
24+
uses: actions/[email protected]
25+
with:
26+
python-version: 3.7
27+
28+
- name: Install, start, and test the virtual framebuffer
29+
run: |
30+
chmod +x .ci/setup_headless_display.sh
31+
.ci/setup_headless_display.sh
32+
pip install -r .ci/requirements_test_xvfb.txt
33+
python .ci/display_test.py
34+
35+
- name: Install ansys.dpf.post
36+
run: |
37+
pip install -r requirements_build.txt
38+
pip install -e .
39+
cd tests
40+
python -c "from ansys.dpf import post; print(post.Report(gpu=False))"
41+
env:
42+
DEVOPS_PAT: ${{ secrets.DEVOPS_PACKAGES_PAT }}
43+
44+
- name: Copy ansys.dpf.core examples to local directory
45+
run: |
46+
EXAMPLES_DIR=$(python -c "from ansys.dpf.core import examples; import os; print(os.path.dirname(examples.__file__))")
47+
mkdir -p ansys/dpf/core
48+
cp -r $EXAMPLES_DIR ansys/dpf/core
49+
50+
- name: Pull, launch, and validate DPF service
51+
run: |
52+
echo $PAT | docker login -u $GH_USERNAME --password-stdin docker.pkg.github.com
53+
docker run --restart always --name dpf -v `pwd`:/dpf -v /tmp:/dpf/_cache -p $DPF_PORT:50054 $DPF_IMAGE > log.txt &
54+
grep -q 'server started on ip' <(timeout 60 tail -f log.txt)
55+
python -c "from ansys.dpf.post import examples;from ansys.dpf import core;print(core.Model(examples.simple_bar))"
56+
env:
57+
GH_USERNAME: ${{ secrets.GH_USERNAME }}
58+
PAT: ${{ secrets.REPO_DOWNLOAD_PAT }}
59+
60+
- name: Build Documentation
61+
run: |
62+
sudo apt-get install pandoc -qy
63+
pip install -r requirements_docs.txt
64+
make -C docs html
65+
touch docs/_build/html/.nojekyll
66+
67+
- name: Upload Documentation
68+
uses: actions/[email protected]
69+
with:
70+
name: Documentation
71+
path: docs/_build/html
72+
retention-days: 7
73+
74+
- name: Deploy
75+
uses: JamesIves/[email protected]
76+
if: startsWith(github.ref, 'refs/tags/')
77+
with:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
BRANCH: gh-pages
80+
FOLDER: docs/_build/html
81+
CLEAN: true

.github/workflows/style.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# check spelling, codestyle
2+
name: Style Check
3+
4+
on: [push, pull_request, workflow_dispatch]
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-20.04
9+
10+
steps:
11+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
12+
- uses: actions/checkout@v2
13+
14+
- name: Setup Python
15+
uses: actions/[email protected]
16+
with:
17+
python-version: 3.8
18+
19+
- name: Style
20+
run: |
21+
pip install -r requirements_style.txt --disable-pip-version-check
22+
make

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
## DPF
33
#########################
44

5-
/__pycache__
5+
__pycache__
66
/.pytest_cache
77
/.spyproject
88

9+
910
#tests
1011
/tests/__pycache__
1112
/tests/.pytest_cache

ansys/dpf/post/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from ansys.dpf.post.post_utility import load_solution, print_available_keywords
44
from ansys import dpf
55

6+
from ansys.dpf.post.misc import Report
7+
68
"""Post-processing module. Using Data Processing Framework.
79
Allow to create a result object, then use it to get wanted results.
810
@@ -17,6 +19,3 @@
1719
#dpf.core.start_local_server()
1820

1921

20-
21-
22-

ansys/dpf/post/examples/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
"""DPF-Post example files"""
2+
import os
3+
4+
# alias files used by the core
25
from ansys.dpf.core.examples import (
36
simple_bar,
47
static_rst,
@@ -13,3 +16,7 @@
1316
download_transient_result,
1417
msup_transient,
1518
)
19+
20+
# must copy files over when using docker
21+
# running_docker = os.environ.get('DPF_DOCKER', False)
22+
# breakpoint()

0 commit comments

Comments
 (0)