Skip to content

Commit

Permalink
CI: Test GMT dev version on Windows by building from source
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Oct 27, 2023
1 parent f828bc5 commit 000ca3d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
59 changes: 31 additions & 28 deletions .github/workflows/ci_tests_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
# This workflow runs regular PyGMT tests with the GMT dev version, and also
# pre-release versions of several dependencies like NumPy, Pandas, Xarray, etc.
# If any tests fail, it also uploads the diff images as workflow artifacts.
# On Linux/macOS, GMT dev version is installed by fetching the latest source
# codes from the GMT master branch and compiling.
# On Windows, GMT dev version is installed from the conda-forge's dev channel
# due to the complexity of building GMT source codes on Windows.
# The GMT dev version is installed by fetching the latest source codes from
# the GMT master branch and compiling.
#
# It is triggered when a pull request is marked as "ready as review", or using
# the slash command `/test-gmt-dev`. It is also scheduled to run on Monday,
Expand All @@ -16,7 +14,7 @@ name: GMT Dev Tests

on:
# push:
# branches: [ main ]
# branches: [ main ]
pull_request:
types: [ready_for_review]
paths-ignore:
Expand Down Expand Up @@ -116,6 +114,33 @@ jobs:
pcre
zlib
# Build and install latest GMT from GitHub
- name: Install GMT ${{ matrix.gmt_git_ref }} branch (Linux/macOS)
run: curl https://raw.githubusercontent.com/GenericMappingTools/gmt/master/ci/build-gmt.sh | bash
env:
GMT_GIT_REF: ${{ matrix.gmt_git_ref }}
GMT_INSTALL_DIR: ${{ github.workspace }}/gmt-install-dir
if: runner.os != 'Windows'

- name: Install GMT ${{ matrix.gmt_git_ref }} branch (Windows)
shell: cmd
run: |
git clone --depth=1 --single-branch --branch ${{ env.GMT_GIT_REF }} https://github.com/GenericMappingTools/gmt
cd gmt/
mkdir build
cd build
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake -G Ninja .. -DCMAKE_INSTALL_PREFIX=${{ env.GMT_INSTALL_DIR }} -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=${{ env.MAMBA_ROOT_PREFIX }}\envs\pygmt\Library
cmake --build .
cmake --build . --target install
env:
GMT_GIT_REF: ${{ matrix.gmt_git_ref }}
GMT_INSTALL_DIR: ${{ github.workspace }}/gmt-install-dir
if: runner.os == 'Windows'

- name: Add GMT's bin to PATH
run: echo '${{ github.workspace }}/gmt-install-dir/bin' >> $GITHUB_PATH

# Install dependencies from PyPI
- name: Install dependencies
run: |
Expand All @@ -136,18 +161,6 @@ jobs:
dvc pull
ls -lhR pygmt/tests/baseline/
# Build and install latest GMT from GitHub
- name: Install GMT ${{ matrix.gmt_git_ref }} branch (Linux/macOS)
run: curl https://raw.githubusercontent.com/GenericMappingTools/gmt/master/ci/build-gmt.sh | bash
env:
GMT_GIT_REF: ${{ matrix.gmt_git_ref }}
GMT_INSTALL_DIR: ${{ github.workspace }}/gmt-install-dir
if: runner.os != 'Windows'

- name: Install GMT dev version from conda-forge (Windows)
run: micromamba install -c conda-forge/label/dev gmt
if: runner.os == 'Windows'

# Download cached remote files (artifacts) from GitHub
- name: Download remote data from GitHub
uses: dawidd6/action-download-artifact@v2.28.0
Expand All @@ -170,21 +183,11 @@ jobs:
- name: Install the package
run: make install

- name: Add GMT's bin to PATH (Linux/macOS)
run: echo ${GITHUB_WORKSPACE}/gmt-install-dir/bin >> $GITHUB_PATH
if: runner.os != 'Windows'

# Run the tests
- name: Test with pytest (Linux/macOS)
- name: Test with pytest
run: make test PYTEST_EXTRA="-r P"
env:
GMT_LIBRARY_PATH: ${{ github.workspace }}/gmt-install-dir/lib
if: runner.os != 'Windows'

# Run the tests
- name: Test with pytest (Windows)
run: make test PYTEST_EXTRA="-r P"
if: runner.os == 'Windows'

# Upload diff images on test failure
- name: Upload diff images if any test fails
Expand Down
8 changes: 4 additions & 4 deletions pygmt/tests/test_clib_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test the functions that load libgmt.
"""
import ctypes
import os
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -280,9 +281,8 @@ def test_clib_full_names_gmt_library_path_undefined_path_included(
"""
with monkeypatch.context() as mpatch:
mpatch.delenv("GMT_LIBRARY_PATH", raising=False)
mpatch.setenv("PATH", gmt_bin_dir)
mpatch.setenv("PATH", gmt_bin_dir, prepend=os.pathsep)
lib_fullpaths = clib_full_names()

assert isinstance(lib_fullpaths, types.GeneratorType)
# Windows: find_library() searches the library in PATH, so one more
npath = 2 if sys.platform == "win32" else 1
Expand All @@ -298,7 +298,7 @@ def test_clib_full_names_gmt_library_path_defined_path_included(
"""
with monkeypatch.context() as mpatch:
mpatch.setenv("GMT_LIBRARY_PATH", str(PurePath(gmt_lib_realpath).parent))
mpatch.setenv("PATH", gmt_bin_dir)
mpatch.setenv("PATH", gmt_bin_dir, prepend=os.pathsep)
lib_fullpaths = clib_full_names()

assert isinstance(lib_fullpaths, types.GeneratorType)
Expand All @@ -317,7 +317,7 @@ def test_clib_full_names_gmt_library_path_incorrect_path_included(
"""
with monkeypatch.context() as mpatch:
mpatch.setenv("GMT_LIBRARY_PATH", "/not/a/valid/library/path")
mpatch.setenv("PATH", gmt_bin_dir)
mpatch.setenv("PATH", gmt_bin_dir, prepend=os.pathsep)
lib_fullpaths = clib_full_names()

assert isinstance(lib_fullpaths, types.GeneratorType)
Expand Down

0 comments on commit 000ca3d

Please sign in to comment.