nshutils 0.4.0__tar.gz → 0.5.1__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.
- {nshutils-0.4.0 → nshutils-0.5.1}/PKG-INFO +1 -1
- {nshutils-0.4.0 → nshutils-0.5.1}/pyproject.toml +1 -1
- {nshutils-0.4.0 → nshutils-0.5.1}/src/nshutils/logging.py +6 -1
- {nshutils-0.4.0 → nshutils-0.5.1}/src/nshutils/snoop.py +25 -11
- {nshutils-0.4.0 → nshutils-0.5.1}/README.md +0 -0
- {nshutils-0.4.0 → nshutils-0.5.1}/src/nshutils/__init__.py +0 -0
- {nshutils-0.4.0 → nshutils-0.5.1}/src/nshutils/actsave/__init__.py +0 -0
- {nshutils-0.4.0 → nshutils-0.5.1}/src/nshutils/actsave/_loader.py +0 -0
- {nshutils-0.4.0 → nshutils-0.5.1}/src/nshutils/actsave/_saver.py +0 -0
- {nshutils-0.4.0 → nshutils-0.5.1}/src/nshutils/collections.py +0 -0
- {nshutils-0.4.0 → nshutils-0.5.1}/src/nshutils/typecheck.py +0 -0
@@ -7,6 +7,7 @@ def init_python_logging(
|
|
7
7
|
lovely_tensors: bool = False,
|
8
8
|
lovely_numpy: bool = False,
|
9
9
|
rich: bool = False,
|
10
|
+
rich_tracebacks: bool = False,
|
10
11
|
log_level: int | str | None = logging.INFO,
|
11
12
|
log_save_dir: Path | None = None,
|
12
13
|
):
|
@@ -40,7 +41,7 @@ def init_python_logging(
|
|
40
41
|
try:
|
41
42
|
from rich.logging import RichHandler
|
42
43
|
|
43
|
-
log_handlers.append(RichHandler())
|
44
|
+
log_handlers.append(RichHandler(rich_tracebacks=rich_tracebacks))
|
44
45
|
except ImportError:
|
45
46
|
logging.warning(
|
46
47
|
"Failed to import rich. Falling back to default Python logging."
|
@@ -61,6 +62,7 @@ def pretty(
|
|
61
62
|
log_level: int | str | None = logging.INFO,
|
62
63
|
log_save_dir: Path | None = None,
|
63
64
|
rich_log_handler: bool = True,
|
65
|
+
rich_tracebacks: bool = True,
|
64
66
|
):
|
65
67
|
init_python_logging(
|
66
68
|
lovely_tensors=lovely_tensors,
|
@@ -68,6 +70,7 @@ def pretty(
|
|
68
70
|
rich=rich_log_handler,
|
69
71
|
log_level=log_level,
|
70
72
|
log_save_dir=log_save_dir,
|
73
|
+
rich_tracebacks=rich_tracebacks,
|
71
74
|
)
|
72
75
|
|
73
76
|
|
@@ -78,6 +81,7 @@ def lovely(
|
|
78
81
|
log_level: int | str | None = logging.INFO,
|
79
82
|
log_save_dir: Path | None = None,
|
80
83
|
rich_log_handler: bool = True,
|
84
|
+
rich_tracebacks: bool = True,
|
81
85
|
):
|
82
86
|
pretty(
|
83
87
|
lovely_tensors=lovely_tensors,
|
@@ -85,4 +89,5 @@ def lovely(
|
|
85
89
|
log_level=log_level,
|
86
90
|
log_save_dir=log_save_dir,
|
87
91
|
rich_log_handler=rich_log_handler,
|
92
|
+
rich_tracebacks=rich_tracebacks,
|
88
93
|
)
|
@@ -16,18 +16,26 @@ try:
|
|
16
16
|
import warnings
|
17
17
|
from contextlib import nullcontext
|
18
18
|
|
19
|
-
import lovely_numpy as lo
|
20
|
-
import lovely_tensors as lt
|
21
|
-
import numpy
|
22
19
|
import pysnooper
|
23
20
|
import pysnooper.utils
|
24
|
-
import torch
|
25
21
|
from pkg_resources import DistributionNotFound, get_distribution
|
26
22
|
|
23
|
+
try:
|
24
|
+
import torch
|
25
|
+
except ImportError:
|
26
|
+
torch = None
|
27
|
+
|
28
|
+
try:
|
29
|
+
import numpy
|
30
|
+
except ImportError:
|
31
|
+
numpy = None
|
32
|
+
|
27
33
|
FLOATING_POINTS = set()
|
28
34
|
for i in ["float", "double", "half", "complex128", "complex32", "complex64"]:
|
29
|
-
|
30
|
-
|
35
|
+
# older version of PyTorch do not have complex dtypes
|
36
|
+
if torch is not None and not hasattr(torch, i):
|
37
|
+
continue
|
38
|
+
FLOATING_POINTS.add(getattr(torch, i))
|
31
39
|
|
32
40
|
try:
|
33
41
|
__version__ = get_distribution(__name__).version
|
@@ -37,13 +45,19 @@ try:
|
|
37
45
|
|
38
46
|
def default_format(x):
|
39
47
|
try:
|
40
|
-
|
41
|
-
|
48
|
+
import lovely_tensors as lt
|
49
|
+
|
50
|
+
return = str(lt.lovely(x))
|
42
51
|
except BaseException:
|
43
52
|
return str(x.shape)
|
44
53
|
|
45
54
|
def default_numpy_format(x):
|
46
|
-
|
55
|
+
try:
|
56
|
+
import lovely_numpy as lo
|
57
|
+
|
58
|
+
return str(lo.lovely(x))
|
59
|
+
except BaseException:
|
60
|
+
return str(x.shape)
|
47
61
|
|
48
62
|
class TorchSnooper(pysnooper.tracer.Tracer):
|
49
63
|
def __init__(
|
@@ -155,9 +169,9 @@ try:
|
|
155
169
|
|
156
170
|
def compute_repr(self, x):
|
157
171
|
orig_repr_func = pysnooper.utils.get_repr_function(x, self.orig_custom_repr)
|
158
|
-
if torch.is_tensor(x):
|
172
|
+
if torch is not None and torch.is_tensor(x):
|
159
173
|
return self.tensor_format(x)
|
160
|
-
if isinstance(x, numpy.ndarray):
|
174
|
+
if numpy is not None and isinstance(x, numpy.ndarray):
|
161
175
|
return self.numpy_format(x)
|
162
176
|
if self.is_return_types(x):
|
163
177
|
return self.return_types_repr(x)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|