robinhilliard / pipes Goto Github PK
View Code? Open in Web Editor NEWElixir–style pipes for Python
Home Page: https://pypi.org/project/pipeop/
License: MIT License
Elixir–style pipes for Python
Home Page: https://pypi.org/project/pipeop/
License: MIT License
Hello Robin,
Thank you so much for this project. I have long felt that Python could benefit from a pipe operator, and to see it actually be implemented is just awesome. I was so pleased with it that I decided to fork your project and take it to its logical extent (arguably, I took it too far). In my fork, which I'm calling Superpipe, each segment of the pipe is much more generalized. You can insert the piped value into any position of a function call, construct new collections on-the-fly, and even call methods on the piped value.
Some examples:
[2, 3] >> [1, *_, 4, 5] >> f"list: {_}" >> print
5 >> _ + 99 >> [_+1, 3] >> sum >> _.bit_length() >> print("Bit length:", _)
I had initially intended to open a pull request here, however as I kept adding more and more to it I began to feel like I had diverged too much from the original vision, and so am deciding to keep my fork independent.
This is the first time I've forked a public project like this, and I want to ensure that I'm respecting your license and you properly.
I am keeping the fork MIT-licensed, so I think I should be in the clear there, however I also intend to upload the fork as a new package on PyPi. I think this should be okay? The only question then left is how do I appropriately credit you. The Github repository correctly attributes you as the author of the fork, and I will include an additional link in the readme, however I am uncertain what to do with regards to authors of the PyPi package: Should I insert my name and email beside yours, or list myself as the sole author?
Thanks
P.S.
Here is a link to the fork: https://github.com/George-lewis/superpipe
The readme is still in the process of being rewritten, however I believe the tests may be of interest
It'd be great if you could apply the @pipes
transformation at the level of the class/module instead of having to annotate each function within.
Hey! Just tried to install the package from pip, and it's failing with:
src/Bot-new mainline pip3 install pipeop
Collecting pipeop
Downloading https://files.pythonhosted.org/packages/f3/71/5449fe7a4ca9ecef67bca9ceb13a163d7326fc0c325b6642694e7da5c0fc/pipeop-0.2.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/bw/539xc4113rd4lcc56p27lq1jghmd7n/T/pip-install-ujbf0qn9/pipeop/setup.py", line 5, in <module>
with open('README.rst', 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'README.rst'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/bw/539xc4113rd4lcc56p27lq1jghmd7n/T/pip-install-ujbf0qn9/pipeop/
Hey, thank you for creating this, just what I'm looking for 😃
It'd be great if you could add Python3 support!
Currently, if I try to use it in Python3, I'm getting the following error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-6-28ed7b59ff38> in <module>()
5 return a * b
6
----> 7 @pipes
8 def calc():
9 print(1 >> add(2) >> times(3)) # prints 9
/usr/local/anaconda3/lib/python3.6/site-packages/pipeop/__init__.py in pipes(func)
17 def pipes(func):
18 # name of our replacement function
---> 19 pipe_func_name = '__pipes_{}'.format(func.func_code.co_name)
20
21 # variable context where decorator added
AttributeError: 'function' object has no attribute 'func_code'
It appears that functions cannot be included conditionally in a series of pipes. For instance:
def noop(arg):
return arg
def sum(a, b):
return a + b
@pipes
def main():
print(
5
>> sum(2)
>> (sum(sys.argv[1]) if len(sys.argv) > 1 else noop)
)
Produces:
TypeError: sum() missing 1 required positional argument: 'b'
This would be a nice feature to have when constructing a complex pipeline which requires some sort of conditional logic.
Thank you so much for this brilliant little thing. I've just copy&pasted your main code as a tooling decorator into https://github.com/amogorkon/justuse and it does its job without complaining even once.
For example
ordered = releases >> _filter_by_platform(tags=get_supported()) >> _sort_releases
last_version = project.releases >> reversed >> iter >> next
meta = (names
<< filter(DIST_PKG_INFO_REGEX.search)
<< map(functions.read_entry)
>> dict
)
Pipes make this so much nicer and less cluttered. Readability counts! I hope you will continue maintaining this beautiful thing and maybe even make a PEP for inclusion into the core language 👍
This probably is also the only way to fix a little issue that happens when you write a small chain of pipes like
a = (foo
>> bar
<< baz
)
which would look ugly on a single line a = foo >> bar << baz
with those arrows piping in different directions - alas, black thinks so otherwise, so it turns the multi-line pipe into a single line.
PS: You really should update your examples on your README to python 3 print-as-a-function ;-)
def calc():
print 1 >> add(2) >> times(3) # prints 9
should be
def calc():
1 >> add(2) >> times(3) >> print # prints 9
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.