nshutils 0.17.0__py3-none-any.whl → 0.19.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/__init__.py CHANGED
@@ -1,8 +1,11 @@
1
+ from __future__ import annotations
2
+
1
3
  from . import actsave as actsave
2
4
  from . import typecheck as typecheck
3
- from ._display import display as display
4
5
  from .actsave import ActLoad as ActLoad
5
6
  from .actsave import ActSave as ActSave
7
+ from .collections import apply_to_collection as apply_to_collection
8
+ from .display import display as display
6
9
  from .logging import init_python_logging as init_python_logging
7
10
  from .logging import lovely as lovely
8
11
  from .logging import pretty as pretty
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from ._loader import ActLoad as ActLoad
2
4
  from ._saver import Activation as Activation
3
5
  from ._saver import ActSave as ActSave
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import pprint
2
4
  from dataclasses import dataclass, field
3
5
  from functools import cached_property
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import contextlib
2
4
  import fnmatch
3
5
  import tempfile
nshutils/collections.py CHANGED
@@ -2,6 +2,8 @@
2
2
  # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # http://www.apache.org/licenses/LICENSE-2.0
4
4
  #
5
+ from __future__ import annotations
6
+
5
7
  import dataclasses
6
8
  from collections import OrderedDict, defaultdict
7
9
  from collections.abc import Callable, Mapping, Sequence
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import importlib.util
2
4
  from functools import cache
3
5
  from typing import Any
@@ -25,7 +27,7 @@ def _rich_installed():
25
27
 
26
28
  def display(*args: Any):
27
29
  """
28
- Display the given arguments in the current environment.
30
+ Display the given arguments in the current environment.
29
31
 
30
32
  If executed in an IPython environment, the display will be handled
31
33
  by treescope if installed, or rich if available. If neither are
nshutils/logging.py CHANGED
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import logging
2
4
  from pathlib import Path
3
5
 
@@ -7,7 +9,7 @@ def init_python_logging(
7
9
  lovely_tensors: bool = False,
8
10
  lovely_numpy: bool = False,
9
11
  treescope: bool = False,
10
- treescope_autovisualize_arrays: bool = True,
12
+ treescope_autovisualize_arrays: bool = False,
11
13
  rich: bool = False,
12
14
  rich_tracebacks: bool = False,
13
15
  log_level: int | str | None = logging.INFO,
@@ -81,8 +83,8 @@ def pretty(
81
83
  *,
82
84
  lovely_tensors: bool = True,
83
85
  lovely_numpy: bool = True,
84
- treescope: bool = True,
85
- treescope_autovisualize_arrays: bool = True,
86
+ treescope: bool = False,
87
+ treescope_autovisualize_arrays: bool = False,
86
88
  log_level: int | str | None = logging.INFO,
87
89
  log_save_dir: Path | None = None,
88
90
  rich_log_handler: bool = False,
@@ -104,8 +106,8 @@ def lovely(
104
106
  *,
105
107
  lovely_tensors: bool = True,
106
108
  lovely_numpy: bool = True,
107
- treescope: bool = True,
108
- treescope_autovisualize_arrays: bool = True,
109
+ treescope: bool = False,
110
+ treescope_autovisualize_arrays: bool = False,
109
111
  log_level: int | str | None = logging.INFO,
110
112
  log_save_dir: Path | None = None,
111
113
  rich_log_handler: bool = False,
nshutils/snoop.py CHANGED
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import contextlib
2
4
  import importlib.metadata
3
5
  from typing import Any, Protocol, cast
@@ -13,6 +15,7 @@ class SnoopConstructor(Protocol):
13
15
  def disable(self) -> contextlib.AbstractContextManager: ...
14
16
 
15
17
 
18
+ snoop: SnoopConstructor
16
19
  try:
17
20
  import warnings
18
21
  from contextlib import nullcontext
@@ -201,7 +204,7 @@ try:
201
204
  disable = nullcontext
202
205
  __call__ = TorchSnooper
203
206
 
204
- snoop: SnoopConstructor = cast(Any, _Snoop())
207
+ snoop = cast(Any, _Snoop())
205
208
 
206
209
  except ImportError:
207
210
  import warnings
@@ -227,4 +230,4 @@ except ImportError:
227
230
 
228
231
  return super().__enter__()
229
232
 
230
- snoop: SnoopConstructor = cast(Any, _snoop_cls)
233
+ snoop = cast(Any, _snoop_cls)
nshutils/typecheck.py CHANGED
@@ -1,6 +1,10 @@
1
+ from __future__ import annotations
2
+
1
3
  import os
4
+ import sys
2
5
  from collections.abc import Sequence
3
6
  from logging import getLogger
7
+ from types import FrameType as _FrameType
4
8
  from typing import Any
5
9
 
6
10
  from jaxtyping import BFloat16 as BFloat16
@@ -76,6 +80,21 @@ def typecheck_modules(modules: Sequence[str]):
76
80
  log.critical(f"Type checking the following modules: {modules}")
77
81
 
78
82
 
83
+ def _get_frame_package_name_or_none(frame: _FrameType) -> str | None:
84
+ # Taken from `beartype._util.func.utilfuncframe.get_frame_package_name_or_none`.
85
+ assert isinstance(frame, _FrameType), f"{repr(frame)} not stack frame."
86
+
87
+ # Fully-qualified name of the parent package of the child module declaring
88
+ # the callable whose code object is that of this stack frame's if that
89
+ # module declares its name *OR* the empty string otherwise (e.g., if that
90
+ # module is either a top-level module or script residing outside any parent
91
+ # package structure).
92
+ frame_package_name = frame.f_globals.get("__package__")
93
+
94
+ # Return the name of this parent package.
95
+ return frame_package_name
96
+
97
+
79
98
  def typecheck_this_module(additional_modules: Sequence[str] = ()):
80
99
  """
81
100
  Typecheck the calling module and any additional modules using `jaxtyping`.
@@ -86,13 +105,11 @@ def typecheck_this_module(additional_modules: Sequence[str] = ()):
86
105
  # Get the calling module's name.
87
106
  # Here, we can just use beartype's internal implementation behind
88
107
  # `beartype_this_package`.
89
- from beartype._util.func.utilfuncframe import get_frame, get_frame_package_name
90
108
 
91
109
  # Get the calling module's name.
92
- assert get_frame is not None, "get_frame is None"
93
- frame = get_frame(1)
110
+ frame = sys._getframe(1)
94
111
  assert frame is not None, "frame is None"
95
- calling_module_name = get_frame_package_name(frame)
112
+ calling_module_name = _get_frame_package_name_or_none(frame)
96
113
  assert calling_module_name is not None, "calling_module_name is None"
97
114
 
98
115
  # Typecheck the calling module + any additional modules.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: nshutils
3
- Version: 0.17.0
3
+ Version: 0.19.0
4
4
  Summary:
5
5
  Author: Nima Shoghi
6
6
  Author-email: nimashoghi@gmail.com
@@ -9,6 +9,7 @@ Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.10
10
10
  Classifier: Programming Language :: Python :: 3.11
11
11
  Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
12
13
  Provides-Extra: extra
13
14
  Requires-Dist: beartype
14
15
  Requires-Dist: jaxtyping
@@ -20,7 +21,7 @@ Requires-Dist: rich ; extra == "extra"
20
21
  Requires-Dist: treescope ; extra == "extra"
21
22
  Requires-Dist: typing-extensions
22
23
  Requires-Dist: uuid7
23
- Project-URL: homepage, https://github.com/nimashoghi/nshutils
24
+ Project-URL: Homepage, https://github.com/nimashoghi/nshutils
24
25
  Description-Content-Type: text/markdown
25
26
 
26
27
  # nshutils
@@ -0,0 +1,12 @@
1
+ nshutils/__init__.py,sha256=4sIp11UG2TFbvfRKbWdVUX4lzIKlsYEJuFK34735rSQ,642
2
+ nshutils/actsave/__init__.py,sha256=hAVsog9d1g3_rQN1TRslrl6sK1PhCGbjy8PPUAmJI58,203
3
+ nshutils/actsave/_loader.py,sha256=mof3HezUNvLliz7macstX6ewXW05L0Mtv3zJyrbmImg,4640
4
+ nshutils/actsave/_saver.py,sha256=Kor7PEk__noRDEAfCZ_I4vxql5UfWSIQIQ1OmW2RRTI,10290
5
+ nshutils/collections.py,sha256=QWGyANmo4Efq4XRNHDSTE9tRLStwEZHGwE0ATHR-Vqo,5233
6
+ nshutils/display.py,sha256=Ge63yllx7gi-MKL3mKQeQ5doql_nj56-o5aoTVmusDg,1473
7
+ nshutils/logging.py,sha256=-6IB0GTDDS8ue1H2tzkv_OLf4bZVN1ywL08TlDZWbtQ,3737
8
+ nshutils/snoop.py,sha256=7d7_Q5sJmINL1J29wcnxEvpV95zvZYNoVn5frCq-rww,7393
9
+ nshutils/typecheck.py,sha256=UOUYfa72wTmc-a7VQw52tKFb4U10xq1qcZuEWc2sAd8,5588
10
+ nshutils-0.19.0.dist-info/METADATA,sha256=g7LvXvnncRKS7MJJ6BmZHZ4aMHVbb6X77jJx6wD9Dwk,4168
11
+ nshutils-0.19.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
12
+ nshutils-0.19.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.0
2
+ Generator: poetry-core 2.1.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,12 +0,0 @@
1
- nshutils/__init__.py,sha256=T1MnsjctEI1c5wM06d_hUOuGIYLIz_NEb1e_tT-TgQ0,539
2
- nshutils/_display.py,sha256=6CSaKdsFBHBGQXMppumRfO5fOfiJDXQ7FhtAvN8id7M,1441
3
- nshutils/actsave/__init__.py,sha256=6gJ49011Ad3kS8BejeZRPj7ZyVyIcmX-VKLEmYZyGM8,167
4
- nshutils/actsave/_loader.py,sha256=fAhD32DrJa4onkYfcwc21YIeGEYzOSXCK_HVo9SZLgQ,4604
5
- nshutils/actsave/_saver.py,sha256=-uKMmMKjEErCa8pfLhAW4077GFcUjxr0Qq0PFAnbEOw,10254
6
- nshutils/collections.py,sha256=EE_qLd-LrsX5lsyk9GSKh03Q8bhn9CHB3jiEeNj4uF4,5197
7
- nshutils/logging.py,sha256=n5v2sNmSj5gKkdjL4avP4OpoUzJb4BVtdDtTm_dzVgM,3696
8
- nshutils/snoop.py,sha256=JW2JZg6oZd9WWubOP6ok6GUbh5mIQUOdP_T29iH5RCE,7369
9
- nshutils/typecheck.py,sha256=_KtfinRy9A0Dgq78kN5MGGrefvb6jn2tGY6svdLEBAs,4915
10
- nshutils-0.17.0.dist-info/METADATA,sha256=LF0Opz5cgFBshbBKuAbfAZJd011ceKdA2_sDvCA2qzA,4117
11
- nshutils-0.17.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
- nshutils-0.17.0.dist-info/RECORD,,