Skip to content

Commit

Permalink
Rely on 'session' context when building wheel and sdist. Fixes #3059.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jan 29, 2022
1 parent 19c1dc0 commit 48f463f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 34 deletions.
1 change: 0 additions & 1 deletion setup.cfg
Expand Up @@ -64,7 +64,6 @@ testing =
sphinx>=4.3.2
jaraco.path>=3.2.0
build[virtualenv]
filelock>=3.4.0
pip_run>=8.8

testing-integration =
Expand Down
13 changes: 0 additions & 13 deletions setuptools/tests/contexts.py
Expand Up @@ -7,7 +7,6 @@
import io

import pkg_resources
from filelock import FileLock


@contextlib.contextmanager
Expand Down Expand Up @@ -97,15 +96,3 @@ def suppress_exceptions(*excs):
yield
except excs:
pass


@contextlib.contextmanager
def session_locked_tmp_dir(tmp_path_factory, name):
"""Uses a file lock to guarantee only one worker can access a temp dir"""
root_tmp_dir = tmp_path_factory.getbasetemp().parent
# ^-- get the temp directory shared by all workers
locked_dir = root_tmp_dir / name
with FileLock(locked_dir.with_suffix(".lock")):
# ^-- prevent multiple workers to access the directory at once
locked_dir.mkdir(exist_ok=True, parents=True)
yield locked_dir
32 changes: 12 additions & 20 deletions setuptools/tests/fixtures.py
Expand Up @@ -64,30 +64,22 @@ def sample_project(tmp_path):

@pytest.fixture(scope="session")
def setuptools_sdist(tmp_path_factory, request):
with contexts.session_locked_tmp_dir(tmp_path_factory, "sdist_build") as tmp:
dist = next(tmp.glob("*.tar.gz"), None)
if dist:
return dist

subprocess.check_call([
sys.executable, "-m", "build", "--sdist",
"--outdir", str(tmp), str(request.config.rootdir)
])
return next(tmp.glob("*.tar.gz"))
target = tmp_path_factory.mktemp('sdist_build')
subprocess.check_call([
sys.executable, "-m", "build", "--sdist",
"--outdir", str(target), str(request.config.rootdir),
])
return next(target.glob("*.tar.gz"))


@pytest.fixture(scope="session")
def setuptools_wheel(tmp_path_factory, request):
with contexts.session_locked_tmp_dir(tmp_path_factory, "wheel_build") as tmp:
dist = next(tmp.glob("*.whl"), None)
if dist:
return dist

subprocess.check_call([
sys.executable, "-m", "build", "--wheel",
"--outdir", str(tmp) , str(request.config.rootdir)
])
return next(tmp.glob("*.whl"))
target = tmp_path_factory.mktemp('wheel_build')
subprocess.check_call([
sys.executable, "-m", "build", "--wheel",
"--outdir", str(target) , str(request.config.rootdir)
])
return next(target.glob("*.whl"))


@pytest.fixture
Expand Down

0 comments on commit 48f463f

Please sign in to comment.