-
-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
- Loading branch information
1 parent
6305d9a
commit 0f8831e
Showing
7 changed files
with
73 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Create session views of the build wheel/sdist into the :ref:`temp_dir` folder - by :user:`gaborbernat`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
import os | ||
import shutil | ||
from itertools import chain | ||
from os.path import commonpath | ||
from pathlib import Path | ||
|
||
|
||
def create_session_view(package: Path, temp_path: Path) -> Path: | ||
"""Allows using the file after you no longer holding a lock to it by moving it into a temp folder""" | ||
# we'll number the active instances, and use the max value as session folder for a new build | ||
# note we cannot change package names as PEP-491 (wheel binary format) | ||
# is strict about file name structure | ||
|
||
temp_path.mkdir(parents=True, exist_ok=True) | ||
exists = [i.name for i in temp_path.iterdir()] | ||
file_id = max(chain((0,), (int(i) for i in exists if str(i).isnumeric()))) | ||
session_dir = temp_path / str(file_id + 1) | ||
session_dir.mkdir() | ||
session_package = session_dir / package.name | ||
|
||
links = False # if we can do hard links do that, otherwise just copy | ||
if hasattr(os, "link"): | ||
try: | ||
os.link(package, session_package) | ||
links = True | ||
except (OSError, NotImplementedError): | ||
pass | ||
if not links: | ||
shutil.copyfile(package, session_package) | ||
operation = "links" if links else "copied" | ||
common = commonpath((session_package, package)) | ||
rel_session, rel_package = session_package.relative_to(common), package.relative_to(common) | ||
logging.debug("package %s %s to %s (%s)", rel_session, operation, rel_package, common) | ||
return session_package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters