Skip to content

Commit a320c3f

Browse files
authored
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'.
1 parent 19639fe commit a320c3f

12 files changed

+24
-18
lines changed

.github/workflows/cache_data.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- conda-forge
4444
- nodefaults
4545
create-args: >-
46-
python=3.11
46+
python=3.12
4747
gmt=6.4.0
4848
numpy
4949
pandas

.github/workflows/ci_docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
# Is it a draft Pull Request (true or false)?
4545
isDraft:
4646
- ${{ github.event.pull_request.draft }}
47-
# Only run one job (Ubuntu + Python 3.11) for draft PRs
47+
# Only run one job (Ubuntu + Python 3.12) for draft PRs
4848
exclude:
4949
- os: macos-latest
5050
isDraft: true
@@ -75,7 +75,7 @@ jobs:
7575
cache-downloads: true
7676
cache-environment: true
7777
create-args: >-
78-
python=3.11
78+
python=3.12
7979
gmt=6.4.0
8080
ghostscript=9.54.0
8181
numpy

.github/workflows/ci_doctests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- conda-forge
4949
- nodefaults
5050
create-args: >-
51-
python=3.11
51+
python=3.12
5252
gmt=6.4.0
5353
numpy
5454
pandas

.github/workflows/ci_tests.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,24 @@ jobs:
5252
strategy:
5353
fail-fast: false
5454
matrix:
55-
python-version: ['3.9', '3.11']
55+
python-version: ['3.9', '3.12']
5656
os: [ubuntu-latest, macos-latest, windows-latest]
5757
# Is it a draft Pull Request (true or false)?
5858
isDraft:
5959
- ${{ github.event.pull_request.draft }}
60-
# Only run two jobs (Ubuntu + Python 3.9/3.11) for draft PRs
60+
# Only run two jobs (Ubuntu + Python 3.9/3.12) for draft PRs
6161
exclude:
6262
- os: macos-latest
6363
isDraft: true
6464
- os: windows-latest
6565
isDraft: true
66-
# Pair Python 3.9 with NumPy 1.22 and Python 3.11 with NumPy 1.26
67-
# Only install optional packages on Python 3.11/NumPy 1.26
66+
# Pair Python 3.9 with NumPy 1.22 and Python 3.12 with NumPy 1.26
67+
# Only install optional packages on Python 3.12/NumPy 1.26
6868
include:
6969
- python-version: '3.9'
7070
numpy-version: '1.22'
7171
optional-packages: ''
72-
- python-version: '3.11'
72+
- python-version: '3.12'
7373
numpy-version: '1.26'
7474
optional-packages: ' contextily geopandas ipython rioxarray sphinx-gallery'
7575

.github/workflows/ci_tests_dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ jobs:
9898
cache-downloads: true
9999
cache-environment: true
100100
create-args: >-
101-
python=3.11
101+
python=3.12
102102
cmake
103103
make
104104
ninja

.github/workflows/format-command.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
# Setup Python environment
2828
- uses: actions/[email protected]
2929
with:
30-
python-version: '3.11'
30+
python-version: '3.12'
3131

3232
# Install formatting tools
3333
- name: Install formatting tools

.github/workflows/publish-to-pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- name: Set up Python
4747
uses: actions/[email protected]
4848
with:
49-
python-version: '3.11'
49+
python-version: '3.12'
5050

5151
- name: Install dependencies
5252
run: python -m pip install build

.github/workflows/style_checks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Set up Python
3131
uses: actions/[email protected]
3232
with:
33-
python-version: '3.11'
33+
python-version: '3.12'
3434

3535
- name: Install packages
3636
run: |

doc/install.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ want):
132132

133133
::
134134

135-
mamba create --name pygmt python=3.11 numpy pandas xarray netcdf4 packaging gmt
135+
mamba create --name pygmt python=3.12 numpy pandas xarray netcdf4 packaging gmt
136136

137137
.. tab-item:: conda
138138
:sync: conda
139139

140140
::
141141

142-
conda create --name pygmt python=3.11 numpy pandas xarray netcdf4 packaging gmt
142+
conda create --name pygmt python=3.12 numpy pandas xarray netcdf4 packaging gmt
143143

144144
Activate the environment by running the following (**do not forget this step!**):
145145

pygmt/tests/test_clib_loading.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ def test_load_libgmt_fails(monkeypatch):
7373
be found.
7474
"""
7575
with monkeypatch.context() as mpatch:
76-
mpatch.setattr(sys, "platform", "win32") # pretend to be on Windows
76+
mpatch.setattr(
77+
sys,
78+
"platform",
79+
# Pretend to be on macOS if running on Linux, and vice versa
80+
"darwin" if sys.platform == "linux" else "linux",
81+
)
7782
mpatch.setattr(
7883
subprocess, "check_output", lambda cmd, encoding: "libfakegmt.so"
7984
)

pygmt/tests/test_clib_put_vector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
22
Test the functions that put vector data into GMT.
33
"""
4+
import datetime
45
import itertools
5-
from datetime import datetime
66

77
import numpy as np
88
import numpy.testing as npt
@@ -122,7 +122,7 @@ def test_put_vector_string_dtype():
122122
"2021-02-03T00:00:00",
123123
"2021-02-03T04:00:00",
124124
"2021-02-03T04:05:06",
125-
f"{datetime.utcnow().strftime('%Y-%m-%d')}T04:50:06",
125+
f"{datetime.datetime.now(tz=datetime.timezone.utc).strftime('%Y-%m-%d')}T04:50:06",
126126
],
127127
]
128128

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ classifiers = [
2828
"Programming Language :: Python :: 3.9",
2929
"Programming Language :: Python :: 3.10",
3030
"Programming Language :: Python :: 3.11",
31+
"Programming Language :: Python :: 3.12",
3132
"License :: OSI Approved :: BSD License",
3233
]
3334
dependencies = [

0 commit comments

Comments
 (0)