Skip to content

Commit

Permalink
Add support for Python 3.12 (#2711)
Browse files Browse the repository at this point in the history
* 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'.
  • Loading branch information
weiji14 committed Nov 7, 2023
1 parent 19639fe commit a320c3f
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cache_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- conda-forge
- nodefaults
create-args: >-
python=3.11
python=3.12
gmt=6.4.0
numpy
pandas
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_doctests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- conda-forge
- nodefaults
create-args: >-
python=3.11
python=3.12
gmt=6.4.0
numpy
pandas
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
cache-downloads: true
cache-environment: true
create-args: >-
python=3.11
python=3.12
cmake
make
ninja
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
# Setup Python environment
- uses: actions/[email protected]
with:
python-version: '3.11'
python-version: '3.12'

# Install formatting tools
- name: Install formatting tools
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.11'
python-version: '3.12'

- name: Install dependencies
run: python -m pip install build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/style_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.11'
python-version: '3.12'

- name: Install packages
run: |
Expand Down
4 changes: 2 additions & 2 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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!**):

Expand Down
7 changes: 6 additions & 1 deletion pygmt/tests/test_clib_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions pygmt/tests/test_clib_put_vector.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
],
]

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit a320c3f

Please sign in to comment.