nshutils 0.18.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
@@ -2,9 +2,10 @@ from __future__ import annotations
2
2
 
3
3
  from . import actsave as actsave
4
4
  from . import typecheck as typecheck
5
- from ._display import display as display
6
5
  from .actsave import ActLoad as ActLoad
7
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
8
9
  from .logging import init_python_logging as init_python_logging
9
10
  from .logging import lovely as lovely
10
11
  from .logging import pretty as pretty
@@ -27,7 +27,7 @@ def _rich_installed():
27
27
 
28
28
  def display(*args: Any):
29
29
  """
30
- Display the given arguments in the current environment.
30
+ Display the given arguments in the current environment.
31
31
 
32
32
  If executed in an IPython environment, the display will be handled
33
33
  by treescope if installed, or rich if available. If neither are
nshutils/snoop.py CHANGED
@@ -15,6 +15,7 @@ class SnoopConstructor(Protocol):
15
15
  def disable(self) -> contextlib.AbstractContextManager: ...
16
16
 
17
17
 
18
+ snoop: SnoopConstructor
18
19
  try:
19
20
  import warnings
20
21
  from contextlib import nullcontext
@@ -203,7 +204,7 @@ try:
203
204
  disable = nullcontext
204
205
  __call__ = TorchSnooper
205
206
 
206
- snoop: SnoopConstructor = cast(Any, _Snoop())
207
+ snoop = cast(Any, _Snoop())
207
208
 
208
209
  except ImportError:
209
210
  import warnings
@@ -229,4 +230,4 @@ except ImportError:
229
230
 
230
231
  return super().__enter__()
231
232
 
232
- snoop: SnoopConstructor = cast(Any, _snoop_cls)
233
+ snoop = cast(Any, _snoop_cls)
nshutils/typecheck.py CHANGED
@@ -1,8 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import os
4
+ import sys
4
5
  from collections.abc import Sequence
5
6
  from logging import getLogger
7
+ from types import FrameType as _FrameType
6
8
  from typing import Any
7
9
 
8
10
  from jaxtyping import BFloat16 as BFloat16
@@ -78,6 +80,21 @@ def typecheck_modules(modules: Sequence[str]):
78
80
  log.critical(f"Type checking the following modules: {modules}")
79
81
 
80
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
+
81
98
  def typecheck_this_module(additional_modules: Sequence[str] = ()):
82
99
  """
83
100
  Typecheck the calling module and any additional modules using `jaxtyping`.
@@ -88,13 +105,11 @@ def typecheck_this_module(additional_modules: Sequence[str] = ()):
88
105
  # Get the calling module's name.
89
106
  # Here, we can just use beartype's internal implementation behind
90
107
  # `beartype_this_package`.
91
- from beartype._util.func.utilfuncframe import get_frame, get_frame_package_name
92
108
 
93
109
  # Get the calling module's name.
94
- assert get_frame is not None, "get_frame is None"
95
- frame = get_frame(1)
110
+ frame = sys._getframe(1)
96
111
  assert frame is not None, "frame is None"
97
- calling_module_name = get_frame_package_name(frame)
112
+ calling_module_name = _get_frame_package_name_or_none(frame)
98
113
  assert calling_module_name is not None, "calling_module_name is None"
99
114
 
100
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.18.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=1kiWfKqSELCpTwUv4B6m43cnp2W4RPoD2DX9svgd3IA,575
2
- nshutils/_display.py,sha256=lfxjB5A2SMdtrtElYCP_xhdgIsPjA8XL21G5jKv6dys,1477
3
- nshutils/actsave/__init__.py,sha256=hAVsog9d1g3_rQN1TRslrl6sK1PhCGbjy8PPUAmJI58,203
4
- nshutils/actsave/_loader.py,sha256=mof3HezUNvLliz7macstX6ewXW05L0Mtv3zJyrbmImg,4640
5
- nshutils/actsave/_saver.py,sha256=Kor7PEk__noRDEAfCZ_I4vxql5UfWSIQIQ1OmW2RRTI,10290
6
- nshutils/collections.py,sha256=QWGyANmo4Efq4XRNHDSTE9tRLStwEZHGwE0ATHR-Vqo,5233
7
- nshutils/logging.py,sha256=-6IB0GTDDS8ue1H2tzkv_OLf4bZVN1ywL08TlDZWbtQ,3737
8
- nshutils/snoop.py,sha256=VuEMwFXxI1mXrv2IDaj947s3UhgvoGhgaRxyu2iiIgI,7405
9
- nshutils/typecheck.py,sha256=IC0cbPLlYV2Fnwv4xUl458fhye9_4O3zOpc1dNEgmVM,4951
10
- nshutils-0.18.0.dist-info/METADATA,sha256=TiMkBQTVYLIHbr81cg7GP-hSaTik_shtem0K8T06h1k,4117
11
- nshutils-0.18.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
- nshutils-0.18.0.dist-info/RECORD,,