2023-01-06 11:47:44 +00:00
|
|
|
"""
|
|
|
|
A platform independent file lock that supports the with-statement.
|
|
|
|
|
|
|
|
.. autodata:: filelock.__version__
|
|
|
|
:no-value:
|
|
|
|
|
|
|
|
"""
|
2024-06-05 08:37:08 +00:00
|
|
|
|
2023-01-06 11:47:44 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import warnings
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
from ._api import AcquireReturnProxy, BaseFileLock
|
|
|
|
from ._error import Timeout
|
|
|
|
from ._soft import SoftFileLock
|
|
|
|
from ._unix import UnixFileLock, has_fcntl
|
|
|
|
from ._windows import WindowsFileLock
|
2024-06-25 22:16:08 +00:00
|
|
|
from .asyncio import (
|
|
|
|
AsyncAcquireReturnProxy,
|
|
|
|
AsyncSoftFileLock,
|
|
|
|
AsyncUnixFileLock,
|
|
|
|
AsyncWindowsFileLock,
|
|
|
|
BaseAsyncFileLock,
|
|
|
|
)
|
2023-01-06 11:47:44 +00:00
|
|
|
from .version import version
|
|
|
|
|
|
|
|
#: version of the project as a string
|
|
|
|
__version__: str = version
|
|
|
|
|
|
|
|
|
|
|
|
if sys.platform == "win32": # pragma: win32 cover
|
|
|
|
_FileLock: type[BaseFileLock] = WindowsFileLock
|
2024-06-25 22:16:08 +00:00
|
|
|
_AsyncFileLock: type[BaseAsyncFileLock] = AsyncWindowsFileLock
|
2023-09-17 19:40:34 +00:00
|
|
|
else: # pragma: win32 no cover # noqa: PLR5501
|
2023-01-06 11:47:44 +00:00
|
|
|
if has_fcntl:
|
|
|
|
_FileLock: type[BaseFileLock] = UnixFileLock
|
2024-06-25 22:16:08 +00:00
|
|
|
_AsyncFileLock: type[BaseAsyncFileLock] = AsyncUnixFileLock
|
2023-01-06 11:47:44 +00:00
|
|
|
else:
|
|
|
|
_FileLock = SoftFileLock
|
2024-06-25 22:16:08 +00:00
|
|
|
_AsyncFileLock = AsyncSoftFileLock
|
2023-01-06 11:47:44 +00:00
|
|
|
if warnings is not None:
|
2023-04-12 13:51:13 +00:00
|
|
|
warnings.warn("only soft file lock is available", stacklevel=2)
|
2023-01-06 11:47:44 +00:00
|
|
|
|
2024-06-05 08:37:08 +00:00
|
|
|
if TYPE_CHECKING:
|
2023-01-06 11:47:44 +00:00
|
|
|
FileLock = SoftFileLock
|
2024-06-25 22:16:08 +00:00
|
|
|
AsyncFileLock = AsyncSoftFileLock
|
2023-01-06 11:47:44 +00:00
|
|
|
else:
|
2023-05-05 14:08:05 +00:00
|
|
|
#: Alias for the lock, which should be used for the current platform.
|
2023-01-06 11:47:44 +00:00
|
|
|
FileLock = _FileLock
|
2024-06-25 22:16:08 +00:00
|
|
|
AsyncFileLock = _AsyncFileLock
|
2023-01-06 11:47:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
2024-06-05 08:37:08 +00:00
|
|
|
"AcquireReturnProxy",
|
2024-06-25 22:16:08 +00:00
|
|
|
"AsyncAcquireReturnProxy",
|
|
|
|
"AsyncFileLock",
|
|
|
|
"AsyncSoftFileLock",
|
|
|
|
"AsyncUnixFileLock",
|
|
|
|
"AsyncWindowsFileLock",
|
|
|
|
"BaseAsyncFileLock",
|
2024-06-05 08:37:08 +00:00
|
|
|
"BaseFileLock",
|
2023-01-06 11:47:44 +00:00
|
|
|
"FileLock",
|
|
|
|
"SoftFileLock",
|
|
|
|
"Timeout",
|
|
|
|
"UnixFileLock",
|
|
|
|
"WindowsFileLock",
|
2024-06-05 08:37:08 +00:00
|
|
|
"__version__",
|
2023-01-06 11:47:44 +00:00
|
|
|
]
|