Skip to content

Commit 7cd1dc1

Browse files
authored
Fix broken cicd that has new mypy deps. (#256)
Context: [mm](https://chat.kaggle.net/kaggle/pl/fcxzntt8efdijjp8kc8uyuoz6a) **Root cause** There seem to be 2 failures for cicd: 1. Updated `ruff` and other checking tools for non-top level imports (fixed with inline comments.) 2. Our lint script `mypy --install-types --non-interactive src/kagglehub tests` will need to install a new dep `scipy-stubs`, which is NOT available for Python 3.9. This dependence is likely to be introduced in [this PR](#196) - Long term solution: retire Python 3.9 since it EOL is 2025/Oct. - Short term: added exceptions based on [this doc](https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports) I propose we go for the short term solution to unblock, and keep track the long term solution in other tasks.
1 parent 53e426b commit 7cd1dc1

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,16 +523,16 @@ The following shows how to run `hatch run lint:all` but this also works for any
523523
./docker-hatch run lint:all
524524
525525
# Use specific Python version (Must be a valid tag from: https://hub.docker.com/_/python)
526-
./docker-hatch -v 3.9 run lint:all
526+
./docker-hatch -v 3.10 run lint:all
527527
528528
# Run test in docker with specific Python version
529-
./docker-hatch -v 3.9 test
529+
./docker-hatch -v 3.10 test
530530
531531
# Run python from specific environment (e.g. one with optional dependencies installed)
532532
./docker-hatch run extra-deps-env:python -c "print('hello world')"
533533
534534
# Run commands with other root-level hatch options (everything after -- gets passed to hatch)
535-
./docker-hatch -v 3.9 -- -v env create debug-env-with-verbose-logging
535+
./docker-hatch -v 3.10 -- -v env create debug-env-with-verbose-logging
536536
```
537537

538538
## VS Code setup

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ dependencies = [
8484
"types-requests",
8585
"types-tqdm",
8686
"pandas_stubs",
87-
"polars"
87+
"polars",
8888
]
8989

9090
[tool.hatch.envs.lint.scripts]
@@ -237,3 +237,7 @@ exclude_lines = [
237237

238238
[tool.mypy]
239239
mypy_path = "./stubs"
240+
241+
[[tool.mypy.overrides]]
242+
module = ["yaml.*"]
243+
ignore_missing_imports = true

src/kagglehub/auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _is_in_notebook() -> bool:
5151
Adapted to make it work with Google colab as well.
5252
"""
5353
try:
54-
from IPython import get_ipython # type: ignore
54+
from IPython import get_ipython # type: ignore # noqa: PLC0415
5555

5656
shell_class = get_ipython().__class__
5757
for parent_class in shell_class.__mro__: # e.g. "is subclass of"
@@ -66,8 +66,8 @@ def _notebook_login(validate_credentials: bool) -> None: # noqa: FBT001
6666
"""Prompt the user for their Kaggle token and save it in a widget (Jupyter or Colab)."""
6767
library_error = "You need the `ipywidgets` module: `pip install ipywidgets`."
6868
try:
69-
from IPython.display import display # type: ignore
70-
from ipywidgets import widgets # type: ignore
69+
from IPython.display import display # type: ignore # noqa: PLC0415
70+
from ipywidgets import widgets # type: ignore # noqa: PLC0415
7171
except ImportError:
7272
raise ImportError(library_error) # noqa: B904
7373

src/kagglehub/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _normalize_whitespace(s: str) -> str:
162162
def get_colab_credentials() -> Optional[KaggleApiCredentials]:
163163
# userdata access is already thread-safe after b/318732641
164164
try:
165-
from google.colab import userdata # type: ignore[import]
165+
from google.colab import userdata # type: ignore[import] # noqa: PLC0415
166166
except ImportError:
167167
return None
168168

src/kagglehub/datasets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def dataset_load(
126126
polars_frame_type = polars_frame_type if polars_frame_type is not None else PolarsFrameType.LAZY_FRAME
127127
try:
128128
if adapter is KaggleDatasetAdapter.HUGGING_FACE:
129-
import kagglehub.hf_datasets
129+
import kagglehub.hf_datasets # noqa: PLC0415
130130

131131
return kagglehub.hf_datasets.load_hf_dataset(
132132
handle,
@@ -136,13 +136,13 @@ def dataset_load(
136136
hf_kwargs=hf_kwargs,
137137
)
138138
elif adapter is KaggleDatasetAdapter.PANDAS:
139-
import kagglehub.pandas_datasets
139+
import kagglehub.pandas_datasets # noqa: PLC0415
140140

141141
return kagglehub.pandas_datasets.load_pandas_dataset(
142142
handle, path, pandas_kwargs=pandas_kwargs, sql_query=sql_query
143143
)
144144
elif adapter is KaggleDatasetAdapter.POLARS:
145-
import kagglehub.polars_datasets
145+
import kagglehub.polars_datasets # noqa: PLC0415
146146

147147
return kagglehub.polars_datasets.load_polars_dataset(
148148
handle, path, polars_frame_type=polars_frame_type, polars_kwargs=polars_kwargs, sql_query=sql_query

src/kagglehub/signing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def sign_with_sigstore(local_model_dir: str, handle: ModelHandle) -> bool:
11-
from model_signing.signing import Config
11+
from model_signing.signing import Config # noqa: PLC0415
1212

1313
try:
1414
token = signing_token(handle.owner, handle.model)

tools/cicd/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ ARG PYTHON_VERSION
66

77
FROM python:${PYTHON_VERSION}
88

9+
RUN python -m pip install --upgrade pip
10+
911
RUN python -m pip install hatch==1.14.0 twine==6.0.1
1012

1113
ENTRYPOINT ["hatch"]

0 commit comments

Comments
 (0)