nshutils 0.15.0__tar.gz → 0.17.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.15.0 → nshutils-0.17.0}/PKG-INFO +1 -1
- {nshutils-0.15.0 → nshutils-0.17.0}/pyproject.toml +1 -1
- {nshutils-0.15.0 → nshutils-0.17.0}/src/nshutils/__init__.py +4 -0
- nshutils-0.17.0/src/nshutils/_display.py +60 -0
- {nshutils-0.15.0 → nshutils-0.17.0}/src/nshutils/logging.py +5 -5
- {nshutils-0.15.0 → nshutils-0.17.0}/README.md +0 -0
- {nshutils-0.15.0 → nshutils-0.17.0}/src/nshutils/actsave/__init__.py +0 -0
- {nshutils-0.15.0 → nshutils-0.17.0}/src/nshutils/actsave/_loader.py +0 -0
- {nshutils-0.15.0 → nshutils-0.17.0}/src/nshutils/actsave/_saver.py +0 -0
- {nshutils-0.15.0 → nshutils-0.17.0}/src/nshutils/collections.py +0 -0
- {nshutils-0.15.0 → nshutils-0.17.0}/src/nshutils/snoop.py +0 -0
- {nshutils-0.15.0 → nshutils-0.17.0}/src/nshutils/typecheck.py +0 -0
@@ -1,8 +1,12 @@
|
|
1
1
|
from . import actsave as actsave
|
2
2
|
from . import typecheck as typecheck
|
3
|
+
from ._display import display as display
|
3
4
|
from .actsave import ActLoad as ActLoad
|
4
5
|
from .actsave import ActSave as ActSave
|
5
6
|
from .logging import init_python_logging as init_python_logging
|
6
7
|
from .logging import lovely as lovely
|
7
8
|
from .logging import pretty as pretty
|
8
9
|
from .snoop import snoop as snoop
|
10
|
+
from .typecheck import tassert as tassert
|
11
|
+
from .typecheck import typecheck_modules as typecheck_modules
|
12
|
+
from .typecheck import typecheck_this_module as typecheck_this_module
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import importlib.util
|
2
|
+
from functools import cache
|
3
|
+
from typing import Any
|
4
|
+
|
5
|
+
|
6
|
+
@cache
|
7
|
+
def _in_ipython():
|
8
|
+
try:
|
9
|
+
from IPython import get_ipython
|
10
|
+
|
11
|
+
return get_ipython() is not None
|
12
|
+
except ImportError:
|
13
|
+
return False
|
14
|
+
|
15
|
+
|
16
|
+
@cache
|
17
|
+
def _treescope_installed():
|
18
|
+
return importlib.util.find_spec("treescope") is not None
|
19
|
+
|
20
|
+
|
21
|
+
@cache
|
22
|
+
def _rich_installed():
|
23
|
+
return importlib.util.find_spec("rich") is not None
|
24
|
+
|
25
|
+
|
26
|
+
def display(*args: Any):
|
27
|
+
"""
|
28
|
+
Display the given arguments in the current environment.
|
29
|
+
|
30
|
+
If executed in an IPython environment, the display will be handled
|
31
|
+
by treescope if installed, or rich if available. If neither are
|
32
|
+
installed, it will fall back to IPython's display function. In a
|
33
|
+
non-IPython environment, rich will be used if available, otherwise
|
34
|
+
the standard print function will be used.
|
35
|
+
|
36
|
+
Args:
|
37
|
+
*args: Any objects to display.
|
38
|
+
"""
|
39
|
+
if _in_ipython():
|
40
|
+
if _treescope_installed():
|
41
|
+
import treescope
|
42
|
+
|
43
|
+
with treescope.active_autovisualizer.set_scoped(
|
44
|
+
treescope.ArrayAutovisualizer()
|
45
|
+
):
|
46
|
+
treescope.display(*args)
|
47
|
+
elif _rich_installed():
|
48
|
+
import rich
|
49
|
+
|
50
|
+
rich.print(*args)
|
51
|
+
else:
|
52
|
+
from IPython.display import display
|
53
|
+
|
54
|
+
display(*args)
|
55
|
+
elif _rich_installed():
|
56
|
+
import rich
|
57
|
+
|
58
|
+
rich.print(*args)
|
59
|
+
else:
|
60
|
+
print(*args)
|
@@ -19,7 +19,7 @@ def init_python_logging(
|
|
19
19
|
|
20
20
|
_lovely_tensors.monkey_patch()
|
21
21
|
except ImportError:
|
22
|
-
logging.
|
22
|
+
logging.info(
|
23
23
|
"Failed to import `lovely_tensors`. Ignoring pretty PyTorch tensor formatting"
|
24
24
|
)
|
25
25
|
|
@@ -29,7 +29,7 @@ def init_python_logging(
|
|
29
29
|
|
30
30
|
_lovely_numpy.set_config(repr=_lovely_numpy.lovely)
|
31
31
|
except ImportError:
|
32
|
-
logging.
|
32
|
+
logging.info(
|
33
33
|
"Failed to import `lovely_numpy`. Ignoring pretty numpy array formatting"
|
34
34
|
)
|
35
35
|
|
@@ -45,11 +45,11 @@ def init_python_logging(
|
|
45
45
|
autovisualize_arrays=treescope_autovisualize_arrays
|
46
46
|
)
|
47
47
|
else:
|
48
|
-
logging.
|
48
|
+
logging.info(
|
49
49
|
"Treescope setup is only supported in Jupyter notebooks. Skipping."
|
50
50
|
)
|
51
51
|
except ImportError:
|
52
|
-
logging.
|
52
|
+
logging.info(
|
53
53
|
"Failed to import `treescope` or `IPython`. Ignoring `treescope` registration"
|
54
54
|
)
|
55
55
|
|
@@ -65,7 +65,7 @@ def init_python_logging(
|
|
65
65
|
|
66
66
|
log_handlers.append(RichHandler(rich_tracebacks=rich_tracebacks))
|
67
67
|
except ImportError:
|
68
|
-
logging.
|
68
|
+
logging.info(
|
69
69
|
"Failed to import rich. Falling back to default Python logging."
|
70
70
|
)
|
71
71
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|