Skip to content

Commit

Permalink
ENH: Add qt and pyvista options (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Mar 28, 2023
1 parent a90d08f commit 8b39741
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,30 @@ jobs:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-2019, windows-2022]
qt: [""]
include:
- os: ubuntu-latest
qt: "qt"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Test Action
uses: ./
with:
qt: ${{ matrix.qt == 'qt' }}

- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.9
python-version: "3.9"

- name: Install PyVista
run: pip install pyvista

- name: Test PyVista
run: python test_pyvista.py
run: python tests/test_pyvista.py

- uses: actions/upload-artifact@v2
with:
Expand All @@ -44,6 +50,14 @@ jobs:
- name: Second test of PyVista
run: python -c "import pyvista;pyvista.Cube().plot(screenshot='${{ matrix.os }}-cube.png')"

- name: Test Qt
if: matrix.qt == 'qt'
run: |
set -eo pipefail
pip install PyQt6 matplotlib
QT_DEBUG_PLUGINS=1 LIBGL_DEBUG=verbose python tests/test_qt.py
shell: bash

- uses: actions/upload-artifact@v2
with:
name: cube
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ jobs:
uses: pyvista/setup-headless-display-action@v1
```
### Options
- `qt` (default `false`): set to `true` to install libraries required for Qt
on Linux, e.g.:
```yml
- uses: pyvista/setup-headless-display-action@v1
with:
qt: true
```
- `pyvista` (default `true`): set to `false` if you don't want to set env
vars to use PyVista in offscreen mode.

### 🖼️ PyVista Example

Expand Down
30 changes: 21 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
name: 'setup-headless-display-action'
description: 'Setup a headless display on Linux and Windows'
author: PyVista Developers'
inputs:
pyvista:
description: "Set PyVista env vars for headless mode"
required: false
default: true
qt:
description: "Install libraries required for Qt on Linux"
required: false
default: false
branding:
icon: 'monitor'
color: 'blue'
runs:
using: "composite"
steps:
- name: Install Linux GL Dependencies

- name: Install Linux dependencies
if: runner.os == 'Linux'
shell: bash
run: sudo apt-get update && sudo apt-get install libgl1-mesa-glx xvfb -y
# TODO: Pyvista uses `xset` which is part of x11-xserver-utils, maybe a better way to check?
run: sudo apt update && sudo apt install libgl1-mesa-glx xvfb x11-xserver-utils -y

- name: Install Linux Qt dependencies
if: runner.os == 'Linux' && inputs.qt != 'false'
shell: bash
run: sudo apt install libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 libopengl0 libegl1 libosmesa6 mesa-utils libxcb-shape0

- name: Install Windows GL Dependencies
if: runner.os == 'Windows'
Expand All @@ -28,19 +44,15 @@ runs:
export DISPLAY=:99.0
echo "DISPLAY=:99.0" >> $GITHUB_ENV
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- name: Give xvfb some time to start on Linux
if: runner.os == 'Linux'
shell: bash
run: sleep 3
sleep 3
- name: Configure for PyVista on Linux and macOS
if: runner.os != 'Windows'
if: runner.os != 'Windows' && inputs.pyvista != 'false'
shell: bash
run: echo "PYVISTA_OFF_SCREEN=true" >> $GITHUB_ENV

- name: Configure for PyVista on Windows
if: runner.os == 'Windows'
if: runner.os == 'Windows' && inputs.pyvista != 'false'
shell: powershell
run: |
chcp 65001 #set code page to utf-8
Expand Down
4 changes: 3 additions & 1 deletion test_pyvista.py → tests/test_pyvista.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Quickly check if VTK off screen plotting works."""
from pathlib import Path
import pyvista
from pyvista.plotting import system_supports_plotting

print(f'system_supports_plotting: {system_supports_plotting()}')
assert system_supports_plotting()
# pyvista.OFF_SCREEN = True # should be set by Action in Env
sphere = pyvista.Sphere()
pyvista.plot(sphere, screenshot='sphere.png')
out_path = Path(__file__).parent / '..' / 'sphere.png'
pyvista.plot(sphere, screenshot=out_path)
6 changes: 6 additions & 0 deletions tests/test_qt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import matplotlib
matplotlib.use('QtAgg')
import matplotlib.pyplot as plt
plt.figure()
backend = matplotlib.get_backend()
assert backend == 'QtAgg', backend

0 comments on commit 8b39741

Please sign in to comment.