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

Example code in readme does not work with latest PyPI percol 0.2.1 #108

Open
hartwork opened this issue Jul 21, 2020 · 4 comments
Open

Example code in readme does not work with latest PyPI percol 0.2.1 #108

hartwork opened this issue Jul 21, 2020 · 4 comments

Comments

@hartwork
Copy link

hartwork commented Jul 21, 2020

Hi!

I would like to vote for for a new release. The readme changes merged from 4b28037 are not supported: Once I fix the sting IO import for Python 3 (#107) I get ImportError: cannot import name 'no_output' from 'percol.actions' for a good reason: It does not exist in release 0.2.1. Can we have a new release please please?

If anyone needs a version of the example that works with Python 3.7:

from io import StringIO
from percol import Percol
from percol.actions import action

@action()
def no_output(lines, percol):
    "ignore all output"
    pass

def main(candidates):
    si, so, se = StringIO(), StringIO(), StringIO()
    with Percol(
            actions=[no_output],
            descriptors={'stdin': si, 'stdout': so, 'stderr': se},
            candidates=iter(candidates)) as p:
        p.loop()
    if p.args_for_action is None:
        raise KeyboardInterrupt
    results = p.model_candidate.get_selected_results_with_index()
    return [r[0] for r in results]

if __name__ == "__main__":
    candidates = ['foo', 'bar', 'baz']
    results = main(candidates)
    print("You picked: {!r}".format(results))

Best, Sebastian

@clach04
Copy link

clach04 commented Sep 1, 2024

@hartwork I just tried this against https://pypi.org/project/percolator - does this do what you want?

It seems to work.

@hartwork
Copy link
Author

hartwork commented Sep 1, 2024

Hi @clach04, so you forked percol as percolator on PyPI now, I see. My fixed example above does seem to work with percolator out of the box, but percolator's readme still reads from cStringIO import StringIO which does not support Python 3.

@clach04
Copy link

clach04 commented Sep 2, 2024

Thanks for checking @hartwork , I thought I had fixed that a few days ago. I'm guessing I'm missing another location. I fixed/updated https://github.com/clach04/percolator/tree/mymain?tab=readme-ov-file#calling-percol-from-python can you point me at the place(s) I missed?

Thanks again!

@hartwork
Copy link
Author

hartwork commented Sep 2, 2024

@clach04 my bad, I think I mixed something up, nevermind.

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

2 participants