Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
5091c904cb
!22 Make singleton class instance dict unique per subclass
From: @lixiaoyong1 
Reviewed-by: @yangzhao_kl 
Signed-off-by: @yangzhao_kl
2024-05-11 03:17:29 +00:00
lixiaoyong
7c8161eff9 Make singleton class instance dict unique per subclass 2024-05-10 06:11:02 -04:00
openeuler-ci-bot
100da0c697
!17 Backport patch:fix permission denied error when lock file is placed in /tmp
From: @tjwangxm 
Reviewed-by: @yangzhao_kl 
Signed-off-by: @yangzhao_kl
2024-05-10 02:24:06 +00:00
wangxiaomeng
94d605040c Backport patch:fix permission denied error when lock file is placed in /tmp 2024-05-09 03:26:42 +08:00
openeuler-ci-bot
fee0e83329
!14 Update package to version 3.13.1
From: @jxy_git 
Reviewed-by: @yangzhao_kl 
Signed-off-by: @yangzhao_kl
2023-12-06 09:12:02 +00:00
jxy_git
5dfe135d82 Update package to version 3.13.1 2023-12-06 13:38:00 +08:00
openeuler-ci-bot
8a2c02c3de
!13 Update package to version 3.12.4
From: @jxy_git 
Reviewed-by: @yangzhao_kl 
Signed-off-by: @yangzhao_kl
2023-10-27 09:36:20 +00:00
jxy_git
2f6f6031b4 Update package to version 3.12.4 2023-10-26 14:25:29 +08:00
openeuler-ci-bot
f65b5614a4
!12 Update package to version 3.12.2
From: @ccdxx 
Reviewed-by: @shinwell_hu 
Signed-off-by: @shinwell_hu
2023-06-25 00:35:19 +00:00
chendexi
ae4b194545 Update package to version 3.12.2 2023-06-21 14:49:29 +08:00
5 changed files with 140 additions and 4 deletions

View File

@ -0,0 +1,36 @@
From 9a6437521131490a72e68813164885cecfd1232d Mon Sep 17 00:00:00 2001
From: kota-iizuka <64062831+kota-iizuka@users.noreply.github.com>
Date: Mon, 25 Mar 2024 23:24:53 +0900
Subject: [PATCH] [BugFix] fix permission denied error when lock file is placed
in `/tmp` (#317)
---
src/filelock/_unix.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/filelock/_unix.py b/src/filelock/_unix.py
index 4ee6033..4ae1fbe 100644
--- a/src/filelock/_unix.py
+++ b/src/filelock/_unix.py
@@ -4,6 +4,7 @@ import os
import sys
from contextlib import suppress
from errno import ENOSYS
+from pathlib import Path
from typing import cast
from ._api import BaseFileLock
@@ -35,7 +36,9 @@ else: # pragma: win32 no cover
def _acquire(self) -> None:
ensure_directory_exists(self.lock_file)
- open_flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC
+ open_flags = os.O_RDWR | os.O_TRUNC
+ if not Path(self.lock_file).exists():
+ open_flags |= os.O_CREAT
fd = os.open(self.lock_file, open_flags, self._context.mode)
with suppress(PermissionError): # This locked is not owned by this UID
os.fchmod(fd, self._context.mode)
--
2.33.0

View File

@ -0,0 +1,83 @@
From 3f6df70c77df591473e1d9b5efdd073ca49d9a5e Mon Sep 17 00:00:00 2001
From: nefrob <25070989+nefrob@users.noreply.github.com>
Date: Mon, 25 Mar 2024 12:54:25 -0400
Subject: [PATCH] Make singleton class instance dict unique per subclass (#318)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Bernát Gábor <gaborjbernat@gmail.com>
Reference: https://github.com/tox-dev/filelock/commit/3f6df70c77df591473e1d9b5efdd073ca49d9a5e#diff-002cb54f397bb2d2e9abfc11353165034eeb49d2fd8aeba0195c241bf5c3daca
---
src/filelock/_api.py | 9 +++++++--
tests/test_filelock.py | 15 +++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/src/filelock/_api.py b/src/filelock/_api.py
index 49eaf1e..7bec3ce 100644
--- a/src/filelock/_api.py
+++ b/src/filelock/_api.py
@@ -8,7 +8,7 @@ import warnings
from abc import ABC, abstractmethod
from dataclasses import dataclass
from threading import local
-from typing import TYPE_CHECKING, Any, ClassVar
+from typing import TYPE_CHECKING, Any
from weakref import WeakValueDictionary
from ._error import Timeout
@@ -77,7 +77,7 @@ class ThreadLocalFileContext(FileLockContext, local):
class BaseFileLock(ABC, contextlib.ContextDecorator):
"""Abstract base class for a file lock object."""
- _instances: ClassVar[WeakValueDictionary[str, BaseFileLock]] = WeakValueDictionary()
+ _instances: WeakValueDictionary[str, BaseFileLock]
def __new__( # noqa: PLR0913
cls,
@@ -100,6 +100,11 @@ class BaseFileLock(ABC, contextlib.ContextDecorator):
return instance # type: ignore[return-value] # https://github.com/python/mypy/issues/15322
+ def __init_subclass__(cls, **kwargs: dict[str, Any]) -> None:
+ """Setup unique state for lock subclasses."""
+ super().__init_subclass__(**kwargs)
+ cls._instances = WeakValueDictionary()
+
def __init__( # noqa: PLR0913
self,
lock_file: str | os.PathLike[str],
diff --git a/tests/test_filelock.py b/tests/test_filelock.py
index 674d81a..f9a4e5f 100644
--- a/tests/test_filelock.py
+++ b/tests/test_filelock.py
@@ -14,6 +14,7 @@ from stat import S_IWGRP, S_IWOTH, S_IWUSR, filemode
from types import TracebackType
from typing import TYPE_CHECKING, Any, Callable, Iterator, Tuple, Type, Union
from uuid import uuid4
+from weakref import WeakValueDictionary
import pytest
@@ -687,3 +688,17 @@ def test_singleton_locks_are_deleted_when_no_external_references_exist(
assert lock_type._instances == {str(lock_path): lock} # noqa: SLF001
del lock
assert lock_type._instances == {} # noqa: SLF001
+
+
+@pytest.mark.skipif(hasattr(sys, "pypy_version_info"), reason="del() does not trigger GC in PyPy")
+@pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock])
+def test_singleton_instance_tracking_is_unique_per_subclass(lock_type: type[BaseFileLock]) -> None:
+ class Lock1(lock_type): # type: ignore[valid-type, misc]
+ pass
+
+ class Lock2(lock_type): # type: ignore[valid-type, misc]
+ pass
+
+ assert isinstance(Lock1._instances, WeakValueDictionary) # noqa: SLF001
+ assert isinstance(Lock2._instances, WeakValueDictionary) # noqa: SLF001
+ assert Lock1._instances is not Lock2._instances # noqa: SLF001
--
2.18.2

Binary file not shown.

BIN
filelock-3.13.1.tar.gz Normal file

Binary file not shown.

View File

@ -1,10 +1,12 @@
Name: python-filelock
Version: 3.12.0
Release: 1
Version: 3.13.1
Release: 3
Summary: A platform independent file lock
License: Unlicense
URL: https://github.com/benediktschmitt/py-filelock
Source0: https://files.pythonhosted.org/packages/24/85/cf4df939cc0a037ebfe18353005e775916faec24dcdbc7a2f6539ad9d943/filelock-3.12.0.tar.gz
Source0: https://files.pythonhosted.org/packages/70/70/41905c80dcfe71b22fb06827b8eae65781783d4a14194bce79d16a013263/filelock-3.13.1.tar.gz
Patch0: 0001-BugFix-fix-permission-denied-error-when-lock-file-is.patch
Patch1: 0002-backport-Make-singleton-class-instance-dict-unique-per-subclass.patch
BuildArch: noarch
@ -41,7 +43,7 @@ independent file locking mechanism for Python.
%pyproject_build
%install
%pyproject_install filelock==%{version}
%pyproject_install
%check
export PYTHONPATH=%{buildroot}%{python3_sitelib}/
@ -62,6 +64,21 @@ pytest
%doc README.md
%changelog
* Fri May 10 2024 lixiaoyong <lixiaoyong@kylinos.cn> - 3.13.1-3
- Backport patch:Make singleton class instance dict unique per subclass
* Thu May 09 2024 wangxiaomeng <wangxiaomeng@kylinos.cn> - 3.13.1-2
- Backport patch:fix permission denied error when lock file is placed in /tmp
* Wed Dec 06 2023 jiangxinyu <jiangxinyu@kylinos.cn> - 3.13.1-1
- Update package to version 3.13.1
* Thu Oct 26 2023 jiangxinyu <jiangxinyu@kylinos.cn> - 3.12.4-1
- Update package to version 3.12.4
* Wed Jun 21 2023 chendexi <chendexi@kylinos.cn> - 3.12.2-1
- Update package to version 3.12.2
* Thu Apr 27 2023 xu_ping <707078654@qq.com> - 3.12.0-1
- Upgrade to 3.12.0