forked from pex-tool/pex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working: + `py -mpex cowsay -ccowsay -- -t Moo!` + `py -mpex cowsay -ccowsay --venv -- -t Moo!` + `py -mpex cowsay -ccowsay -ocowsay.pex` + `py -mpex cowsay -ccowsay --venv -ocowsay.pex` + `py -mpex cowsay` + `py -mpex.cli cache {prune,purge}` Next up: + Figure out tox on Windows. + Set up failing CI. Work towards pex-tool#2658
- Loading branch information
Showing
28 changed files
with
585 additions
and
88 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
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
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
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,126 @@ | ||
# Copyright 2025 Pex project contributors. | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import | ||
|
||
import os | ||
import sys | ||
from typing import Callable | ||
|
||
from pex.os import WINDOWS | ||
from pex.typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import Text, Optional | ||
|
||
if WINDOWS and not hasattr(os, "replace"): | ||
_MOVEFILE_REPLACE_EXISTING = 0x1 | ||
|
||
_MF = None | ||
|
||
def safe_rename( | ||
src, # type: Text | ||
dst, # type: Text | ||
): | ||
# type: (...) -> None | ||
|
||
import ctypes | ||
from ctypes.wintypes import BOOL, DWORD, LPCWSTR | ||
|
||
global _MF | ||
if _MF is None: | ||
mf = ctypes.windll.kernel32.MoveFileExW | ||
mf.argtypes = ( | ||
# lpExistingFileName | ||
LPCWSTR, | ||
# lpNewFileName | ||
LPCWSTR, | ||
# dwFlags | ||
DWORD, | ||
) | ||
mf.restype = BOOL | ||
_MF = mf | ||
|
||
# See: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexw | ||
if not _MF(src, dst, _MOVEFILE_REPLACE_EXISTING): | ||
raise ctypes.WinError() | ||
|
||
else: | ||
safe_rename = getattr(os, "replace", os.rename) | ||
|
||
|
||
# N.B.: Python 3.7 has os.symlink on Windows, but the implementation does not pass the | ||
# _SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE flag. | ||
if WINDOWS and (not hasattr(os, "symlink") or sys.version_info[:2] < (3, 8)): | ||
_SYMBOLIC_LINK_FLAG_FILE = 0x0 | ||
_SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1 | ||
_SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE = 0x2 | ||
|
||
_CSL = None | ||
|
||
def safe_symlink( | ||
src, # type: Text | ||
dst, # type: Text | ||
): | ||
# type: (...) -> None | ||
|
||
import ctypes | ||
from ctypes.wintypes import BOOLEAN, DWORD, LPCWSTR | ||
|
||
global _CSL | ||
if _CSL is None: | ||
csl = ctypes.windll.kernel32.CreateSymbolicLinkW | ||
csl.argtypes = ( | ||
# lpSymlinkFileName | ||
LPCWSTR, | ||
# lpTargetFileName | ||
LPCWSTR, | ||
# dwFlags | ||
DWORD, | ||
) | ||
csl.restype = BOOLEAN | ||
_CSL = csl | ||
|
||
# See: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsymboliclinkw | ||
flags = _SYMBOLIC_LINK_FLAG_DIRECTORY if os.path.isdir(src) else _SYMBOLIC_LINK_FLAG_FILE | ||
flags |= _SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE | ||
if not _CSL(dst, src, flags): | ||
raise ctypes.WinError() | ||
|
||
else: | ||
safe_realpath = os.path.realpath | ||
safe_symlink = getattr(os, "symlink") | ||
|
||
|
||
if WINDOWS and not hasattr(os, "link"): | ||
_CHL = None | ||
|
||
def safe_link( | ||
src, # type: Text | ||
dst, # type: Text | ||
): | ||
# type: (...) -> None | ||
|
||
import ctypes | ||
from ctypes.wintypes import BOOL, LPCWSTR, LPVOID | ||
|
||
global _CHL | ||
if _CHL is None: | ||
# See: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createhardlinkw | ||
chl = ctypes.windll.kernel32.CreateHardLinkW | ||
chl.argtypes = ( | ||
# lpFileName | ||
LPCWSTR, | ||
# lpExistingFileName | ||
LPCWSTR, | ||
# lpSecurityAttributes (Reserved; must be NULL) | ||
LPVOID, | ||
) | ||
chl.restype = BOOL | ||
_CHL = chl | ||
|
||
if not _CHL(dst, src, None): | ||
raise ctypes.WinError() | ||
|
||
else: | ||
safe_link = getattr(os, "link") |
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,44 @@ | ||
# Copyright 2025 Pex project contributors. | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import | ||
|
||
import fcntl | ||
|
||
from pex.fs.lock import FileLock, FileLockStyle | ||
from pex.typing import TYPE_CHECKING, cast | ||
|
||
if TYPE_CHECKING: | ||
from typing import Callable | ||
|
||
|
||
class PosixFileLock(FileLock): | ||
@staticmethod | ||
def _lock_api(style): | ||
# type: (FileLockStyle.Value) -> Callable[[int, int], None] | ||
|
||
return cast( | ||
"Callable[[int, int], None]", fcntl.flock if style is FileLockStyle.BSD else fcntl.lockf | ||
) | ||
|
||
@classmethod | ||
def acquire( | ||
cls, | ||
fd, # type: int | ||
exclusive, # type: bool | ||
style, # type: FileLockStyle.Value | ||
): | ||
# type: (...) -> PosixFileLock | ||
|
||
cls._lock_api(style)(fd, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH) | ||
return cls(locked_fd=fd, unlock=lambda: cls.release_lock(fd, style=style)) | ||
|
||
@classmethod | ||
def release_lock( | ||
cls, | ||
fd, # type: int | ||
style, # type: FileLockStyle.Value | ||
): | ||
# type: (...) -> None | ||
|
||
cls._lock_api(style)(fd, fcntl.LOCK_UN) |
Oops, something went wrong.