Skip to content

Commit 5b20c5e

Browse files
committed
CI: Test GMT dev version on Windows by building from source
1 parent f828bc5 commit 5b20c5e

2 files changed

Lines changed: 36 additions & 32 deletions

File tree

.github/workflows/ci_tests_dev.yaml

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
# This workflow runs regular PyGMT tests with the GMT dev version, and also
44
# pre-release versions of several dependencies like NumPy, Pandas, Xarray, etc.
55
# If any tests fail, it also uploads the diff images as workflow artifacts.
6-
# On Linux/macOS, GMT dev version is installed by fetching the latest source
7-
# codes from the GMT master branch and compiling.
8-
# On Windows, GMT dev version is installed from the conda-forge's dev channel
9-
# due to the complexity of building GMT source codes on Windows.
6+
# The GMT dev version is installed by fetching the latest source codes from
7+
# the GMT master branch and compiling.
108
#
119
# It is triggered when a pull request is marked as "ready as review", or using
1210
# the slash command `/test-gmt-dev`. It is also scheduled to run on Monday,
@@ -16,7 +14,7 @@ name: GMT Dev Tests
1614

1715
on:
1816
# push:
19-
# branches: [ main ]
17+
# branches: [ main ]
2018
pull_request:
2119
types: [ready_for_review]
2220
paths-ignore:
@@ -116,6 +114,34 @@ jobs:
116114
pcre
117115
zlib
118116
117+
# Build and install latest GMT from GitHub
118+
- name: Install GMT ${{ matrix.gmt_git_ref }} branch (Linux/macOS)
119+
run: curl https://raw.githubusercontent.com/GenericMappingTools/gmt/master/ci/build-gmt.sh | bash
120+
env:
121+
GMT_GIT_REF: ${{ matrix.gmt_git_ref }}
122+
GMT_INSTALL_DIR: ${{ github.workspace }}/gmt-install-dir
123+
if: runner.os != 'Windows'
124+
125+
- name: Install GMT ${{ matrix.gmt_git_ref }} branch (Windows)
126+
shell: cmd
127+
run: |
128+
git clone --depth=1 --single-branch --branch ${{ env.GMT_GIT_REF }} https://github.com/GenericMappingTools/gmt
129+
cd gmt/
130+
mkdir build
131+
cd build
132+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
133+
cmake -G Ninja .. -DCMAKE_INSTALL_PREFIX=${{ env.GMT_INSTALL_DIR }} -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=${{ env.MAMBA_ROOT_PREFIX }}\envs\pygmt\Library
134+
cmake --build .
135+
cmake --build . --target install
136+
env:
137+
GMT_GIT_REF: ${{ matrix.gmt_git_ref }}
138+
GMT_INSTALL_DIR: ${{ github.workspace }}/gmt-install-dir
139+
if: runner.os == 'Windows'
140+
141+
- name: Add GMT's bin to PATH
142+
run: |
143+
echo '${{ github.workspace }}/gmt-install-dir/bin' >> $GITHUB_PATH
144+
119145
# Install dependencies from PyPI
120146
- name: Install dependencies
121147
run: |
@@ -136,18 +162,6 @@ jobs:
136162
dvc pull
137163
ls -lhR pygmt/tests/baseline/
138164
139-
# Build and install latest GMT from GitHub
140-
- name: Install GMT ${{ matrix.gmt_git_ref }} branch (Linux/macOS)
141-
run: curl https://raw.githubusercontent.com/GenericMappingTools/gmt/master/ci/build-gmt.sh | bash
142-
env:
143-
GMT_GIT_REF: ${{ matrix.gmt_git_ref }}
144-
GMT_INSTALL_DIR: ${{ github.workspace }}/gmt-install-dir
145-
if: runner.os != 'Windows'
146-
147-
- name: Install GMT dev version from conda-forge (Windows)
148-
run: micromamba install -c conda-forge/label/dev gmt
149-
if: runner.os == 'Windows'
150-
151165
# Download cached remote files (artifacts) from GitHub
152166
- name: Download remote data from GitHub
153167
uses: dawidd6/action-download-artifact@v2.28.0
@@ -170,21 +184,11 @@ jobs:
170184
- name: Install the package
171185
run: make install
172186

173-
- name: Add GMT's bin to PATH (Linux/macOS)
174-
run: echo ${GITHUB_WORKSPACE}/gmt-install-dir/bin >> $GITHUB_PATH
175-
if: runner.os != 'Windows'
176-
177187
# Run the tests
178-
- name: Test with pytest (Linux/macOS)
188+
- name: Test with pytest
179189
run: make test PYTEST_EXTRA="-r P"
180190
env:
181191
GMT_LIBRARY_PATH: ${{ github.workspace }}/gmt-install-dir/lib
182-
if: runner.os != 'Windows'
183-
184-
# Run the tests
185-
- name: Test with pytest (Windows)
186-
run: make test PYTEST_EXTRA="-r P"
187-
if: runner.os == 'Windows'
188192

189193
# Upload diff images on test failure
190194
- name: Upload diff images if any test fails

pygmt/tests/test_clib_loading.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test the functions that load libgmt.
33
"""
44
import ctypes
5+
import os
56
import shutil
67
import subprocess
78
import sys
@@ -280,9 +281,8 @@ def test_clib_full_names_gmt_library_path_undefined_path_included(
280281
"""
281282
with monkeypatch.context() as mpatch:
282283
mpatch.delenv("GMT_LIBRARY_PATH", raising=False)
283-
mpatch.setenv("PATH", gmt_bin_dir)
284+
mpatch.setenv("PATH", gmt_bin_dir, prepend=os.pathsep)
284285
lib_fullpaths = clib_full_names()
285-
286286
assert isinstance(lib_fullpaths, types.GeneratorType)
287287
# Windows: find_library() searches the library in PATH, so one more
288288
npath = 2 if sys.platform == "win32" else 1
@@ -298,7 +298,7 @@ def test_clib_full_names_gmt_library_path_defined_path_included(
298298
"""
299299
with monkeypatch.context() as mpatch:
300300
mpatch.setenv("GMT_LIBRARY_PATH", str(PurePath(gmt_lib_realpath).parent))
301-
mpatch.setenv("PATH", gmt_bin_dir)
301+
mpatch.setenv("PATH", gmt_bin_dir, prepend=os.pathsep)
302302
lib_fullpaths = clib_full_names()
303303

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

323323
assert isinstance(lib_fullpaths, types.GeneratorType)

0 commit comments

Comments
 (0)