Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Python 3.12 #2711

Merged
merged 12 commits into from
Nov 7, 2023
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
numpy
pandas
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 @@ -100,7 +100,7 @@ jobs:
cache-downloads: true
cache-environment: true
create-args: >-
python=3.11
python=3.12
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GMT Dev Tests failing because pygit2 doesn't have Python 3.12 wheels, and building from source fails at https://github.com/GenericMappingTools/pygmt/actions/runs/6648200102/job/18064869372#step:7:570:

  Building wheel for pygit2 (pyproject.toml): started
  Building wheel for pygit2 (pyproject.toml): finished with status 'error'
  error: subprocess-exited-with-error
  
  × Building wheel for pygit2 (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [66 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-312
      creating build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/index.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/ffi.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/submodule.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/credentials.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/_run.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/utils.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/config.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/errors.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/_build.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/refspec.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/repository.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/blame.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/packbuilder.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/remote.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/callbacks.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/settings.py -> build/lib.linux-x86_64-cpython-312/pygit2
      copying pygit2/__init__.py -> build/lib.linux-x86_64-cpython-312/pygit2
      creating build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/transport.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/errors.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/blame.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/checkout.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/net.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/strarray.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/merge.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/diff.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/graph.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/describe.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/refspec.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/buffer.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/proxy.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/commit.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/revert.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/config.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/common.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/oid.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/attr.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/repository.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/remote.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/types.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/pack.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/callbacks.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/clone.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/indexer.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/stash.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/index.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/decl/submodule.h -> build/lib.linux-x86_64-cpython-312/pygit2/decl
      copying pygit2/_pygit2.pyi -> build/lib.linux-x86_64-cpython-312/pygit2
      running build_ext
      generating cffi module 'build/temp.linux-x86_64-cpython-312/pygit2._libgit2.c'
      creating build/temp.linux-x86_64-cpython-312
      building 'pygit2._pygit2' extension
      creating build/temp.linux-x86_64-cpython-312/src
      gcc -pthread -B /home/runner/micromamba/envs/pygmt/compiler_compat -fno-strict-overflow -DNDEBUG -O2 -Wall -fPIC -O2 -isystem /home/runner/micromamba/envs/pygmt/include -fPIC -O2 -isystem /home/runner/micromamba/envs/pygmt/include -fPIC -I/usr/local/include -I/home/runner/micromamba/envs/pygmt/include/python3.12 -c src/blob.c -o build/temp.linux-x86_64-cpython-312/src/blob.o
      In file included from src/blob.c:30:
      src/diff.h:33:10: fatal error: git2.h: No such file or directory
         33 | #include <git2.h>
            |          ^~~~~~~~
      compilation terminated.
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pygit2
  Building wheel for frozenlist (pyproject.toml): started
  Building wheel for frozenlist (pyproject.toml): finished with status 'done'
  Created wheel for frozenlist: filename=frozenlist-1.4.0-cp312-cp312-linux_x86_64.whl size=53997 sha256=39bb8d4c56a724d4cd9ed87de83b7de69e78a79763d0d9f5ae5e95f8497b5b83
  Stored in directory: /home/runner/.cache/pip/wheels/f1/9c/94/9386cb0ea511a93226456388d41d35f1c24ba15a62ffd7b1ef
  Building wheel for multidict (pyproject.toml): started
  Building wheel for multidict (pyproject.toml): finished with status 'done'
  Created wheel for multidict: filename=multidict-6.0.4-cp312-cp312-linux_x86_64.whl size=34743 sha256=b99632e55f0994365432703c422b45c7b80332be4690bfa943602cb30e69d013
  Stored in directory: /home/runner/.cache/pip/wheels/f6/d8/ff/3c14a64b8f2ab1aa94ba2888f5a988be6ab446ec5c8d1a82da
  Building wheel for yarl (pyproject.toml): started
  Building wheel for yarl (pyproject.toml): finished with status 'done'
  Created wheel for yarl: filename=yarl-1.9.2-cp312-cp312-linux_x86_64.whl size=70034 sha256=d286d55089432e38d0441fa83a86e4a994b9537a62cec71e97187e4d2d41a9ec
  Stored in directory: /home/runner/.cache/pip/wheels/84/e3/6a/7d0fa1abee8e4aa39922b5bd54689b4b5e4269b2821f482a32
Successfully built antlr4-python3-runtime dulwich frozenlist multidict yarl
Failed to build pygit2
ERROR: Could not build wheels for pygit2, which is required to install pyproject.toml-based projects

Might need to wait for libgit2/pygit2#1240.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than waiting for pygit2 to release Python 3.12 wheels, we could also keep the GMT Dev Tests on Python 3.11 for now?

Suggested change
python=3.12
python=3.11

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like pygit2 has Python 3.12 wheels now - https://pypi.org/project/pygit2/1.13.2/#files

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/setup-python@v4.7.1
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/setup-python@v4.7.1
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/setup-python@v4.7.1
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
2 changes: 1 addition & 1 deletion pygmt/tests/test_clib_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this workaround I applied in a048c86 doesn't actually work on macOS...

Copy link
Member Author

@weiji14 weiji14 Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your workaround a048c86 fails on macOS CI, because on macOS, PyGMT will find the gmt.dylib successfully in the system default path (I think conda's lib path is in the default search path)

Two possible workarounds:

1. Monkeypatch `sys.platform` so it always returns the wrong platform, e.g., return `linux` on macOS/Windows and `darwin` on Linux

2. Instead of monkeypatching `sys.platform`, we can monkeypath `clib_names` to return invalid library names.

Ok, trying out Option 1 in 99fdbf8. Edit: Yep, it worked!

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.UTC).strftime('%Y-%m-%d')}T04:50:06",
weiji14 marked this conversation as resolved.
Show resolved Hide resolved
],
]

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
Loading