Skip to content

Commit

Permalink
[python/ci] typeguard==4.2.1, make requirements_dev.txt canonical (
Browse files Browse the repository at this point in the history
…#2314)

* use requirements_dev.txt in CI, setup.py

* use typeguard>=4.2, fixup some type checks

agronholm/typeguard#442 was fixed in typeguard 4.2.0

* cr feedback: `_UNSET`/`_Unset` sentinel value/type
  • Loading branch information
ryan-williams authored Mar 26, 2024
1 parent d42c07a commit 36d5b6e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 32 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/python-ci-single.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,8 @@ jobs:
# dist
# key: libtiledbsoma-build-dist-${{ inputs.os }}-${{ inputs.python_version }}-${{ hashFiles('libtiledbsoma', 'scripts/bld') }}

- name: Install testing prereqs
run: python -m pip -v install -U pip pytest-cov 'typeguard==4.1.5' types-setuptools sparse

- name: Install tiledbsoma
run: python -m pip -v install -e apis/python
run: python -m pip -v install -e apis/python[dev]
env:
CC: ${{ inputs.cc }}
CXX: ${{ inputs.cxx }}
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/r-python-interop-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ jobs:
cache: pip
cache-dependency-path: ./apis/python/setup.py

- name: Install testing prereqs
run: python -m pip -v install -U pip pytest-cov 'typeguard==4.1.5' types-setuptools

- name: Install tiledbsoma
run: python -m pip -v install -e apis/python
run: python -m pip -v install -e apis/python[dev]

- name: Show Python package versions
run: |
Expand Down
8 changes: 5 additions & 3 deletions apis/python/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake >= 3.21
pybind11-global >= 2.10.0
typeguard==4.1.5
black
ruff
pytest
pytest-cov
sparse
typeguard==4.2.1
types-setuptools
7 changes: 1 addition & 6 deletions apis/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,7 @@ def run(self):
"typing-extensions", # Note "-" even though `import typing_extensions`
],
extras_require={
"dev": [
"black",
"ruff",
"pytest",
"typeguard==4.1.5",
]
"dev": open("requirements_dev.txt").read(),
},
python_requires=">=3.8",
cmdclass={"build_ext": build_ext, "bdist_wheel": bdist_wheel},
Expand Down
5 changes: 2 additions & 3 deletions apis/python/src/tiledbsoma/_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def add_new_collection(
def add_new_collection(
self,
key: str,
kind: Optional[Type[AnyTileDBCollection]] = None,
kind: Optional[Type[CollectionBase]] = None, # type: ignore[type-arg]
*,
uri: Optional[str] = None,
platform_config: Optional[options.PlatformConfig] = None,
Expand Down Expand Up @@ -377,7 +377,6 @@ def add_new_sparse_ndarray(self, key: str, **kwargs: Any) -> SparseNDArray:
"""
return self._add_new_ndarray(SparseNDArray, key, **kwargs)

@typeguard_ignore
def _add_new_element(
self,
key: str,
Expand Down Expand Up @@ -444,7 +443,7 @@ def __getitem__(self, key: str) -> CollectionElementType:
entry.entry.wrapper_type.open, uri, mode, context, timestamp
)
# Since we just opened this object, we own it and should close it.
self._close_stack.enter_context(entry.soma) # type: ignore[arg-type]
self._close_stack.enter_context(entry.soma)
return cast(CollectionElementType, entry.soma)

def set(
Expand Down
3 changes: 1 addition & 2 deletions apis/python/src/tiledbsoma/_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def open(
Experimental.
"""
context = _validate_soma_tiledb_context(context)
obj: TileDBObject[_Wrapper] = _open_internal( # type: ignore[no-untyped-call,valid-type]
obj: TileDBObject[_Wrapper] = _open_internal( # type: ignore[valid-type]
_tdb_handles.open, uri, mode, context, tiledb_timestamp
)
try:
Expand All @@ -143,7 +143,6 @@ def open(
raise


@no_type_check
def _open_internal(
opener: Callable[
[str, options.OpenMode, SOMATileDBContext, Optional[OpenTimestamp]], _Wrapper
Expand Down
22 changes: 12 additions & 10 deletions apis/python/src/tiledbsoma/options/_soma_tiledb_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import functools
import threading
import time
from concurrent import futures
from typing import Any, Dict, Mapping, Optional, Union
from concurrent.futures import ThreadPoolExecutor
from typing import Any, Dict, Literal, Mapping, Optional, Union

import tiledb
from somacore import ContextBase
Expand Down Expand Up @@ -46,8 +46,8 @@ def _maybe_timestamp_ms(input: Optional[OpenTimestamp]) -> Optional[int]:
return to_timestamp_ms(input)


_SENTINEL = object()
"""Sentinel object to distinguish default parameters from None."""
_Unset = Literal["__unset__"]
_UNSET: _Unset = "__unset__"


class SOMATileDBContext(ContextBase):
Expand All @@ -68,7 +68,7 @@ def __init__(
tiledb_ctx: Optional[tiledb.Ctx] = None,
tiledb_config: Optional[Dict[str, Union[str, float]]] = None,
timestamp: Optional[OpenTimestamp] = None,
threadpool: Optional[futures.ThreadPoolExecutor] = None,
threadpool: Optional[ThreadPoolExecutor] = None,
) -> None:
"""Initializes a new SOMATileDBContext.
Expand Down Expand Up @@ -138,7 +138,7 @@ def __init__(
"""The TileDB context to use, either provided or lazily constructed."""
self._timestamp_ms = _maybe_timestamp_ms(timestamp)

self.threadpool = threadpool or futures.ThreadPoolExecutor()
self.threadpool = threadpool or ThreadPoolExecutor()
"""User specified threadpool. If None, we'll instantiate one ourselves."""
self._native_context: Optional[clib.SOMAContext] = None
"""Lazily construct clib.SOMAContext."""
Expand Down Expand Up @@ -219,8 +219,8 @@ def replace(
*,
tiledb_config: Optional[Dict[str, Any]] = None,
tiledb_ctx: Optional[tiledb.Ctx] = None,
timestamp: Optional[OpenTimestamp] = _SENTINEL, # type: ignore[assignment]
threadpool: Optional[futures.ThreadPoolExecutor] = _SENTINEL, # type: ignore[assignment]
timestamp: Union[None, OpenTimestamp, _Unset] = _UNSET,
threadpool: Union[None, ThreadPoolExecutor, _Unset] = _UNSET,
) -> Self:
"""Create a copy of the context, merging changes.
Expand Down Expand Up @@ -259,12 +259,14 @@ def replace(
new_config = self._internal_tiledb_config()
new_config.update(tiledb_config)
tiledb_config = {k: v for (k, v) in new_config.items() if v is not None}
if timestamp is _SENTINEL:

if timestamp == _UNSET:
# Keep the existing timestamp if not overridden.
timestamp = self._timestamp_ms
if threadpool is _SENTINEL:
if threadpool == _UNSET:
# Keep the existing threadpool if not overridden.
threadpool = self.threadpool

return type(self)(
tiledb_config=tiledb_config,
tiledb_ctx=tiledb_ctx,
Expand Down

0 comments on commit 36d5b6e

Please sign in to comment.