Skip to content

Commit

Permalink
Merge pull request #188 from seismic-anisotropy/allow-python-3.10
Browse files Browse the repository at this point in the history
dev: Add support for Python 3.10 and test against 3.10-3.12
  • Loading branch information
Patol75 authored Apr 20, 2024
2 parents c38091f + 14efb05 commit 08a116e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
install-linux:
name: (Linux) Install package and run tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']

steps:
- name: Checkout repository
Expand All @@ -20,7 +23,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: ${{ matrix.python-version }}

- name: Install and test
run: |
Expand All @@ -34,6 +37,9 @@ jobs:
install-macos:
name: (MacOS) Install package and run tests
runs-on: macos-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']

steps:
- name: Checkout repository
Expand All @@ -42,7 +48,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: ${{ matrix.python-version }}

- name: Install and test
run: |
Expand All @@ -53,6 +59,9 @@ jobs:
install-windows:
name: (Windows) Install package and run tests
runs-on: windows-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']

steps:
- name: Checkout repository
Expand All @@ -61,7 +70,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: ${{ matrix.python-version }}

- name: Install and test
run: |
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ name = "pydrex"
dynamic = ["version"] # Managed by setuptools_scm.
description = "Dynamic CPO calculations for olivine-enstatite polycrystal aggregates"
readme = "README.md"
requires-python = ">=3.11" # We use tomllib: <https://docs.python.org/3/library/tomllib.html>.
requires-python = ">=3.10" # We use tomllib on 3.11: <https://docs.python.org/3/library/tomllib.html>.
license = {file = "LICENSE"}
authors = [
{name = "Thomas Duvernay", email = "td75013@hotmail.fr"},
Expand All @@ -33,6 +33,7 @@ classifiers = [
]

dependencies = [
"tomli >= 1.1.0 ; python_version < '3.11'", # https://github.com/hukkin/tomli?tab=readme-ov-file#building-a-tomlitomllib-compatibility-layer
"numpy >= 1.8", # <https://numpy.org/doc/stable/reference/generated/numpy.linalg.eigvalsh.html>
"numba >= 0.57", # <https://numba.readthedocs.io/en/stable/release-notes.html#version-0-57-0-1-may-2023>
"scipy >= 1.2", # <https://github.com/scipy/scipy/pull/9176>
Expand Down
8 changes: 7 additions & 1 deletion src/pydrex/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
import io
import os
import pathlib
import tomllib
import sys

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

from importlib.resources import files

import h5py
Expand Down
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""> Configuration and fixtures for PyDRex tests."""

import sys

import matplotlib
import pytest
from _pytest.logging import LoggingPlugin, _LiveLoggingStreamHandler
Expand Down Expand Up @@ -142,6 +144,14 @@ def ncpus(request):
return max(1, request.config.getoption("--ncpus"))


@pytest.fixture(scope="session")
def named_tempfile_kwargs(request):
if sys.platform == "win32":
return {"delete": False}
else:
return dict()


@pytest.fixture(scope="function")
def console_handler(request):
if request.config.option.verbose > 0: # Show console logs if -v/--verbose given.
Expand Down
10 changes: 5 additions & 5 deletions tests/test_scsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_read_specfile():


@pytest.mark.skipif(sys.platform == "win32", reason="Items are not equal")
def test_save_specfile(outdir):
def test_save_specfile(outdir, named_tempfile_kwargs):
"""Test SCSV spec file reproduction."""
schema = {
"delimiter": ",",
Expand Down Expand Up @@ -159,8 +159,8 @@ def test_save_specfile(outdir):
_io.save_scsv(f"{outdir}/spec_out_alt.scsv", schema_alt, data_alt)

# https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
temp = tempfile.NamedTemporaryFile(delete_on_close=False)
temp_alt = tempfile.NamedTemporaryFile(delete_on_close=False)
temp = tempfile.NamedTemporaryFile(**named_tempfile_kwargs)
temp_alt = tempfile.NamedTemporaryFile(**named_tempfile_kwargs)
_io.save_scsv(temp.name, schema, data)
_io.save_scsv(temp_alt.name, schema_alt, data_alt)
raw_read = []
Expand Down Expand Up @@ -194,7 +194,7 @@ def test_read_Kaminski2002():
# fmt: on


def test_save_scsv_errors():
def test_save_scsv_errors(named_tempfile_kwargs):
"""Check that we raise errors when attempting to write bad SCSV data."""
schema = {
"delimiter": ",",
Expand All @@ -208,7 +208,7 @@ def test_save_scsv_errors():
],
}
# https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
temp = tempfile.NamedTemporaryFile(delete_on_close=False)
temp = tempfile.NamedTemporaryFile(**named_tempfile_kwargs)
with pytest.raises(_err.SCSVError):
foo = [1, 5, 0.2]
_io.save_scsv(temp.name, schema, [foo])
Expand Down

0 comments on commit 08a116e

Please sign in to comment.