From a320c3fa00e342aa5a7a0256e3a1cbc3e23564ea Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Wed, 8 Nov 2023 02:12:37 +1300 Subject: [PATCH] Add support for Python 3.12 (#2711) * 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 * Fix DeprecationWarning with use of datetime.utcnow() on Python 3.12 * Use datetime.timezone.utc instead of Python 3.11+ only datetime.UTC * 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'. --- .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 ++-- pygmt/tests/test_clib_loading.py | 7 ++++++- pygmt/tests/test_clib_put_vector.py | 4 ++-- pyproject.toml | 1 + 12 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.github/workflows/cache_data.yaml b/.github/workflows/cache_data.yaml index 710c1781285..6db77a2a1ba 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 11e225e323b..2a2f590082d 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 ghostscript=9.54.0 numpy diff --git a/.github/workflows/ci_doctests.yaml b/.github/workflows/ci_doctests.yaml index 649a9f6604c..390c17b67e8 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 3f6ebbd92cd..5016d991399 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.26 - # Only install optional packages on Python 3.11/NumPy 1.26 + # Pair Python 3.9 with NumPy 1.22 and Python 3.12 with NumPy 1.26 + # Only install optional packages on Python 3.12/NumPy 1.26 include: - python-version: '3.9' numpy-version: '1.22' optional-packages: '' - - python-version: '3.11' + - python-version: '3.12' numpy-version: '1.26' 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 6ea32c69707..3a565cac466 100644 --- a/.github/workflows/ci_tests_dev.yaml +++ b/.github/workflows/ci_tests_dev.yaml @@ -98,7 +98,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 30272d29e46..f40234f8be3 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.1 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 7c500b11eb0..963b426e5d7 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.1 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 92b10452ef8..a286b7c85b5 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.1 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/pygmt/tests/test_clib_loading.py b/pygmt/tests/test_clib_loading.py index 445fa34f7dc..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", "win32") # pretend to be on Windows + 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" ) diff --git a/pygmt/tests/test_clib_put_vector.py b/pygmt/tests/test_clib_put_vector.py index de137e13781..e9da9e6242a 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.timezone.utc).strftime('%Y-%m-%d')}T04:50:06", ], ] diff --git a/pyproject.toml b/pyproject.toml index 91d3c15a0ae..9414f2a557b 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 = [