pipe-cleaner 0.1.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.
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: pipe-cleaner
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary:
|
|
5
|
+
Author: Maciej Katafiasz
|
|
6
|
+
Author-email: mathrick@disroot.org
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Requires-Dist: pipe (>=2.2,<3.0)
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
`pipe-cleaner` is a library of common, useful extensions to the [Pipe](https://pypi.org/project/pipe/) library.
|
|
19
|
+
|
|
20
|
+
Installation
|
|
21
|
+
============
|
|
22
|
+
|
|
23
|
+
`pipe-cleaner` is [available on PyPI](https://pypi.org/project/pipe-cleaner/). Use your favourite package manager:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
pip install pipe-cleaner
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
poetry add pipe-cleaner
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Usage
|
|
35
|
+
=====
|
|
36
|
+
|
|
37
|
+
_TBD_
|
|
38
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
`pipe-cleaner` is a library of common, useful extensions to the [Pipe](https://pypi.org/project/pipe/) library.
|
|
2
|
+
|
|
3
|
+
Installation
|
|
4
|
+
============
|
|
5
|
+
|
|
6
|
+
`pipe-cleaner` is [available on PyPI](https://pypi.org/project/pipe-cleaner/). Use your favourite package manager:
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
pip install pipe-cleaner
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
poetry add pipe-cleaner
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Usage
|
|
18
|
+
=====
|
|
19
|
+
|
|
20
|
+
_TBD_
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pipe-cleaner"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = ""
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "Maciej Katafiasz", email = "mathrick@disroot.org"}
|
|
7
|
+
]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.8"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"pipe (>=2.2,<3.0)"
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[tool.poetry]
|
|
15
|
+
packages = [{include = "pipe_cleaner", from = "src"}]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
[build-system]
|
|
19
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
20
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Pipe debuging utilities"""
|
|
2
|
+
|
|
3
|
+
from pipe import Pipe, batched, islice
|
|
4
|
+
|
|
5
|
+
__all__ = ["debug_eager"]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
("Hello world!"
|
|
9
|
+
| as_list()
|
|
10
|
+
| take_while(lambda x: x != " ")
|
|
11
|
+
| debug_eager("Characters:")
|
|
12
|
+
| map(ord)
|
|
13
|
+
| debug_eager("Codepoints:")
|
|
14
|
+
| as_list())
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@Pipe
|
|
18
|
+
def debug_eager(iterable, label: str | None = None, max_count: int = 100):
|
|
19
|
+
"""
|
|
20
|
+
Debugging helper. Prints label if given, then eagerly fetches items from iterable,
|
|
21
|
+
prints them, then passes them on. This is similar to tee(), but tee() is
|
|
22
|
+
completely lazy, and will print items one-by-one, whereas this function will
|
|
23
|
+
|
|
24
|
+
For safety, only up to max_count items will be printed, to avoid infinite loops.
|
|
25
|
+
|
|
26
|
+
Note that although this function is eager once it starts fetching the items, it's
|
|
27
|
+
still a generator and thus won't actually do anything until something starts to
|
|
28
|
+
iterate the pipeline (e.g. as_list()).
|
|
29
|
+
|
|
30
|
+
Useful for figuring out why the pipeline doesn't produce all the expected elements,
|
|
31
|
+
for example with take_while().
|
|
32
|
+
|
|
33
|
+
>>> ("Hello world!"
|
|
34
|
+
... | as_list()
|
|
35
|
+
... | take_while(lambda x: x != " ")
|
|
36
|
+
... | debug_eager("Characters:")
|
|
37
|
+
... | map(ord)
|
|
38
|
+
... | debug_eager("Codepoints:")
|
|
39
|
+
... | as_list())
|
|
40
|
+
Characters:
|
|
41
|
+
H
|
|
42
|
+
e
|
|
43
|
+
l
|
|
44
|
+
l
|
|
45
|
+
o
|
|
46
|
+
Codepoints:
|
|
47
|
+
72
|
|
48
|
+
101
|
|
49
|
+
108
|
|
50
|
+
108
|
|
51
|
+
111
|
|
52
|
+
[72, 101, 108, 108, 111]
|
|
53
|
+
"""
|
|
54
|
+
iterable = iter(iterable)
|
|
55
|
+
items = list(iterable | islice(None, max_count))
|
|
56
|
+
if label is not None:
|
|
57
|
+
print(label)
|
|
58
|
+
for item in items:
|
|
59
|
+
print(item)
|
|
60
|
+
yield from items
|
|
61
|
+
yield from iterable
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Simple wrappers around existing functions
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from functools import reduce
|
|
6
|
+
|
|
7
|
+
from pipe import Pipe
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"as_list",
|
|
11
|
+
"as_dict",
|
|
12
|
+
"as_tuple",
|
|
13
|
+
"as_sum",
|
|
14
|
+
"join",
|
|
15
|
+
"reduce",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def as_list() -> Pipe:
|
|
20
|
+
"""Convert pipe's iterable to list. Simple shorthand for Pipe(list)"""
|
|
21
|
+
return Pipe(list)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def as_dict() -> Pipe:
|
|
25
|
+
"""Convert pipe's iterable to dict. Simple shorthand for Pipe(dict)"""
|
|
26
|
+
return Pipe(dict)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def as_tuple() -> Pipe:
|
|
30
|
+
"""Convert pipe's iterable to tuple. Simple shorthand for Pipe(tuple)"""
|
|
31
|
+
return Pipe(tuple)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@Pipe
|
|
35
|
+
def as_sum(iterable, /, start=0):
|
|
36
|
+
"""
|
|
37
|
+
Return sum of the pipe's iterable. Wraps builtin sum() as a Pipe, same as add()
|
|
38
|
+
from Pipe 1.x
|
|
39
|
+
"""
|
|
40
|
+
return sum(iterable, start=start)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def join(sep: str):
|
|
44
|
+
"""
|
|
45
|
+
Join the iterable into a string with sep. Wraps sep.join as a Pipe
|
|
46
|
+
"""
|
|
47
|
+
return Pipe(sep.join)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@Pipe
|
|
51
|
+
def reduce(iterable, function, *args, **kwargs):
|
|
52
|
+
"""
|
|
53
|
+
Reduce the pipe's iterable with function. Wraps functools.reduce() as a Pipe
|
|
54
|
+
"""
|
|
55
|
+
return reduce(function, iterable, *args, **kwargs)
|