Skip to content

Commit a9acd43

Browse files
committed
tests: use filelock instead of config
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
1 parent 66af618 commit a9acd43

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

.distro/python-scikit-build-core.spec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ BuildRequires: ninja-build
2222
BuildRequires: gcc
2323
BuildRequires: gcc-c++
2424
BuildRequires: git
25-
BuildRequires: python3-hatch-vcs
2625

2726
%global _description %{expand:
2827
A next generation Python CMake adapter and Python API for plugins

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ jobs:
187187

188188
- name: Install min requirements
189189
run: |
190-
uv pip install -e. --group=test --resolution=lowest-direct --system
190+
uv pip install -e. --group=test-pybind11 --resolution=lowest-direct --system
191191
192192
- name: Setup CMake 3.15
193193
uses: jwlawson/actions-setup-cmake@v2.0
@@ -223,7 +223,7 @@ jobs:
223223
run: python3.13t -m venv /venv
224224

225225
- name: Install deps
226-
run: /venv/bin/pip install -e . --group=test ninja pybind11
226+
run: /venv/bin/pip install -e . --group=test-pybind11 ninja
227227

228228
- name: Test package
229229
run: /venv/bin/pytest
@@ -312,7 +312,7 @@ jobs:
312312
persist-credentials: false
313313

314314
- name: Install
315-
run: python -m pip install . --group=test
315+
run: python -m pip install . --group=test-pybind11
316316

317317
- name: Test package
318318
run: >-

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ hatch.scikit-build = "scikit_build_core.hatch.hooks"
7777
test = [
7878
"build >=0.8",
7979
"cattrs >=22.2.0",
80+
"filelock >=3.8.0",
8081
"hatchling >=1.24",
8182
"hatch-vcs >=0.4",
8283
"pip>=23; python_version<'3.13'",

tests/conftest.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import Any, Literal, overload
1515

1616
import virtualenv as _virtualenv
17+
from filelock import FileLock
1718

1819
if sys.version_info < (3, 11):
1920
import tomli as tomllib
@@ -37,28 +38,34 @@
3738
VIRTUALENV_VERSION = Version(metadata.version("virtualenv"))
3839

3940

40-
def pytest_configure(config) -> None:
41-
if hasattr(config, "workerinput"):
42-
return # Running in pytest-xdist worker
43-
44-
wheelhouse = config.cache.mkdir("wheelhouse")
45-
46-
subprocess.run(
47-
[
48-
sys.executable,
49-
"-m",
50-
"pip",
51-
"wheel",
52-
"--no-build-isolation",
53-
"--wheel-dir",
54-
str(wheelhouse),
55-
f"{BASE}",
56-
],
57-
check=True,
58-
)
41+
@pytest.fixture(scope="session")
42+
def pep518_wheelhouse(pytestconfig: pytest.Config) -> Path:
43+
wheelhouse = pytestconfig.cache.mkdir("wheelhouse")
44+
45+
main_lock = FileLock(wheelhouse / "main.lock")
46+
with main_lock:
47+
subprocess.run(
48+
[
49+
sys.executable,
50+
"-m",
51+
"pip",
52+
"wheel",
53+
"--wheel-dir",
54+
str(wheelhouse),
55+
"--no-build-isolation",
56+
f"{BASE}",
57+
],
58+
check=True,
59+
capture_output=True,
60+
text=True,
61+
)
5962

60-
if not all(list(wheelhouse.glob(f"{p}*.whl")) for p in download_wheels.WHEELS):
61-
download_wheels.prepare(wheelhouse)
63+
wheels_lock = FileLock(wheelhouse / "wheels.lock")
64+
with wheels_lock:
65+
if not all(list(wheelhouse.glob(f"{p}*.whl")) for p in download_wheels.WHEELS):
66+
download_wheels.prepare(wheelhouse)
67+
68+
return wheelhouse
6269

6370

6471
class VEnv:
@@ -152,10 +159,9 @@ def prepare_no_build_isolation(self) -> None:
152159

153160

154161
@pytest.fixture
155-
def isolated(tmp_path: Path, pytestconfig: pytest.Config) -> VEnv:
162+
def isolated(tmp_path: Path, pep518_wheelhouse: Path) -> VEnv:
156163
path = tmp_path / "venv"
157-
wheelhouse = pytestconfig.cache.mkdir("wheelhouse").resolve()
158-
return VEnv(path, wheelhouse=wheelhouse)
164+
return VEnv(path, wheelhouse=pep518_wheelhouse)
159165

160166

161167
@pytest.fixture
@@ -345,7 +351,7 @@ def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
345351
item.add_marker(pytest.mark.network)
346352

347353

348-
def pytest_report_header(config: pytest.Config) -> str:
354+
def pytest_report_header() -> str:
349355
with BASE.joinpath("pyproject.toml").open("rb") as f:
350356
pyproject = tomllib.load(f)
351357
project = pyproject.get("project", {})
@@ -357,9 +363,6 @@ def pytest_report_header(config: pytest.Config) -> str:
357363
interesting_packages = {Requirement(p).name for p in pkgs}
358364
interesting_packages.add("pip")
359365

360-
wheelhouse = config.cache.mkdir("wheelhouse")
361-
pkgs = wheelhouse.glob("*.whl")
362-
363366
valid = []
364367
for package in sorted(interesting_packages):
365368
with contextlib.suppress(ModuleNotFoundError):
@@ -368,6 +371,5 @@ def pytest_report_header(config: pytest.Config) -> str:
368371
lines = [
369372
f"installed packages of interest: {reqs}",
370373
f"sysconfig platform: {sysconfig.get_platform()}",
371-
f"wheelhouse: {' '.join('-'.join(p.name.split('-')[:2]) for p in pkgs)}",
372374
]
373375
return "\n".join(lines)

tests/utils/download_wheels.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"cython",
1919
"hatchling",
2020
"pip",
21-
"pybind11",
2221
"setuptools",
2322
"virtualenv",
2423
"wheel",

0 commit comments

Comments
 (0)