https://prefect.io logo
#prefect-community
Title
# prefect-community
w

William Jamir

05/18/2022, 9:04 PM
I have a file that defines the flow instance as a global variable, which is later used for registering the flow. Something like this:
Copy code
with Flow(...) as flow:
   x = Parameter(...)
   ...
Which is registered with:
Copy code
prefect register -p flows/my_file.py --project "MyProject"
But now I dont want to have this flow as a global variable, because my tests need to do some settings before and I dont want to trigger any of the code within this context manager. I can easily move this to a function, and make it return the flow instance, but I dont know how to deal with the registration by command line. I mean, its possible to still use the register by command line, or do I need to make it now programmatically? Basically, I’m looking for a solution like this:
Copy code
def main():
   with Flow(...) as flow:
      x = Parameter(...)
      ...
   return flow
Registering
Copy code
prefect register -p flows/my_file.py:main --project "MyProject"
k

Kevin Kho

05/18/2022, 9:25 PM
Maybe you can use the
if __name__ == __main__
instead and add flow.register() or call your function there?
I think it needs to be defined in the global namespace for you to be able to use the CLI
5 Views