Skip to content
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

Pipe mode, line-by-line (stdin/stdout) #390

Open
rkdarst opened this issue Feb 8, 2024 · 0 comments
Open

Pipe mode, line-by-line (stdin/stdout) #390

rkdarst opened this issue Feb 8, 2024 · 0 comments

Comments

@rkdarst
Copy link

rkdarst commented Feb 8, 2024

I recently had to make a "pipe mode" for Argos, which can read lines from stdin and translate each line separately, as soon as a \n is received. (This is since I couldn't install argos in the virtualenvironment I had other software in, which would have let me directly call it from Python. I have too many requests to make it worth re-starting Python for each query). Is this something you'd be interested in as a pull request? I guess I'd add a --pipe option to the existing argos-translate and try to reuse the existing other options for configuration. Or I could make piping the default if no argument is given.

Thanks for Argos! It has been very useful.

Below is the synopsis of my current frontent and what I would implement:

while True:
    # walrus operator would be appropriate but 3.8 still too new for my tastes                       
    line = sysstdin.readline()
    if not line:
        break

    if args.format == 'json':
        line = json.loads(line)

    new = argostranslate.translate.translate(
        line, sys.argv[1], sys.argv[2])

    if args.format == 'json':
        print(json.dumps(new))
        sys.stdout.flush()
    else:
        print(new)
@rkdarst rkdarst changed the title Pipe mode (stdin/stdout) Pipe mode, line-by-line (stdin/stdout) Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant