nshutils 0.12.2__py3-none-any.whl → 0.14.0__py3-none-any.whl

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/logging.py CHANGED
@@ -6,6 +6,8 @@ def init_python_logging(
6
6
  *,
7
7
  lovely_tensors: bool = False,
8
8
  lovely_numpy: bool = False,
9
+ treescope: bool = False,
10
+ treescope_autovisualize_arrays: bool = True,
9
11
  rich: bool = False,
10
12
  rich_tracebacks: bool = False,
11
13
  log_level: int | str | None = logging.INFO,
@@ -31,6 +33,18 @@ def init_python_logging(
31
33
  "Failed to import `lovely_numpy`. Ignoring pretty numpy array formatting"
32
34
  )
33
35
 
36
+ if treescope:
37
+ try:
38
+ import treescope as _treescope # type: ignore
39
+
40
+ _treescope.basic_interactive_setup(
41
+ autovisualize_arrays=treescope_autovisualize_arrays
42
+ )
43
+ except ImportError:
44
+ logging.warning(
45
+ "Failed to import `treescope`. Ignoring `treescope` registration"
46
+ )
47
+
34
48
  log_handlers: list[logging.Handler] = []
35
49
  if log_save_dir:
36
50
  log_file = log_save_dir / "logging.log"
@@ -59,14 +73,18 @@ def pretty(
59
73
  *,
60
74
  lovely_tensors: bool = True,
61
75
  lovely_numpy: bool = True,
76
+ treescope: bool = True,
77
+ treescope_autovisualize_arrays: bool = True,
62
78
  log_level: int | str | None = logging.INFO,
63
79
  log_save_dir: Path | None = None,
64
- rich_log_handler: bool = True,
65
- rich_tracebacks: bool = True,
80
+ rich_log_handler: bool = False,
81
+ rich_tracebacks: bool = False,
66
82
  ):
67
83
  init_python_logging(
68
84
  lovely_tensors=lovely_tensors,
69
85
  lovely_numpy=lovely_numpy,
86
+ treescope=treescope,
87
+ treescope_autovisualize_arrays=treescope_autovisualize_arrays,
70
88
  rich=rich_log_handler,
71
89
  log_level=log_level,
72
90
  log_save_dir=log_save_dir,
@@ -78,14 +96,18 @@ def lovely(
78
96
  *,
79
97
  lovely_tensors: bool = True,
80
98
  lovely_numpy: bool = True,
99
+ treescope: bool = True,
100
+ treescope_autovisualize_arrays: bool = True,
81
101
  log_level: int | str | None = logging.INFO,
82
102
  log_save_dir: Path | None = None,
83
- rich_log_handler: bool = True,
84
- rich_tracebacks: bool = True,
103
+ rich_log_handler: bool = False,
104
+ rich_tracebacks: bool = False,
85
105
  ):
86
106
  pretty(
87
107
  lovely_tensors=lovely_tensors,
88
108
  lovely_numpy=lovely_numpy,
109
+ treescope=treescope,
110
+ treescope_autovisualize_arrays=treescope_autovisualize_arrays,
89
111
  log_level=log_level,
90
112
  log_save_dir=log_save_dir,
91
113
  rich_log_handler=rich_log_handler,
nshutils/snoop.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import contextlib
2
+ import importlib.metadata
2
3
  from typing import Any, Protocol, cast
3
4
 
4
5
  from typing_extensions import TypeVar
@@ -18,7 +19,6 @@ try:
18
19
 
19
20
  import pysnooper # type: ignore
20
21
  import pysnooper.utils # type: ignore
21
- from pkg_resources import DistributionNotFound, get_distribution
22
22
 
23
23
  try:
24
24
  import torch # type: ignore
@@ -38,8 +38,8 @@ try:
38
38
  FLOATING_POINTS.add(getattr(torch, i))
39
39
 
40
40
  try:
41
- __version__ = get_distribution(__name__).version
42
- except DistributionNotFound:
41
+ __version__ = importlib.metadata.version(__name__)
42
+ except importlib.metadata.PackageNotFoundError:
43
43
  # package is not installed
44
44
  pass
45
45
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nshutils
3
- Version: 0.12.2
3
+ Version: 0.14.0
4
4
  Summary:
5
5
  Author: Nima Shoghi
6
6
  Author-email: nimashoghi@gmail.com
@@ -17,6 +17,7 @@ Requires-Dist: lovely-tensors ; extra == "extra"
17
17
  Requires-Dist: numpy
18
18
  Requires-Dist: pysnooper ; extra == "extra"
19
19
  Requires-Dist: rich ; extra == "extra"
20
+ Requires-Dist: treescope ; extra == "extra"
20
21
  Requires-Dist: typing-extensions
21
22
  Requires-Dist: uuid7
22
23
  Project-URL: homepage, https://github.com/nimashoghi/nshutils
@@ -3,9 +3,9 @@ nshutils/actsave/__init__.py,sha256=6gJ49011Ad3kS8BejeZRPj7ZyVyIcmX-VKLEmYZyGM8,
3
3
  nshutils/actsave/_loader.py,sha256=fAhD32DrJa4onkYfcwc21YIeGEYzOSXCK_HVo9SZLgQ,4604
4
4
  nshutils/actsave/_saver.py,sha256=-uKMmMKjEErCa8pfLhAW4077GFcUjxr0Qq0PFAnbEOw,10254
5
5
  nshutils/collections.py,sha256=EE_qLd-LrsX5lsyk9GSKh03Q8bhn9CHB3jiEeNj4uF4,5197
6
- nshutils/logging.py,sha256=tL-6XvdvJEEr7bje9DSmUBpm6pnJS9XG_1fuw3U1eME,2573
7
- nshutils/snoop.py,sha256=XhcFic6jbRP1EaBfcpcdtPdh-4kG6uHWKyZIRN4EPnM,7391
6
+ nshutils/logging.py,sha256=B-S4fPKbMPjJwMrEBrA83VvsBca_3sAokSmzn0A0EEw,3384
7
+ nshutils/snoop.py,sha256=JW2JZg6oZd9WWubOP6ok6GUbh5mIQUOdP_T29iH5RCE,7369
8
8
  nshutils/typecheck.py,sha256=_KtfinRy9A0Dgq78kN5MGGrefvb6jn2tGY6svdLEBAs,4915
9
- nshutils-0.12.2.dist-info/METADATA,sha256=w7k32VmAqHvikP9CCkaWartLJ2EOe3UpqC8U20AN8M0,4073
10
- nshutils-0.12.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
11
- nshutils-0.12.2.dist-info/RECORD,,
9
+ nshutils-0.14.0.dist-info/METADATA,sha256=59Cz9XX3JUg22c_arXyxQRPl7wHIaGHpbxNxbcjxdZs,4117
10
+ nshutils-0.14.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
11
+ nshutils-0.14.0.dist-info/RECORD,,