From fc5c445cee5f26ff3874c3a7a15102308ae7e4b7 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 3 Oct 2023 09:34:29 +1300 Subject: [PATCH 1/7] Add support for Python 3.12 Python 3.12 has been released on 2 Oct 2023, changelog is at https://docs.python.org/3.12/whatsnew/3.12.html --- .github/workflows/cache_data.yaml | 2 +- .github/workflows/ci_docs.yml | 4 ++-- .github/workflows/ci_doctests.yaml | 2 +- .github/workflows/ci_tests.yaml | 10 +++++----- .github/workflows/ci_tests_dev.yaml | 2 +- .github/workflows/format-command.yml | 2 +- .github/workflows/publish-to-pypi.yml | 2 +- .github/workflows/style_checks.yaml | 2 +- doc/install.rst | 4 ++-- pyproject.toml | 1 + 10 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/workflows/cache_data.yaml b/.github/workflows/cache_data.yaml index 56249a077a1..907ad5142e4 100644 --- a/.github/workflows/cache_data.yaml +++ b/.github/workflows/cache_data.yaml @@ -43,7 +43,7 @@ jobs: - conda-forge - nodefaults create-args: >- - python=3.11 + python=3.12 gmt=6.4.0 numpy pandas diff --git a/.github/workflows/ci_docs.yml b/.github/workflows/ci_docs.yml index 6e5fd719608..f4de63c0841 100644 --- a/.github/workflows/ci_docs.yml +++ b/.github/workflows/ci_docs.yml @@ -44,7 +44,7 @@ jobs: # Is it a draft Pull Request (true or false)? isDraft: - ${{ github.event.pull_request.draft }} - # Only run one job (Ubuntu + Python 3.11) for draft PRs + # Only run one job (Ubuntu + Python 3.12) for draft PRs exclude: - os: macos-latest isDraft: true @@ -75,7 +75,7 @@ jobs: cache-downloads: true cache-environment: true create-args: >- - python=3.11 + python=3.12 gmt=6.4.0 numpy pandas diff --git a/.github/workflows/ci_doctests.yaml b/.github/workflows/ci_doctests.yaml index 9f8a49e7252..963b72723ef 100644 --- a/.github/workflows/ci_doctests.yaml +++ b/.github/workflows/ci_doctests.yaml @@ -48,7 +48,7 @@ jobs: - conda-forge - nodefaults create-args: >- - python=3.11 + python=3.12 gmt=6.4.0 numpy pandas diff --git a/.github/workflows/ci_tests.yaml b/.github/workflows/ci_tests.yaml index 55c38d1628a..8340e09cf3c 100644 --- a/.github/workflows/ci_tests.yaml +++ b/.github/workflows/ci_tests.yaml @@ -52,24 +52,24 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.9', '3.11'] + python-version: ['3.9', '3.12'] os: [ubuntu-latest, macos-latest, windows-latest] # Is it a draft Pull Request (true or false)? isDraft: - ${{ github.event.pull_request.draft }} - # Only run two jobs (Ubuntu + Python 3.9/3.11) for draft PRs + # Only run two jobs (Ubuntu + Python 3.9/3.12) for draft PRs exclude: - os: macos-latest isDraft: true - os: windows-latest isDraft: true - # Pair Python 3.9 with NumPy 1.22 and Python 3.11 with NumPy 1.25 - # Only install optional packages on Python 3.11/NumPy 1.25 + # Pair Python 3.9 with NumPy 1.22 and Python 3.12 with NumPy 1.25 + # Only install optional packages on Python 3.12/NumPy 1.25 include: - python-version: '3.9' numpy-version: '1.22' optional-packages: '' - - python-version: '3.11' + - python-version: '3.12' numpy-version: '1.25' optional-packages: ' contextily geopandas ipython rioxarray sphinx-gallery' diff --git a/.github/workflows/ci_tests_dev.yaml b/.github/workflows/ci_tests_dev.yaml index a6dc9099e2f..bf2ff732cf3 100644 --- a/.github/workflows/ci_tests_dev.yaml +++ b/.github/workflows/ci_tests_dev.yaml @@ -100,7 +100,7 @@ jobs: cache-downloads: true cache-environment: true create-args: >- - python=3.11 + python=3.12 cmake make ninja diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index a305272c021..e2aa94c58aa 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -27,7 +27,7 @@ jobs: # Setup Python environment - uses: actions/setup-python@v4.7.0 with: - python-version: '3.11' + python-version: '3.12' # Install formatting tools - name: Install formatting tools diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 908727964d4..9cc1fca8f75 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -46,7 +46,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4.7.0 with: - python-version: '3.11' + python-version: '3.12' - name: Install dependencies run: python -m pip install build diff --git a/.github/workflows/style_checks.yaml b/.github/workflows/style_checks.yaml index 894be0d6f4e..b2b7af33ec0 100644 --- a/.github/workflows/style_checks.yaml +++ b/.github/workflows/style_checks.yaml @@ -30,7 +30,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4.7.0 with: - python-version: '3.11' + python-version: '3.12' - name: Install packages run: | diff --git a/doc/install.rst b/doc/install.rst index c64695502a5..5b1d0a2a79d 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -132,14 +132,14 @@ want): :: - mamba create --name pygmt python=3.11 numpy pandas xarray netcdf4 packaging gmt + mamba create --name pygmt python=3.12 numpy pandas xarray netcdf4 packaging gmt .. tab-item:: conda :sync: conda :: - conda create --name pygmt python=3.11 numpy pandas xarray netcdf4 packaging gmt + conda create --name pygmt python=3.12 numpy pandas xarray netcdf4 packaging gmt Activate the environment by running the following (**do not forget this step!**): diff --git a/pyproject.toml b/pyproject.toml index c3c229939ed..b5223c3281b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "License :: OSI Approved :: BSD License", ] dependencies = [ From 6bded071077cec408668f1296e934961390d03f6 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 3 Oct 2023 09:53:00 +1300 Subject: [PATCH 2/7] Add conda-forge/label/python_rc channel --- .github/workflows/ci_docs.yml | 1 + .github/workflows/ci_tests.yaml | 1 + .github/workflows/ci_tests_dev.yaml | 1 + 3 files changed, 3 insertions(+) diff --git a/.github/workflows/ci_docs.yml b/.github/workflows/ci_docs.yml index f4de63c0841..a7a8e780a55 100644 --- a/.github/workflows/ci_docs.yml +++ b/.github/workflows/ci_docs.yml @@ -72,6 +72,7 @@ jobs: channels: - conda-forge - nodefaults + - conda-forge/label/python_rc cache-downloads: true cache-environment: true create-args: >- diff --git a/.github/workflows/ci_tests.yaml b/.github/workflows/ci_tests.yaml index 8340e09cf3c..8779b43c73d 100644 --- a/.github/workflows/ci_tests.yaml +++ b/.github/workflows/ci_tests.yaml @@ -101,6 +101,7 @@ jobs: channels: - conda-forge - nodefaults + - conda-forge/label/python_rc cache-downloads: true cache-environment: true create-args: >- diff --git a/.github/workflows/ci_tests_dev.yaml b/.github/workflows/ci_tests_dev.yaml index bf2ff732cf3..f02158478d5 100644 --- a/.github/workflows/ci_tests_dev.yaml +++ b/.github/workflows/ci_tests_dev.yaml @@ -97,6 +97,7 @@ jobs: channels: - conda-forge - nodefaults + - conda-forge/label/python_rc cache-downloads: true cache-environment: true create-args: >- From 654e8bea7af8be2896b80c6383dc1879adb8a39e Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:39:01 +1300 Subject: [PATCH 3/7] Revert "Add conda-forge/label/python_rc channel" This reverts commit 6bded071077cec408668f1296e934961390d03f6. --- .github/workflows/ci_docs.yml | 1 - .github/workflows/ci_tests.yaml | 1 - .github/workflows/ci_tests_dev.yaml | 1 - 3 files changed, 3 deletions(-) diff --git a/.github/workflows/ci_docs.yml b/.github/workflows/ci_docs.yml index a7a8e780a55..f4de63c0841 100644 --- a/.github/workflows/ci_docs.yml +++ b/.github/workflows/ci_docs.yml @@ -72,7 +72,6 @@ jobs: channels: - conda-forge - nodefaults - - conda-forge/label/python_rc cache-downloads: true cache-environment: true create-args: >- diff --git a/.github/workflows/ci_tests.yaml b/.github/workflows/ci_tests.yaml index 8779b43c73d..8340e09cf3c 100644 --- a/.github/workflows/ci_tests.yaml +++ b/.github/workflows/ci_tests.yaml @@ -101,7 +101,6 @@ jobs: channels: - conda-forge - nodefaults - - conda-forge/label/python_rc cache-downloads: true cache-environment: true create-args: >- diff --git a/.github/workflows/ci_tests_dev.yaml b/.github/workflows/ci_tests_dev.yaml index f02158478d5..bf2ff732cf3 100644 --- a/.github/workflows/ci_tests_dev.yaml +++ b/.github/workflows/ci_tests_dev.yaml @@ -97,7 +97,6 @@ jobs: channels: - conda-forge - nodefaults - - conda-forge/label/python_rc cache-downloads: true cache-environment: true create-args: >- From d1b01c388bb6ff43ae608d7649dbf6734d822876 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Wed, 25 Oct 2023 17:57:37 +1300 Subject: [PATCH 4/7] Fix DeprecationWarning with use of datetime.utcnow() on Python 3.12 Replace deprecated datetime.datetime.utcnow() with datetime.datetime.now(tz=datetime.UTC). --- pygmt/tests/test_clib_put_vector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_clib_put_vector.py b/pygmt/tests/test_clib_put_vector.py index de137e13781..521984ba217 100644 --- a/pygmt/tests/test_clib_put_vector.py +++ b/pygmt/tests/test_clib_put_vector.py @@ -1,8 +1,8 @@ """ Test the functions that put vector data into GMT. """ +import datetime import itertools -from datetime import datetime import numpy as np import numpy.testing as npt @@ -122,7 +122,7 @@ def test_put_vector_string_dtype(): "2021-02-03T00:00:00", "2021-02-03T04:00:00", "2021-02-03T04:05:06", - f"{datetime.utcnow().strftime('%Y-%m-%d')}T04:50:06", + f"{datetime.datetime.now(tz=datetime.UTC).strftime('%Y-%m-%d')}T04:50:06", ], ] From a048c8617e2b8e77a79e3743ab76bfbcced0484a Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:54:07 +1300 Subject: [PATCH 5/7] Pretend to be on macOS instead of Windows Workaround for AttributeError: 'NoneType' object has no attribute 'NeedCurrentDirectoryForExePath' when calling`_winapi.NeedCurrentDirectoryForExePath`, where `_winapi` is None on UNIX. See https://github.com/GenericMappingTools/pygmt/pull/2711#issuecomment-1778456261 --- pygmt/tests/test_clib_loading.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_clib_loading.py b/pygmt/tests/test_clib_loading.py index 055badd8656..1330d71ccd0 100644 --- a/pygmt/tests/test_clib_loading.py +++ b/pygmt/tests/test_clib_loading.py @@ -72,7 +72,7 @@ def test_load_libgmt_fails(monkeypatch): be found. """ with monkeypatch.context() as mpatch: - mpatch.setattr(sys, "platform", "win32") # pretend to be on Windows + mpatch.setattr(sys, "platform", "darwin") # pretend to be on macOS mpatch.setattr( subprocess, "check_output", lambda cmd, encoding: "libfakegmt.so" ) From 90a3a497816cf85109c0acbdacd26a510cd70b14 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 26 Oct 2023 14:17:19 +1300 Subject: [PATCH 6/7] Use datetime.timezone.utc instead of Python 3.11+ only datetime.UTC Make the test compatible with Python<3.11 --- pygmt/tests/test_clib_put_vector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_clib_put_vector.py b/pygmt/tests/test_clib_put_vector.py index 521984ba217..e9da9e6242a 100644 --- a/pygmt/tests/test_clib_put_vector.py +++ b/pygmt/tests/test_clib_put_vector.py @@ -122,7 +122,7 @@ def test_put_vector_string_dtype(): "2021-02-03T00:00:00", "2021-02-03T04:00:00", "2021-02-03T04:05:06", - f"{datetime.datetime.now(tz=datetime.UTC).strftime('%Y-%m-%d')}T04:50:06", + f"{datetime.datetime.now(tz=datetime.timezone.utc).strftime('%Y-%m-%d')}T04:50:06", ], ] From 99fdbf8403bd238226cc752485df1ab1891c2088 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 7 Nov 2023 14:36:12 +1300 Subject: [PATCH 7/7] Pretend to be on macOS if running on Linux, and vice versa Hack test_load_libgmt_fails, so that if on Linux, sys.platform returns 'darwin', and if on macOS, sys.platform returns 'linux'. --- pygmt/tests/test_clib_loading.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pygmt/tests/test_clib_loading.py b/pygmt/tests/test_clib_loading.py index abf8d423e48..f3871b5c7b4 100644 --- a/pygmt/tests/test_clib_loading.py +++ b/pygmt/tests/test_clib_loading.py @@ -73,7 +73,12 @@ def test_load_libgmt_fails(monkeypatch): be found. """ with monkeypatch.context() as mpatch: - mpatch.setattr(sys, "platform", "darwin") # pretend to be on macOS + mpatch.setattr( + sys, + "platform", + # Pretend to be on macOS if running on Linux, and vice versa + "darwin" if sys.platform == "linux" else "linux", + ) mpatch.setattr( subprocess, "check_output", lambda cmd, encoding: "libfakegmt.so" )