From 8b39741bba8c06652c7def81821b5841adc17582 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Tue, 28 Mar 2023 08:42:00 -0600 Subject: [PATCH] ENH: Add qt and pyvista options (#7) --- .github/workflows/local.yml | 18 ++++++++++++-- README.md | 11 +++++++++ action.yml | 30 +++++++++++++++++------- test_pyvista.py => tests/test_pyvista.py | 4 +++- tests/test_qt.py | 6 +++++ 5 files changed, 57 insertions(+), 12 deletions(-) rename test_pyvista.py => tests/test_pyvista.py (71%) create mode 100644 tests/test_qt.py diff --git a/.github/workflows/local.yml b/.github/workflows/local.yml index 0e7bcc8..f9f45f5 100644 --- a/.github/workflows/local.yml +++ b/.github/workflows/local.yml @@ -17,6 +17,10 @@ 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 @@ -24,17 +28,19 @@ jobs: - 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: @@ -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 diff --git a/README.md b/README.md index 3dc8bb6..ca5b264 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 96e0a42..2d58782 100644 --- a/action.yml +++ b/action.yml @@ -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' @@ -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 diff --git a/test_pyvista.py b/tests/test_pyvista.py similarity index 71% rename from test_pyvista.py rename to tests/test_pyvista.py index b1fa05c..6e9b0c5 100644 --- a/test_pyvista.py +++ b/tests/test_pyvista.py @@ -1,4 +1,5 @@ """Quickly check if VTK off screen plotting works.""" +from pathlib import Path import pyvista from pyvista.plotting import system_supports_plotting @@ -6,4 +7,5 @@ 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) diff --git a/tests/test_qt.py b/tests/test_qt.py new file mode 100644 index 0000000..1d1b6c7 --- /dev/null +++ b/tests/test_qt.py @@ -0,0 +1,6 @@ +import matplotlib +matplotlib.use('QtAgg') +import matplotlib.pyplot as plt +plt.figure() +backend = matplotlib.get_backend() +assert backend == 'QtAgg', backend