nf-core / tools

Python package with helper tools for the nf-core community.
https://nf-co.re
MIT License
232 stars 187 forks source link

Offer of help #682

Closed willmcgugan closed 3 years ago

willmcgugan commented 4 years ago

Not an issue per se. I noticed you guys are using Rich to do some interesting stuff. I'm the author or Rich, and I just wanted to say feel free to mention me if you ever need any assistance with it.

ewels commented 4 years ago

Brilliant - thank you very much @willmcgugan, much appreciated!

I've been really enjoying myself over the past few days playing with Rich. We're doing a week long hackathon for @nf-core (see https://nf-co.re/events/2020/hackathon-july-2020) so I've been on a mission to start using Rich throughout the code base since I found out about it! It's a beautiful library - both in terms of code and output 🤩

We only have a couple of instances of click.style left, that we were previously using for coloured output. They are all within click.confirm functions, eg: https://github.com/nf-core/tools/blob/bf950c96101b59e14afe9820e79c65478e5677c2/nf_core/launch.py#L117-L121

I saw that Rich has an input method which I want to have a play with soon. I was curious to know if there is a way to handle confirmation prompts with Rich as well? I didn't post an issue yet as I haven't really looked around or tried anything yet, but as you're here maybe you have a suggestion.. 😄

willmcgugan commented 4 years ago

I've been really enjoying myself over the past few days playing with Rich. We're doing a week long hackathon for @nf-core (see https://nf-co.re/events/2020/hackathon-july-2020) so I've been on a mission to start using Rich throughout the code base since I found out about it! It's a beautiful library - both in terms of code and output 🤩

Glad its working for you! The hackathon explains why you've been so busy.

I think click.prompt does a little more processing of the return value, whereas Console.input just returns a string. I'll think about adding that at some point, in the meantime something like this should work:

if console.input("[yellow]Do you want to overwrite this file?[/] [red][[y/N]]").lower() == "y":
    overwrite() 
ewels commented 4 years ago

Sounds like solid advice, thanks 👍🏻

Is the [/] needed in your above example? I wasn't sure whether to put those in or not when using multiple colours in a string.

willmcgugan commented 4 years ago

For this example, you don't strictly need the closing tag. Since the red foreground replaces the yellow foreground. But other styles can overlap. For instance if the first part of the the text was "bold yellow" you might need to close it, or the [y/N] would also be bold.

willmcgugan commented 4 years ago

You might want to try out the prompt branch which has a new rich.prompt module.

No docs as yet, but see prompt.py for examples.

I'll release this in a day or two when I've got docs. Let me know if you have any feedback.

ewels commented 4 years ago

Amazing! Thank you - I'll give it a try asap.

ewels commented 4 years ago

Ok, now I'm going to get really cheeky whilst I have your ear. Feel free to tell me that this is way out of scope and I'll move on 😅

We have a new command-line wizard feature which I wrote using the PyInquirer package. It generally works well (see a demo on YouTube from last week), but PyInquirer seems to have some problems with package management and I need to strip it out (https://github.com/nf-core/tools/issues/641).

I'm currently working on alternatives now, such as the much simpler pick for select lists. Any thoughts whether Rich could support any functionality like this? We actually looked for and found Rich in the first place to render the markdown help above these questions. It would be super cool if we could just render the whole console interface through Rich...

willmcgugan commented 4 years ago

TBH I've been thinking about this for a while. I've seen pyInquirer and similar console packages in other languages, and I would love to implement something similar using Rich to do the rendering.

If it happens, it would probably be an external package, perhaps "rich-interactive", to keep dependancies down for those who don't need it.

Reason it might not happen is my wife says I spend too much time working and not getting paid for it, and she's right. It would be easier to justify if I get Github sponsorship.

ewels commented 4 years ago

That would be awesome! I've just pinned PyInquirer with a couple of workarounds which should keep things ticking for a bit, but if a Rich package ever turns up I'd love to give it a go (we don't use 90% of the PyInquirer features).

Reason it might not happen is my wife says I spend too much time working and not getting paid for it, and she's right. It would be easier to justify if I get GitHub sponsorship.

A very valid reason! I totally understand. I struggle with this a bit as we are primarily academic and government / grant funded (so a lot of bureaucracy) and also open source / largely volunteer driven. I'll have a think about whether we can compile a list of "upstream developers" or something though, to present to people using our tools. Probably won't amount to much but can't hurt.. 🤔 Made an issue: https://github.com/nf-core/nf-co.re/issues/448

willmcgugan commented 4 years ago

I've pushed Rich 3.4.0, with rich.prompt.