News for hackers. Stuff that matters.
Re:Gooey: Turn almost any Python command line program into a... by frederikvs on Monday June 14, 2021 @05:44AM (#27500833)
Gooey is a brilliant bit of software.

We use it in combination with Python Fire [0] to easily convert python code to something that users can interact with. Python fire converts our python code into a CLI without all the manual parameter parsing, and Gooey turns the CLI into a simple GUI.

[0] https://github.com/google/python-fire

Re:Gooey: Turn almost any Python command line program into a... by sireat on Monday June 14, 2021 @06:40AM (#27501102)
Brilliant workflow!

Today I learned about Fire AND Gooey

Sometimes I get bogged down in writing proper argparse when it really is not needed.

Are there any edge cases where Fire does not work too well, like some strange parameters (for example tuple as dictionary key)?

Re:Gooey: Turn almost any Python command line program into a... by roganartu on Monday June 14, 2021 @09:15AM (#27502122)
If you like the look of fire for the ease of creating a cli but wish it automatically did validation based on type annotations, you might like Typer[0]. The pathlib parameters are especially handy, I find.

[0] https://github.com/tiangolo/typer

Re:Gooey: Turn almost any Python command line program into a... by franga2000 on Monday June 14, 2021 @11:00AM (#27503384)
You had me at pathlib! I wish people used it more...
Re:Gooey: Turn almost any Python command line program into a... by roryokane on Monday June 14, 2021 @11:46PM (#27511047)
For anyone who doesn’t know what pathlib is: https://docs.python.org/3/library/pathlib.html
Re:Gooey: Turn almost any Python command line program into a... by vorticalbox on Monday June 14, 2021 @02:30PM (#27506332)
I love fastapi I wish I knew about this before!
Re:Gooey: Turn almost any Python command line program into a... by miohtama on Monday June 14, 2021 @07:03PM (#27509465)
I also recommend checking out Clicky. It is similar to Fire, but has been out there for very long time and has some more power features and documentation.
Re:Gooey: Turn almost any Python command line program into a... by high_byte on Monday June 14, 2021 @10:59AM (#27503372)
Same! TIL Fire & Gooey is a power move.
Re:Gooey: Turn almost any Python command line program into a... by deagle50 on Monday June 14, 2021 @11:24AM (#27503687)
Same! Thanks.
Re:Gooey: Turn almost any Python command line program into a... by franga2000 on Monday June 14, 2021 @10:39AM (#27503094)
I've been using Gooey quite a lot lately and I'm really tired of setting up Argparse every time. Your recommendation of Fire came at exactly the right time! Thanks
Re:Gooey: Turn almost any Python command line program into a... by khimaros on Monday June 14, 2021 @10:30AM (#27502963)
an interesting related tool is https://github.com/fredrik-corneliusson/click-web which builds on the click library to create web front ends automatically.
Re:Gooey: Turn almost any Python command line program into a... by StavrosK on Monday June 14, 2021 @12:35PM (#27504692)
Oh damn, that's fantastic! I wanted to write a small server that did something between this and Fire above (i.e. allowed you to drop a Python script into a directory and would create a UI for its functions). It's a great way to make small, random functions I've written accessible to people with zero work.
Re:Gooey: Turn almost any Python command line program into a... by andreareina on Tuesday June 15, 2021 @05:29AM (#27512969)
Just found out about this, looks cool! Unfortunately file handling is a bit wonky, I suspect some of that is just the web platform (e.g. can't select directories), while some of it is probably due to a lack of bandwidth from what looks to mostly be a solo developer.
Re:Gooey: Turn almost any Python command line program into a... by legobmw99 on Monday June 14, 2021 @08:31AM (#27501785)
I’m not familiar with Fire, but I assume it uses argparse under the hood? Do you put the Gooey annotation on the function that calls fire.fire?
Re:Gooey: Turn almost any Python command line program into a... by frederikvs on Monday June 14, 2021 @10:41AM (#27503117)
Actually, I misspoke slightly when I said it turns the GUI into a CLI. Rather, it turns the same underlying class into a GUI.

So we have one file which contains the class with all the functions we want to expose (in our case, the class is named JobManager). At the end, it goes

    if __name__ == '__main__':
        fire.Fire(JobManager)
which takes care of all the CLI access we could want.

Then we have a second file for the GUI, which has a main-function that does some argparse stuff. The GUI interface is simplified from the CLI interface, so it's not that much work to write the argparse code for that. Simplified, it looks a little like this :

    @Gooey(default_size=(1000, 600))
    def main():
        parser = GooeyParser(description="jobGUI")
        # argparser code
        args = parser.parse_args()
    
        JobManager(args.name, args.whatever)
    
    if __name__ == '__main__':
        main()
Re:Gooey: Turn almost any Python command line program into a... by jmholla on Monday June 14, 2021 @03:43PM (#27507304)
Seems like you have update your API in two locations when changes happen, once in the `JobManager` definition and another time in the parser. How do you avoid issues with inconsistency?
Re:Gooey: Turn almost any Python command line program into a... by SeaWhales1000 on Monday June 14, 2021 @10:49AM (#27503229)
Thanks for the info. Where does your code/Gooey/Fire live? If I wanted to take a Python script to use, where do I put it with this setup?
Re:Gooey: Turn almost any Python command line program into a... by frederikvs on Monday June 14, 2021 @01:55PM (#27505815)
In our setup, we have a class that does the heavy lifting. The file where that class lives ends with :

    if __name__ == '__main__':
        fire.Fire(JobManager)
which turns it into an instant CLI.

Then we have a separate gui.py file, which contains the Gooey code. This includes the class mentioned above, and builds a minimalistic GUI around it. This does need some argparse-based code, but in the GUI we only expose a small subset of the full power, so we only need a little bit of argparse-code.

P.S. I'm not certain this is the best way to approach things, but it's the way we use it, and we're happy with it so far.

Re:Gooey: Turn almost any Python command line program into a... by catlifeonmars on Monday June 14, 2021 @09:42PM (#27510438)
Does anything like Fire exist for JS?
Re:Gooey: Turn almost any Python command line program into a... by delaaxe on Monday June 14, 2021 @06:42AM (#27501111)
Fire is great