-
-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple pipelining #3366
Comments
You realise, the Python part of your code is faulty to begin with, so it can't work in xonsh, right? Here is a correct Python version:
That being said, there is a real problem. The tutorial clearly states, that it should be possible to pipe into python mode:
But if one runs this in a recent version of xonsh, xonsh seems to wait for input until the cows come home. Even worse, we now have a process that is not stopped by Ctrl+C and idles in one thread at 100% CPU. |
@con-f-use: Works for me just fine on current master/HEAD. xonfig
|
This comment has been minimized.
This comment has been minimized.
Could you please checkout d782074 and try again? |
This comment has been minimized.
This comment has been minimized.
OK, thanks for testing. Could you please file a bug report against 5648b8d? Thank you! |
@laloch have you any comments about first message of this issue? |
@anki-code, as already pointed out by @con-f-use, both your shell code and Python are syntactically wrong. I'm afraid that it's not possible to enumerate lines of standard input on a single line and yield a string as an output at the same time. Let's first create simple helper function to enumerate the lines and apply arbitrary modifications on them: def filter_stdin(stdin, stdout, filter):
n = 0
# call `filter` function for each input line and print the result
for l in stdin.readlines():
n += 1
print(filter(l.rstrip(), n), file=stdout) Now we can use it in our shell code:
|
@laloch thank you for example! My question is about how to reduce the overhead (exclude function and "lambda a,i,o" in your example). Is there a way to create function
? If there is no way I suggest to make it because it looks very elegant and useful. In common case we just want to get stdin, split by lines and do something with lines. Let's just make it simple like it done in // Could you please hide con-f-use comments? It's confusing :) and about another issue. |
It's not really another issue, because if piping doesn't work at all, nothing you want can. I'd suggest you edit your opening post to make it clearer, what you are after and that there actually is a way to do it - just not a nice way - because your suggestion is actually a good idea. Also include a "skip ahead" link to a post where the non-confusing conversation starts. Btw. @con-f-use can hide his comments himself, so you don't have to talk over his head π On the subject, I agree that the
see https://github.com/xonsh/xonsh/blob/master/xonsh/parsers/base.py#L2988 |
@anki-code: if you don't want to fiddle with the parser code, you can achieve similar results using callable alias: def _stdfilter(args, stdin, stdout):
command_string = "lambda line,index:"
for arg in args:
command_string += arg + " "
fn = eval(command_string)
index = 0
for line in stdin.readlines():
index += 1
res = fn(line.rstrip(), index)
if res is not None:
print(res, file=stdout, flush=True)
aliases['stdfilter'] = _stdfilter
|
@laloch many thanks! The more simple version works for me like a charm: def _pl(args, stdin, stdout):
fn = eval('lambda line:'+args[0])
for line in stdin.readlines():
res = fn(line.rstrip(os.linesep))
print(res, file=stdout, flush=True)
aliases['pl'] = _pl
del _pl $ ls -1 / | pl "line+'!!!'" | head -n2
bin!!!
boot!!! |
You are welcome. This is indeed very useful. import os
res = fn(line.rstrip(os.linesep)) |
The It will be cool if there will be an ability to create macro like |
xontrib-pipeliner is here #3558 |
Hi! Thank you for great project!
π½ Start reading the thread from here β #3366 (comment)
π₯ Most closest solution here β #3366 (comment)
π₯ Xontrib: xontrib-pipeliner
The text was updated successfully, but these errors were encountered: