Skip to content

Commit 1299803

Browse files
committed
revert setuptools backend & cleanup
1 parent e89994b commit 1299803

File tree

5 files changed

+24
-34
lines changed

5 files changed

+24
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ pip-log.txt
2020
.mypy_cache/
2121
.venv/
2222
.envrc
23+
.build

README.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -533,60 +533,47 @@ optional arguments after:
533533
>>>
534534
```
535535

536-
### Organizing using class
536+
### Organizing pipes more effectively using classes
537537

538-
You can also organize pipes using classes as shown below:
538+
The `@Pipe` decorator isn't just for functions-it also works with classes. You can use it with instance methods, class methods, and static methods to better structure your code while keeping it pipeable.
539539

540-
1. As a `method` method
540+
1. Using an Instance Method
541541

542542
```python
543543
>>> class Factor:
544-
... n: int = 10
545-
...
546544
... def __init__(self, n: int):
547545
... self.n = n
548-
...
549546
... @Pipe
550547
... def mul(self, iterable):
551548
... return (x * self.n for x in iterable)
552-
...
553549
>>> fact = Factor(10)
554550
>>> list([1, 2, 3] | fact.mul)
555551
[10, 20, 30]
556552
>>>
557553
```
558554

559-
1. As a `classmethod`
555+
2. Using a Class Method
560556

561557
```python
562558
>>> class Factor:
563559
... n: int = 10
564-
...
565-
... def __init__(self, n: int):
566-
... self.n = n
567-
...
568560
... @Pipe
569561
... @classmethod
570562
... def mul(cls, iterable):
571563
... return (x * cls.n for x in iterable)
572-
...
573564
>>> list([1, 2, 3] | Factor.mul)
574565
[10, 20, 30]
575566
>>>
576567
```
577568

578-
Supported on classmethod like functions
569+
3. Using a Static Method
579570

580-
```py
571+
```python
581572
>>> class Factor:
582-
... def __init__(self, n: int):
583-
... self.n = n
584-
...
585573
... @Pipe
586574
... @staticmethod
587575
... def mul(iterable):
588576
... return (x * 10 for x in iterable)
589-
...
590577
>>> list([1, 2, 3] | Factor.mul)
591578
[10, 20, 30]
592579
>>>

pipe.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def __init__(self, function, *args, **kwargs):
4747
self.args = args
4848
self.kwargs = kwargs
4949
self.function = function
50-
self.instance = None
5150
functools.update_wrapper(self, function)
5251

5352
def __ror__(self, other):
@@ -88,7 +87,7 @@ def __get__(self, instance, owner=None):
8887
return Pipe(
8988
function=self.function.__get__(instance, owner),
9089
*self.args,
91-
*self.kwargs,
90+
**self.kwargs,
9291
)
9392

9493

pyproject.toml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
2-
requires = ["hatchling"]
3-
build-backend = "hatchling.build"
2+
requires = ["setuptools", "wheel"]
3+
build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pipe"
@@ -36,17 +36,10 @@ coverage = ["coverage[toml]", "covdefaults"]
3636
dev = [{ include-group = "ruff" }, "pre-commit>=2.21.0", "tox>=4.23.2"]
3737
test = [{ include-group = "coverage" }, "mock", "pytest", "pytest-cov"]
3838

39-
[tool.hatch.metadata]
40-
allow-direct-references = true
41-
42-
[tool.hatch.version]
43-
path = "pipe.py"
44-
45-
[tool.hatch.build.targets.sdist]
46-
include = ["pipe.py"]
47-
48-
[tool.hatch.build.targets.wheel]
49-
include = ["pipe.py"]
39+
[tool.setuptools]
40+
py-modules = ["pipe"]
41+
include-package-data = false
42+
dynamic.version.attr = "pipe.__version__"
5043

5144
[tool.ruff]
5245
lint.pydocstyle.convention = "numpy"

tests/test_pipe.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ def mul(self, iterable):
5252
assert list([1, 2, 3] | Factory().mul) == [10, 20, 30]
5353

5454

55+
def test_class_support_with_named_parameter():
56+
class Factory:
57+
@pipe.Pipe
58+
@staticmethod
59+
def mul(iterable, factor=None):
60+
return (x * factor for x in iterable)
61+
62+
assert list([1, 2, 3] | Factory.mul(factor=5)) == [5, 10, 15]
63+
64+
5565
def test_pipe_repr():
5666
@pipe.Pipe
5767
def sample_pipe(iterable):

0 commit comments

Comments
 (0)