zstdlib 0.10.4__tar.gz → 0.10.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {zstdlib-0.10.4 → zstdlib-0.10.5}/PKG-INFO +1 -1
- zstdlib-0.10.5/tests/test_hybridmethod.py +37 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/__init__.py +3 -1
- zstdlib-0.10.5/zstdlib/hybridmethod.py +45 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/macos.py +9 -12
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib.egg-info/PKG-INFO +1 -1
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib.egg-info/SOURCES.txt +2 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/LICENSE +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/README.md +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/pyproject.toml +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/setup.cfg +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/__init__.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/log/__init__.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/log/base.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/log/test_cute.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/log/test_trace.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/test_ansi.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/test_enum.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/test_exc_capture.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/test_frozen.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/test_io.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/test_lazy.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/test_not_set.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/tests/test_singleton.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/ansi.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/enum.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/exc_capture.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/frozen.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/io.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/lazy.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/log/__init__.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/log/cute.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/log/trace.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/not_set.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/py.typed +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/signal_cm.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib/singleton.py +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib.egg-info/dependency_links.txt +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib.egg-info/requires.txt +0 -0
- {zstdlib-0.10.4 → zstdlib-0.10.5}/zstdlib.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring,unused-variable
|
|
2
|
+
from typing import ClassVar
|
|
3
|
+
import unittest
|
|
4
|
+
|
|
5
|
+
from zstdlib import hybridmethod
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestHybridMethod(unittest.TestCase):
|
|
9
|
+
|
|
10
|
+
def test_hybridmethod(self) -> None:
|
|
11
|
+
|
|
12
|
+
class A:
|
|
13
|
+
objs: ClassVar[dict[int, A]] = {}
|
|
14
|
+
|
|
15
|
+
def __init__(self, x: int) -> None:
|
|
16
|
+
self.x: int = x
|
|
17
|
+
self.objs[x] = self
|
|
18
|
+
|
|
19
|
+
@hybridmethod
|
|
20
|
+
def get(self: A | None, cls: type[A], *, x: int | None = None) -> A:
|
|
21
|
+
if x is not None:
|
|
22
|
+
return cls.objs[x]
|
|
23
|
+
if self is None:
|
|
24
|
+
raise TypeError("Unable to determine x")
|
|
25
|
+
return cls.objs[self.x]
|
|
26
|
+
|
|
27
|
+
a = A(1)
|
|
28
|
+
b = A(2)
|
|
29
|
+
self.assertIsNot(a, b)
|
|
30
|
+
self.assertIs(a.get(), a)
|
|
31
|
+
self.assertIs(A.get(x=2), b)
|
|
32
|
+
with self.assertRaises(TypeError):
|
|
33
|
+
A.get()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
unittest.main()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
__version__ = "0.10.
|
|
1
|
+
__version__ = "0.10.5"
|
|
2
2
|
|
|
3
3
|
from .exc_capture import ExcCapture, ExcDelay
|
|
4
|
+
from .hybridmethod import hybridmethod
|
|
4
5
|
from .not_set import NotSetType, NotSet
|
|
5
6
|
from .frozen import Freezable, frozen
|
|
6
7
|
from .singleton import Singleton
|
|
@@ -18,6 +19,7 @@ __all__ = (
|
|
|
18
19
|
"Singleton",
|
|
19
20
|
"auto",
|
|
20
21
|
"frozen",
|
|
22
|
+
"hybridmethod",
|
|
21
23
|
"io",
|
|
22
24
|
"lazy",
|
|
23
25
|
"log",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from typing import Concatenate, overload
|
|
2
|
+
from collections.abc import Callable
|
|
3
|
+
|
|
4
|
+
__all__ = ("hybridmethod",)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
type _HybridFunc[T, R, **P] = Callable[Concatenate[T | None, type[T], P], R]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class hybridmethod[T, R, **P]: # Name aligns with @staticmethod and such
|
|
11
|
+
"""
|
|
12
|
+
A member function decorator that combines an instances bound function and @classmethod
|
|
13
|
+
If a member function uses @hybridmethod then it may use the signature:
|
|
14
|
+
@hybridmethod
|
|
15
|
+
def f(self: Self | None, cls: type[Self], ...)
|
|
16
|
+
This could be used to implement functions such as:
|
|
17
|
+
def history(self: Self | None, cls: type[Self], *, id: int | None = None): ...
|
|
18
|
+
...
|
|
19
|
+
A.history(id=a.id)
|
|
20
|
+
A.history(id=0)
|
|
21
|
+
a.history()
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
__slots__ = ("_fn",)
|
|
25
|
+
|
|
26
|
+
def __init__(self, fn: _HybridFunc[T, R, P]) -> None:
|
|
27
|
+
self._fn: _HybridFunc[T, R, P] = fn
|
|
28
|
+
|
|
29
|
+
@overload
|
|
30
|
+
def __get__(self, instance: T, owner: type[T] | None = None, /) -> Callable[P, R]: ...
|
|
31
|
+
|
|
32
|
+
@overload
|
|
33
|
+
def __get__(self, instance: None, owner: type[T], /) -> Callable[P, R]: ...
|
|
34
|
+
|
|
35
|
+
def __get__(self, instance: T | None, owner: type[T] | None = None, /) -> Callable[P, R]:
|
|
36
|
+
if owner is None:
|
|
37
|
+
if instance is None:
|
|
38
|
+
raise TypeError("instance and owner should not both be None")
|
|
39
|
+
owner = type(instance)
|
|
40
|
+
|
|
41
|
+
# functools.partial doesn't preserve typing as we need it to :/
|
|
42
|
+
def ret(*args: P.args, **kwargs: P.kwargs) -> R:
|
|
43
|
+
return self._fn(instance, owner, *args, **kwargs)
|
|
44
|
+
|
|
45
|
+
return ret
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import NamedTuple,
|
|
1
|
+
from typing import NamedTuple, Final, ClassVar, Self
|
|
2
2
|
from collections.abc import Callable, Iterable
|
|
3
3
|
from subprocess import TimeoutExpired, Popen
|
|
4
4
|
from multiprocessing import Process
|
|
@@ -17,15 +17,12 @@ __all__ = ("Caffeinate", "osascript")
|
|
|
17
17
|
|
|
18
18
|
CAFFEINATE = Path("/usr/bin/caffeinate") # This is a hard-coded location on macOS
|
|
19
19
|
KILL_WAIT_SECONDS: int = 60 # How long to .wait after .send_signal
|
|
20
|
-
_CAFFEINATE_ENABLED = CAFFEINATE.exists()
|
|
21
|
-
|
|
22
|
-
P = ParamSpec("P")
|
|
23
|
-
R = TypeVar("R")
|
|
24
20
|
|
|
25
21
|
|
|
26
22
|
class Caffeinate:
|
|
27
23
|
"""A small wrapper class around macOS' CLI tool Caffeinate"""
|
|
28
24
|
|
|
25
|
+
SUPPORTED: Final[ClassVar[bool]] = CAFFEINATE.exists()
|
|
29
26
|
_finalizing: ClassVar[bool] = False
|
|
30
27
|
_instances_lock: ClassVar[Lock] = Lock()
|
|
31
28
|
_instances: ClassVar[set[Caffeinate]] = set() # Self makes mypy upset here; maybe b/c of subclassing? :/
|
|
@@ -57,7 +54,7 @@ class Caffeinate:
|
|
|
57
54
|
user: bool = False,
|
|
58
55
|
timeout: int | None = None,
|
|
59
56
|
wait: int | Popen | Process | None = None,
|
|
60
|
-
# For
|
|
57
|
+
# For Caffeinate class itself
|
|
61
58
|
signal: Signals | int = Signals.SIGTERM,
|
|
62
59
|
block: bool = False,
|
|
63
60
|
) -> None:
|
|
@@ -76,13 +73,13 @@ class Caffeinate:
|
|
|
76
73
|
disk: If True: Create an assertion to prevent the disk from idle sleeping.
|
|
77
74
|
system: If True: Create an assertion to prevent the system from sleeping. This assertion is valid only when system is running on AC power.
|
|
78
75
|
user: If True: Create an assertion to declare that user is active. If the display is off, this option turns the display on and prevents the display from going into idle sleep. If a timeout is not specified with '-t' option, then this assertion is taken with a default of 5 second timeout.
|
|
79
|
-
timeout: Specifies the timeout value in seconds for which this assertion has to be valid. The assertion is dropped after the specified timeout. Timeout value is not used by the
|
|
80
|
-
wait: Waits for the process with the specified pid to exit. Once the the process exits, the assertion is also released. This option is ignored by the
|
|
76
|
+
timeout: Specifies the timeout value in seconds for which this assertion has to be valid. The assertion is dropped after the specified timeout. Timeout value is not used by the Caffeinate CLI when cmd is passed. Note: this timeout is passed to the Caffeinate CLI command, it is not enforced by python
|
|
77
|
+
wait: Waits for the process with the specified pid to exit. Once the the process exits, the assertion is also released. This option is ignored by the Caffeinate CLI when cmd is passed.
|
|
81
78
|
This option conflicts with cmd.
|
|
82
79
|
signal: The signal used to kill the child process (if cmd likely the process Caffeinate execs into). If 0, do not kill it
|
|
83
80
|
block: If True: Block until cmd has finished executing before returning from __enter__
|
|
84
81
|
"""
|
|
85
|
-
if not
|
|
82
|
+
if not self.SUPPORTED:
|
|
86
83
|
raise NotImplementedError(f"This class is only available on macOS via: {CAFFEINATE}")
|
|
87
84
|
if (
|
|
88
85
|
isinstance(timeout, float)
|
|
@@ -129,7 +126,7 @@ class Caffeinate:
|
|
|
129
126
|
pid = getpid()
|
|
130
127
|
with self._instances_lock:
|
|
131
128
|
if self._finalizing:
|
|
132
|
-
raise PythonFinalizationError("No more new
|
|
129
|
+
raise PythonFinalizationError("No more new Caffeinate subprocesses are allowed")
|
|
133
130
|
self._data = self._Data(pid, Popen(self._cmd)) # pylint: disable=consider-using-with
|
|
134
131
|
self._instances.add(self)
|
|
135
132
|
self._log.debug("Created Popen(%s), pid=%s", self._cmd, self._data.proc.pid)
|
|
@@ -158,7 +155,7 @@ class Caffeinate:
|
|
|
158
155
|
self._stop(signal)
|
|
159
156
|
|
|
160
157
|
@classmethod
|
|
161
|
-
def decorate(
|
|
158
|
+
def decorate[**P, R](
|
|
162
159
|
cls, cmd: list[Path | str | None] | None = None, **init_kwargs: object
|
|
163
160
|
) -> Callable[[Callable[P, R]], Callable[P, R]]:
|
|
164
161
|
"""A decorator to wrap a function with a Caffeinate instance
|
|
@@ -250,5 +247,5 @@ class Caffeinate:
|
|
|
250
247
|
|
|
251
248
|
|
|
252
249
|
assert 0 not in Signals, "0 not expected in signal.Signals as it's a nop"
|
|
253
|
-
if
|
|
250
|
+
if Caffeinate.SUPPORTED:
|
|
254
251
|
atexit.register(Caffeinate._atexit) # pylint: disable=protected-access
|
|
@@ -6,6 +6,7 @@ tests/test_ansi.py
|
|
|
6
6
|
tests/test_enum.py
|
|
7
7
|
tests/test_exc_capture.py
|
|
8
8
|
tests/test_frozen.py
|
|
9
|
+
tests/test_hybridmethod.py
|
|
9
10
|
tests/test_io.py
|
|
10
11
|
tests/test_lazy.py
|
|
11
12
|
tests/test_not_set.py
|
|
@@ -19,6 +20,7 @@ zstdlib/ansi.py
|
|
|
19
20
|
zstdlib/enum.py
|
|
20
21
|
zstdlib/exc_capture.py
|
|
21
22
|
zstdlib/frozen.py
|
|
23
|
+
zstdlib/hybridmethod.py
|
|
22
24
|
zstdlib/io.py
|
|
23
25
|
zstdlib/lazy.py
|
|
24
26
|
zstdlib/macos.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|