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

[python] Python 3.12 support #3001

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

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

This would be the place for a TODO / issue link related to upgrading Typeguard. Do you want me to change this comment?

Copy link
Member

Choose a reason for hiding this comment

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

Filed #3216 and referenced it here

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
Copy link
Member Author

Choose a reason for hiding this comment

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

Let's hvae a GitHub issue tracking the 'real' typeguard release, and let's put its URL here as a to-do comment

Copy link
Member

Choose a reason for hiding this comment

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

This change isn't due to using Typeguard@HEAD; it will remain relevant when we move back to a proper Typeguard release.

The reason for it is: in 3.12, better type-checking was causing a TypeCheckError to occur before the TypeError we were verifying here.

I worked around it by disabling type-checking while triggering this error, so we can continue to verify what we were previously.

# 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
Copy link
Member Author

Choose a reason for hiding this comment

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

Ditto the above to-do URL/comment

Copy link
Member

Choose a reason for hiding this comment

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

Same as above, todo related to upgrading Typeguard is not applicable here.

# `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
Loading