laser-prynter 0.2.5__tar.gz → 0.2.7__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.
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/PKG-INFO +3 -4
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/laser_prynter/pp.py +31 -13
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/laser_prynter.egg-info/PKG-INFO +3 -4
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/laser_prynter.egg-info/SOURCES.txt +0 -1
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/pyproject.toml +4 -6
- laser_prynter-0.2.5/laser_prynter.egg-info/requires.txt +0 -1
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/LICENSE +0 -0
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/README.md +0 -0
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/laser_prynter/__init__.py +0 -0
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/laser_prynter/bench.py +0 -0
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/laser_prynter/colour/__init__.py +0 -0
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/laser_prynter/colour/c.py +0 -0
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/laser_prynter/colour/gradient.py +0 -0
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/laser_prynter/log.py +0 -0
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/laser_prynter.egg-info/dependency_links.txt +0 -0
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/laser_prynter.egg-info/top_level.txt +0 -0
- {laser_prynter-0.2.5 → laser_prynter-0.2.7}/setup.cfg +0 -0
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: laser-prynter
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: terminal/cli/python helpers for colour and pretty-printing
|
|
5
5
|
Author-email: tmck-code <tmck01@gmail.com>
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
6
7
|
Project-URL: Homepage, https://github.com/tmck-code/laser-prynter
|
|
7
8
|
Project-URL: Issues, https://github.com/tmck-code/laser-prynter/issues
|
|
8
9
|
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.12
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
-
Requires-Dist: pygments>=2.19.2
|
|
15
14
|
Dynamic: license-file
|
|
16
15
|
|
|
17
16
|
# laser-prynter
|
|
@@ -13,13 +13,28 @@ STYLES = (
|
|
|
13
13
|
'dracula', 'fruity', 'gruvbox-dark', 'gruvbox-light', 'lightbulb', 'material', 'native',
|
|
14
14
|
'one-dark', 'perldoc', 'tango',
|
|
15
15
|
)
|
|
16
|
+
# disable printing by setting `pp.enabled = False`
|
|
17
|
+
enabled = True
|
|
18
|
+
|
|
19
|
+
def _print(s: str, **kwargs) -> None:
|
|
20
|
+
if enabled:
|
|
21
|
+
print(s, **kwargs)
|
|
16
22
|
|
|
17
23
|
def _isnamedtuple(obj: object):
|
|
18
24
|
return isinstance(obj, tuple) and hasattr(obj, '_fields')
|
|
19
25
|
|
|
26
|
+
def _normalise_keys(d: dict):
|
|
27
|
+
'norlimalise dict keys for JSON by stringifying'
|
|
28
|
+
for k,v in d.items():
|
|
29
|
+
if not isinstance(k, str):
|
|
30
|
+
yield str(k), _normalise(v)
|
|
31
|
+
else:
|
|
32
|
+
yield k, _normalise(v)
|
|
33
|
+
|
|
20
34
|
def _normalise(obj: object):
|
|
21
35
|
'step through obj and normalise namedtuples to dicts'
|
|
22
|
-
if isinstance(obj, dict):
|
|
36
|
+
if isinstance(obj, dict):
|
|
37
|
+
return dict(_normalise_keys(obj))
|
|
23
38
|
if isinstance(obj, list): return [_normalise(i) for i in obj]
|
|
24
39
|
if _isnamedtuple(obj): return obj._asdict()
|
|
25
40
|
return obj
|
|
@@ -36,7 +51,7 @@ def _json_default(obj: object):
|
|
|
36
51
|
elif hasattr(obj, '__dict__'): return obj.__dict__ # class
|
|
37
52
|
return str(obj)
|
|
38
53
|
|
|
39
|
-
def ppd(d_obj, indent=2, style='dracula', random_style=False):
|
|
54
|
+
def ppd(d_obj, indent=2, style='dracula', random_style: bool=False, **kwargs):
|
|
40
55
|
'pretty-print a dict'
|
|
41
56
|
d = _normalise(d_obj) # convert any namedtuples to dicts
|
|
42
57
|
|
|
@@ -45,17 +60,20 @@ def ppd(d_obj, indent=2, style='dracula', random_style=False):
|
|
|
45
60
|
code = json.dumps(d, indent=indent, default=_json_default)
|
|
46
61
|
|
|
47
62
|
if style is None:
|
|
48
|
-
|
|
63
|
+
_print(code, **kwargs)
|
|
49
64
|
else:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
_print(
|
|
66
|
+
highlight(
|
|
67
|
+
code = code,
|
|
68
|
+
lexer = JsonLexer(),
|
|
69
|
+
formatter = Terminal256Formatter(style=get_style_by_name(style))
|
|
70
|
+
).strip(),
|
|
71
|
+
**kwargs,
|
|
72
|
+
)
|
|
55
73
|
|
|
56
|
-
def ppj(j: str, indent: int=None, style: str='dracula', random_style: bool=False) -> None:
|
|
74
|
+
def ppj(j: str, indent: int=None, style: str='dracula', random_style: bool=False, **kwargs) -> None:
|
|
57
75
|
'pretty-print a JSON string'
|
|
58
|
-
ppd(json.loads(j), indent=indent, style=style, random_style=random_style)
|
|
76
|
+
ppd(_normalise(json.loads(j)), indent=indent, style=style, random_style=random_style)
|
|
59
77
|
|
|
60
78
|
def ps(s: str, style: str='yellow', random_style: bool=False) -> str:
|
|
61
79
|
'add color to a string'
|
|
@@ -65,11 +83,11 @@ def ps(s: str, style: str='yellow', random_style: bool=False) -> str:
|
|
|
65
83
|
|
|
66
84
|
def pps(s: str, style: str='yellow', random_style: bool=False) -> None:
|
|
67
85
|
'pretty-print a string'
|
|
68
|
-
|
|
86
|
+
_print(ps(s, style=style, random_style=random_style))
|
|
69
87
|
|
|
70
|
-
def demo() -> None:
|
|
88
|
+
def demo(**kwargs) -> None:
|
|
71
89
|
'demonstrate pretty-printing colours'
|
|
72
90
|
|
|
73
91
|
for s in STYLES:
|
|
74
|
-
ppd({'message': {'Hello': 'World', 'The answer is': 42}, 'style': s}, style=s, indent=None)
|
|
92
|
+
ppd({'message': {'Hello': 'World', 'The answer is': 42}, 'style': s}, style=s, indent=None, **kwargs)
|
|
75
93
|
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: laser-prynter
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: terminal/cli/python helpers for colour and pretty-printing
|
|
5
5
|
Author-email: tmck-code <tmck01@gmail.com>
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
6
7
|
Project-URL: Homepage, https://github.com/tmck-code/laser-prynter
|
|
7
8
|
Project-URL: Issues, https://github.com/tmck-code/laser-prynter/issues
|
|
8
9
|
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.12
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
-
Requires-Dist: pygments>=2.19.2
|
|
15
14
|
Dynamic: license-file
|
|
16
15
|
|
|
17
16
|
# laser-prynter
|
|
@@ -8,7 +8,6 @@ laser_prynter/pp.py
|
|
|
8
8
|
laser_prynter.egg-info/PKG-INFO
|
|
9
9
|
laser_prynter.egg-info/SOURCES.txt
|
|
10
10
|
laser_prynter.egg-info/dependency_links.txt
|
|
11
|
-
laser_prynter.egg-info/requires.txt
|
|
12
11
|
laser_prynter.egg-info/top_level.txt
|
|
13
12
|
laser_prynter/colour/__init__.py
|
|
14
13
|
laser_prynter/colour/c.py
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "laser-prynter"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.7"
|
|
4
4
|
authors = [
|
|
5
5
|
{ name="tmck-code", email="tmck01@gmail.com" },
|
|
6
6
|
]
|
|
7
7
|
description = "terminal/cli/python helpers for colour and pretty-printing"
|
|
8
8
|
readme = "README.md"
|
|
9
|
-
|
|
9
|
+
license = "BSD-3-Clause"
|
|
10
|
+
license-files = ["LICENSE"]
|
|
11
|
+
requires-python = ">=3.12"
|
|
10
12
|
classifiers = [
|
|
11
13
|
"Programming Language :: Python :: 3",
|
|
12
|
-
"License :: OSI Approved :: MIT License",
|
|
13
14
|
"Operating System :: OS Independent",
|
|
14
15
|
]
|
|
15
|
-
dependencies = [
|
|
16
|
-
"pygments>=2.19.2",
|
|
17
|
-
]
|
|
18
16
|
|
|
19
17
|
[project.urls]
|
|
20
18
|
Homepage = "https://github.com/tmck-code/laser-prynter"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pygments>=2.19.2
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|