Guild not getting flags and scalars when using __main__

So my code has the following structure:

class definitions
function definitions

if name == “main”:
class call
function call

I think Guild is not recognizing the flags and scalars because they’re happening inside the class and function calls. Is there a way for Guild to parse them without modifying the code?

Can you provide a more detailed example?

1 Like

Guild does not look into class defs or function defs for scalars by design. Guild supports quite a few standard interfaces to Python modules:

  • Global vars including top-level variables, global dicts, and global simple objects
  • Argparse and click
  • Config files

I would encourage you to define your input params outside class defs and functions and refer to them as needed. This is a good separation for your code — script inputs ought IMO to be clearly defined.

The best way I think is to define a set of command line args to the script (e.g. via argparse or click). This not only clearly designates the script interface, it lets you easily modify params whenever you run the script. This is Guild’s default interface for that reason.

The easiest from a coding standpoint is to just use global variables. If you have a lot of params, use a single global dict or simple object. This example shows the various approaches.