nshutils 0.13.0__py3-none-any.whl → 0.15.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,
@@ -17,7 +19,7 @@ def init_python_logging(
17
19
 
18
20
  _lovely_tensors.monkey_patch()
19
21
  except ImportError:
20
- logging.warning(
22
+ logging.exception(
21
23
  "Failed to import `lovely_tensors`. Ignoring pretty PyTorch tensor formatting"
22
24
  )
23
25
 
@@ -27,10 +29,30 @@ def init_python_logging(
27
29
 
28
30
  _lovely_numpy.set_config(repr=_lovely_numpy.lovely)
29
31
  except ImportError:
30
- logging.warning(
32
+ logging.exception(
31
33
  "Failed to import `lovely_numpy`. Ignoring pretty numpy array formatting"
32
34
  )
33
35
 
36
+ if treescope:
37
+ try:
38
+ # Check if we're in a Jupyter environment
39
+ from IPython import get_ipython
40
+
41
+ if get_ipython() is not None:
42
+ import treescope as _treescope # type: ignore
43
+
44
+ _treescope.basic_interactive_setup(
45
+ autovisualize_arrays=treescope_autovisualize_arrays
46
+ )
47
+ else:
48
+ logging.exception(
49
+ "Treescope setup is only supported in Jupyter notebooks. Skipping."
50
+ )
51
+ except ImportError:
52
+ logging.exception(
53
+ "Failed to import `treescope` or `IPython`. Ignoring `treescope` registration"
54
+ )
55
+
34
56
  log_handlers: list[logging.Handler] = []
35
57
  if log_save_dir:
36
58
  log_file = log_save_dir / "logging.log"
@@ -43,7 +65,7 @@ def init_python_logging(
43
65
 
44
66
  log_handlers.append(RichHandler(rich_tracebacks=rich_tracebacks))
45
67
  except ImportError:
46
- logging.warning(
68
+ logging.exception(
47
69
  "Failed to import rich. Falling back to default Python logging."
48
70
  )
49
71
 
@@ -59,14 +81,18 @@ def pretty(
59
81
  *,
60
82
  lovely_tensors: bool = True,
61
83
  lovely_numpy: bool = True,
84
+ treescope: bool = True,
85
+ treescope_autovisualize_arrays: bool = True,
62
86
  log_level: int | str | None = logging.INFO,
63
87
  log_save_dir: Path | None = None,
64
- rich_log_handler: bool = True,
65
- rich_tracebacks: bool = True,
88
+ rich_log_handler: bool = False,
89
+ rich_tracebacks: bool = False,
66
90
  ):
67
91
  init_python_logging(
68
92
  lovely_tensors=lovely_tensors,
69
93
  lovely_numpy=lovely_numpy,
94
+ treescope=treescope,
95
+ treescope_autovisualize_arrays=treescope_autovisualize_arrays,
70
96
  rich=rich_log_handler,
71
97
  log_level=log_level,
72
98
  log_save_dir=log_save_dir,
@@ -78,14 +104,18 @@ def lovely(
78
104
  *,
79
105
  lovely_tensors: bool = True,
80
106
  lovely_numpy: bool = True,
107
+ treescope: bool = True,
108
+ treescope_autovisualize_arrays: bool = True,
81
109
  log_level: int | str | None = logging.INFO,
82
110
  log_save_dir: Path | None = None,
83
- rich_log_handler: bool = True,
84
- rich_tracebacks: bool = True,
111
+ rich_log_handler: bool = False,
112
+ rich_tracebacks: bool = False,
85
113
  ):
86
114
  pretty(
87
115
  lovely_tensors=lovely_tensors,
88
116
  lovely_numpy=lovely_numpy,
117
+ treescope=treescope,
118
+ treescope_autovisualize_arrays=treescope_autovisualize_arrays,
89
119
  log_level=log_level,
90
120
  log_save_dir=log_save_dir,
91
121
  rich_log_handler=rich_log_handler,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nshutils
3
- Version: 0.13.0
3
+ Version: 0.15.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
6
+ nshutils/logging.py,sha256=3NwW2pSoXBktiRWPGtUzs8BrOW8H9ZpfI-8wiLbEnEE,3721
7
7
  nshutils/snoop.py,sha256=JW2JZg6oZd9WWubOP6ok6GUbh5mIQUOdP_T29iH5RCE,7369
8
8
  nshutils/typecheck.py,sha256=_KtfinRy9A0Dgq78kN5MGGrefvb6jn2tGY6svdLEBAs,4915
9
- nshutils-0.13.0.dist-info/METADATA,sha256=gby5UkK98NiS-G0xv5jhIh8CY5pHYLH2cd6UHWzepbU,4073
10
- nshutils-0.13.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
11
- nshutils-0.13.0.dist-info/RECORD,,
9
+ nshutils-0.15.0.dist-info/METADATA,sha256=0Ak2KBfkCHz2g-8ytTX2YIm6VF5Jic_HJT3JG0t8F0U,4117
10
+ nshutils-0.15.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
11
+ nshutils-0.15.0.dist-info/RECORD,,