Skip to content

Commit ed9dc08

Browse files
authored
fix: Use posix path for Windows compatibility (#314)
* fix posix path * add windows runner * update lock file * downgrade transformers to < 5.4.0 * fix permission error in tests on windows * attempt to simulate windows failure * rerererevert change
1 parent 40deb6b commit ed9dc08

6 files changed

Lines changed: 1950 additions & 1339 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
name: Run tests with pytest
1212
runs-on: ${{ matrix.os }}
1313
strategy:
14+
fail-fast: false
1415
matrix:
15-
os: ["ubuntu-latest"]
16+
os: ["ubuntu-latest", "windows-latest"]
1617
python-version: ["3.10", "3.11", "3.12", "3.13"]
17-
fail-fast: false
1818

1919
steps:
2020
- uses: actions/checkout@v4
@@ -25,24 +25,34 @@ jobs:
2525
python-version: ${{ matrix.python-version }}
2626
allow-prereleases: true
2727

28-
- name: Create and activate a virtual environment (Unix)
28+
- name: Install uv
29+
uses: astral-sh/setup-uv@v6
30+
31+
- name: Create virtual environment
32+
run: uv venv .venv
33+
34+
- name: Add venv to PATH (Linux/macOS)
35+
if: runner.os != 'Windows'
2936
run: |
30-
curl -LsSf https://astral.sh/uv/install.sh | sh
31-
uv venv .venv
3237
echo "VIRTUAL_ENV=.venv" >> $GITHUB_ENV
3338
echo "$PWD/.venv/bin" >> $GITHUB_PATH
3439
35-
# Install dependencies using uv pip
40+
- name: Add venv to PATH (Windows)
41+
if: runner.os == 'Windows'
42+
shell: pwsh
43+
run: |
44+
"VIRTUAL_ENV=.venv" >> $env:GITHUB_ENV
45+
"$pwd\.venv\Scripts" >> $env:GITHUB_PATH
46+
3647
- name: Install dependencies
3748
run: make install-no-pre-commit
3849

39-
# Run tests with coverage
4050
- name: Run tests under coverage
51+
shell: bash
4152
run: |
4253
coverage run --source=model2vec -m pytest
4354
coverage report
4455
45-
# Upload results to Codecov
4656
- name: Upload results to Codecov
4757
uses: codecov/codecov-action@v4
4858
with:

model2vec/persistence/persistence.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ def _resolve_folder(folder_or_repo_path: Path, token: str | None, force_download
144144
if folder := maybe_get_cached_model_path(str(folder_or_repo_path)):
145145
return folder
146146

147-
folder = Path(huggingface_hub.snapshot_download(str(folder_or_repo_path), repo_type="model", token=token))
147+
folder = Path(
148+
huggingface_hub.snapshot_download(str(folder_or_repo_path.as_posix()), repo_type="model", token=token)
149+
)
148150

149151
return folder
150152

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@ dev = [
6060
"ruff",
6161
]
6262

63-
distill = ["torch", "transformers", "scikit-learn", "skeletoken>=0.3.2"]
63+
distill = ["torch", "transformers<5.4.0", "scikit-learn", "skeletoken>=0.3.2"]
6464
onnx = ["onnx", "torch"]
6565
# train also installs inference
6666
train = ["torch", "lightning", "scikit-learn", "skops"]
6767
inference = ["scikit-learn", "skops"]
68-
tokenizer = ["transformers"]
6968
quantization = ["scikit-learn"]
7069

7170
[project.urls]

tests/test_persistence.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ def test_local_loading(mock_static_model: StaticModel) -> None:
2323
with patch("model2vec.persistence.persistence.maybe_get_cached_model_path") as cache:
2424
# Simulate cache hit
2525
cache.return_value = Path(dir_name)
26-
s = StaticModel.from_pretrained("haha", force_download=True)
26+
s = StaticModel.from_pretrained("my_org/haha", force_download=True)
27+
assert mock_snapshot.call_args[0] == ("my_org/haha",)
2728
assert s.tokens == mock_static_model.tokens
28-
s = StaticModel.from_pretrained("haha", force_download=False)
29+
s = StaticModel.from_pretrained("my_org/haha", force_download=False)
2930
assert s.tokens == mock_static_model.tokens
3031

3132
# Simulate cache miss
3233
cache.return_value = None
33-
s = StaticModel.from_pretrained("haha", force_download=True)
34+
s = StaticModel.from_pretrained("my_org/haha", force_download=True)
3435
assert s.tokens == mock_static_model.tokens
35-
s = StaticModel.from_pretrained("haha", force_download=False)
36+
s = StaticModel.from_pretrained("my_org/haha", force_download=False)
3637
assert s.tokens == mock_static_model.tokens
3738

3839
# Called twice, only when `force_download` is False

tests/test_utils.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4-
from tempfile import NamedTemporaryFile
54
from unittest.mock import patch
65

76
import pytest
@@ -16,20 +15,19 @@ def test__get_metadata_from_readme_not_exists() -> None:
1615
assert get_metadata_from_readme(Path("zzz")) == {}
1716

1817

19-
def test__get_metadata_from_readme_mocked_file() -> None:
18+
def test__get_metadata_from_readme_mocked_file(tmp_path: Path) -> None:
2019
"""Test getting metadata from a README."""
21-
with NamedTemporaryFile() as f:
22-
f.write(b"---\nkey: value\n---\n")
23-
f.flush()
24-
assert get_metadata_from_readme(Path(f.name))["key"] == "value"
20+
path = tmp_path / "README.md"
21+
path.write_text("---\nkey: value\n---\n", encoding="utf-8")
2522

23+
assert get_metadata_from_readme(path)["key"] == "value"
2624

27-
def test__get_metadata_from_readme_mocked_file_keys() -> None:
25+
26+
def test__get_metadata_from_readme_mocked_file_keys(tmp_path: Path) -> None:
2827
"""Test getting metadata from a README."""
29-
with NamedTemporaryFile() as f:
30-
f.write(b"")
31-
f.flush()
32-
assert set(get_metadata_from_readme(Path(f.name))) == set()
28+
path = tmp_path / "README.md"
29+
path.write_text("b", encoding="utf-8")
30+
assert set(get_metadata_from_readme(path)) == set()
3331

3432

3533
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)