Skip to content

Commit

Permalink
[python] Python 3.12 support (#3001)
Browse files Browse the repository at this point in the history
* [python] Python 3.12 support

* `python-ci-packaging`: consistent dep order

* use Typeguard@HEAD

for agronholm/typeguard#490, for Python 3.12 tests

* rm `soma@kerl/python-3.12` CI pin

---------

Co-authored-by: Ryan Williams <[email protected]>
  • Loading branch information
johnkerl and ryan-williams authored Oct 22, 2024
1 parent f448271 commit 467cd7b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-ci-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# os: [ubuntu-latest, macos-latest, windows-2019]
# TODO: add 3.12
# https://github.com/single-cell-data/TileDB-SOMA/issues/1849
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']
include:
- runs-on: ubuntu-latest
cc: gcc-11
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python-ci-minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

matrix:
os: [ubuntu-latest, macos-latest]
python-version: ['3.9', '3.11']
python-version: ['3.9', '3.12']
include:
- os: ubuntu-latest
cc: gcc-11
Expand All @@ -43,6 +43,6 @@ jobs:
python_version: ${{ matrix.python-version }}
cc: ${{ matrix.cc }}
cxx: ${{ matrix.cxx }}
report_codecov: ${{ matrix.python-version == '3.11' }}
run_lint: ${{ matrix.python-version == '3.11' }}
report_codecov: ${{ matrix.python-version == '3.12' }}
run_lint: ${{ matrix.python-version == '3.12' }}
secrets: inherit
6 changes: 4 additions & 2 deletions .github/workflows/python-ci-packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
run: |
python --version
python -m venv ./venv-soma
./venv-soma/bin/pip install --prefer-binary pybind11-global typeguard sparse 'setuptools>=70.1' wheel
./venv-soma/bin/pip install --prefer-binary pybind11-global typeguard sparse wheel 'setuptools>=70.1'
./venv-soma/bin/pip list
- name: Build wheel
run: |
Expand Down Expand Up @@ -333,7 +333,9 @@ jobs:
otool -L ./venv-soma/lib/python*/site-packages/tiledbsoma/pytiledbsoma.*.so
otool -l ./venv-soma/lib/python*/site-packages/tiledbsoma/pytiledbsoma.*.so
- name: Install runtime dependencies
run: ./venv-soma/bin/pip install --prefer-binary `grep -v '^\[' apis/python/src/tiledbsoma.egg-info/requires.txt`
run: |
grep -v '^\[' apis/python/src/tiledbsoma.egg-info/requires.txt > runtime-reqs.txt
./venv-soma/bin/pip install --prefer-binary -r runtime-reqs.txt
- name: Runtime test
run: ./venv-soma/bin/python -c "import tiledbsoma; print(tiledbsoma.pytiledbsoma.version())"

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/python-packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ jobs:
dotted-version: '3.10'
- undotted-version: '311'
dotted-version: '3.11'
- undotted-version: '312'
dotted-version: '3.12'
wheel-name:
- manylinux2014
- macos-x86_64
Expand Down
5 changes: 4 additions & 1 deletion apis/python/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ ruff
pytest
pytest-cov
sparse
typeguard==4.2.1
# Python 3.12 support requires https://github.com/agronholm/typeguard/pull/490;
# use Typeguard @ HEAD until that PR is included in a release. See also:
# https://github.com/single-cell-data/TileDB-SOMA/issues/3216
typeguard @ git+https://github.com/agronholm/typeguard
types-setuptools
27 changes: 22 additions & 5 deletions apis/python/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,9 @@ def make_multiply_indexed_dataframe(
"domain": [[-1000, 1000]],
"coords": [{"bogus": True}],
"A": None,
"throws": TypeError,
# Disable Typeguard while asserting this error, otherwise a typeguard.TypeCheckError is
# raised (though that's not what would happen in production)
"throws": (TypeError, False),
},
{
"name": "bad index type bool",
Expand Down Expand Up @@ -890,15 +892,30 @@ def test_read_indexing(tmp_path, io):
read_kwargs.update(
{k: io[k] for k in ("coords", "partitions", "value_filter") if k in io}
)
if io.get("throws", None):
with pytest.raises(io["throws"]):

# `throws` can be `Type[Exception]`, or `(Type[Exception], bool)` indicating explicitly
# whether Typeguard should be enabled during the `with raises` check.
throws = io.get("throws", None)
if throws:
if isinstance(throws, tuple) and not throws[1]:
# Disable Typeguard, verify actual runtime error type (avoid
# `typeguard.TypeCheckError` short-circuit)
throws = throws[0]
throws_ctx = raises_no_typeguard
else:
throws_ctx = pytest.raises
else:
throws_ctx = None

if throws_ctx:
with throws_ctx(throws):
next(sdf.read(**read_kwargs))
else:
table = next(sdf.read(**read_kwargs))
assert table["A"].to_pylist() == io["A"]

if io.get("throws", None):
with pytest.raises(io["throws"]):
if throws_ctx:
with throws_ctx(throws):
next(sdf.read(**read_kwargs)).to_pandas()
else:
table = next(sdf.read(**read_kwargs)).to_pandas()
Expand Down
2 changes: 1 addition & 1 deletion apis/python/tests/test_sparse_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ def test_sparse_nd_array_error_corners(tmp_path):

with soma.SparseNDArray.open(tmp_path.as_posix()) as a:
# other coord types are illegal
with pytest.raises(TypeError):
with raises_no_typeguard(TypeError):
next(a.read("hi").tables())


Expand Down

0 comments on commit 467cd7b

Please sign in to comment.