nshutils 0.17.0__tar.gz → 0.19.0__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.17.0 → nshutils-0.19.0}/PKG-INFO +4 -3
- nshutils-0.19.0/pyproject.toml +40 -0
- {nshutils-0.17.0 → nshutils-0.19.0}/src/nshutils/__init__.py +4 -1
- {nshutils-0.17.0 → nshutils-0.19.0}/src/nshutils/actsave/__init__.py +2 -0
- {nshutils-0.17.0 → nshutils-0.19.0}/src/nshutils/actsave/_loader.py +2 -0
- {nshutils-0.17.0 → nshutils-0.19.0}/src/nshutils/actsave/_saver.py +2 -0
- {nshutils-0.17.0 → nshutils-0.19.0}/src/nshutils/collections.py +2 -0
- nshutils-0.17.0/src/nshutils/_display.py → nshutils-0.19.0/src/nshutils/display.py +3 -1
- {nshutils-0.17.0 → nshutils-0.19.0}/src/nshutils/logging.py +7 -5
- {nshutils-0.17.0 → nshutils-0.19.0}/src/nshutils/snoop.py +5 -2
- {nshutils-0.17.0 → nshutils-0.19.0}/src/nshutils/typecheck.py +21 -4
- nshutils-0.17.0/pyproject.toml +0 -46
- {nshutils-0.17.0 → nshutils-0.19.0}/README.md +0 -0
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: nshutils
|
3
|
-
Version: 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:
|
24
|
+
Project-URL: Homepage, https://github.com/nimashoghi/nshutils
|
24
25
|
Description-Content-Type: text/markdown
|
25
26
|
|
26
27
|
# nshutils
|
@@ -0,0 +1,40 @@
|
|
1
|
+
[project]
|
2
|
+
name = "nshutils"
|
3
|
+
version = "0.19.0"
|
4
|
+
description = ""
|
5
|
+
authors = [{ name = "Nima Shoghi", email = "nimashoghi@gmail.com" }]
|
6
|
+
requires-python = ">=3.10,<4.0"
|
7
|
+
readme = "README.md"
|
8
|
+
|
9
|
+
dependencies = ["numpy", "jaxtyping", "typing-extensions", "beartype", "uuid7"]
|
10
|
+
|
11
|
+
[project.optional-dependencies]
|
12
|
+
extra = ["pysnooper", "lovely-numpy", "lovely-tensors", "rich", "treescope"]
|
13
|
+
|
14
|
+
[project.urls]
|
15
|
+
homepage = "https://github.com/nimashoghi/nshutils"
|
16
|
+
|
17
|
+
[tool.poetry.group.dev.dependencies]
|
18
|
+
basedpyright = "*"
|
19
|
+
ruff = "*"
|
20
|
+
ipykernel = "*"
|
21
|
+
ipywidgets = "*"
|
22
|
+
|
23
|
+
[build-system]
|
24
|
+
requires = ["poetry-core"]
|
25
|
+
build-backend = "poetry.core.masonry.api"
|
26
|
+
|
27
|
+
[tool.basedpyright]
|
28
|
+
typeCheckingMode = "standard"
|
29
|
+
deprecateTypingAliases = true
|
30
|
+
strictListInference = true
|
31
|
+
strictDictionaryInference = true
|
32
|
+
strictSetInference = true
|
33
|
+
reportPrivateImportUsage = false
|
34
|
+
|
35
|
+
[tool.ruff.lint]
|
36
|
+
select = ["FA102", "FA100"]
|
37
|
+
ignore = ["F722", "F821", "E731", "E741"]
|
38
|
+
|
39
|
+
[tool.ruff.lint.isort]
|
40
|
+
required-imports = ["from __future__ import annotations"]
|
@@ -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
|
@@ -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
|
-
|
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
|
@@ -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 =
|
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 =
|
85
|
-
treescope_autovisualize_arrays: bool =
|
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 =
|
108
|
-
treescope_autovisualize_arrays: bool =
|
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,
|
@@ -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
|
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
|
233
|
+
snoop = cast(Any, _snoop_cls)
|
@@ -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
|
-
|
93
|
-
frame = get_frame(1)
|
110
|
+
frame = sys._getframe(1)
|
94
111
|
assert frame is not None, "frame is None"
|
95
|
-
calling_module_name =
|
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.
|
nshutils-0.17.0/pyproject.toml
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
[tool.poetry]
|
2
|
-
name = "nshutils"
|
3
|
-
version = "0.17.0"
|
4
|
-
description = ""
|
5
|
-
authors = ["Nima Shoghi <nimashoghi@gmail.com>"]
|
6
|
-
readme = "README.md"
|
7
|
-
|
8
|
-
[tool.poetry.urls]
|
9
|
-
homepage = "https://github.com/nimashoghi/nshutils"
|
10
|
-
|
11
|
-
[tool.poetry.dependencies]
|
12
|
-
python = "^3.10"
|
13
|
-
numpy = "*"
|
14
|
-
jaxtyping = "*"
|
15
|
-
typing-extensions = "*"
|
16
|
-
beartype = "*"
|
17
|
-
uuid7 = "*"
|
18
|
-
treescope = { version = "*", optional = true }
|
19
|
-
lovely-numpy = { version = "*", optional = true }
|
20
|
-
lovely-tensors = { version = "*", optional = true }
|
21
|
-
pysnooper = { version = "*", optional = true }
|
22
|
-
rich = { version = "*", optional = true }
|
23
|
-
|
24
|
-
[tool.poetry.group.dev.dependencies]
|
25
|
-
pyright = "^1.1.373"
|
26
|
-
ruff = "^0.5.4"
|
27
|
-
ipykernel = "^6.29.5"
|
28
|
-
ipywidgets = "^8.1.3"
|
29
|
-
|
30
|
-
[build-system]
|
31
|
-
requires = ["poetry-core"]
|
32
|
-
build-backend = "poetry.core.masonry.api"
|
33
|
-
|
34
|
-
[tool.pyright]
|
35
|
-
typeCheckingMode = "standard"
|
36
|
-
deprecateTypingAliases = true
|
37
|
-
strictListInference = true
|
38
|
-
strictDictionaryInference = true
|
39
|
-
strictSetInference = true
|
40
|
-
reportPrivateImportUsage = false
|
41
|
-
|
42
|
-
[tool.ruff.lint]
|
43
|
-
ignore = ["F722", "F821", "E731", "E741"]
|
44
|
-
|
45
|
-
[tool.poetry.extras]
|
46
|
-
extra = ["pysnooper", "lovely-numpy", "lovely-tensors", "rich", "treescope"]
|
File without changes
|