Hi. I am having some trouble making `prefect regis...
# ask-community
f
Hi. I am having some trouble making
prefect register --module
work. My project looks like this:
Copy code
flows
  + __init__.py
  + my_flow.py
  + shared_tasks
    + __init__.py
    + util.py
When I run
prefect register --project 'Prefect Testing' -m '<http://flows.my|flows.my>_flow'
, I get
No module named 'flows'
. What am I missing?
k
Hi @Florian Kühnlenz, is your module named
flows
or
flow
?
f
flows
, but sadly the typo was only in slack 😞. I can also import the module just fine in python.
In fact if I do:
python -c "import flows; <http://flows.my|flows.my>_flow.test_flow.register('Prefect Testing')"
it works just fine.
k
What is your Prefect version?
Have you seen this? Did you import all of your flows into the
___init___.py
?
f
Nope, I have not yet seen this. Prefect version is 0.14.15
Sadly it does not help to import the flows in the init it seams.
k
I haven’t had time yet to try this myself but I’ll try to get back to you later
You need the
setup.py
and you need to install the library
pip install -e .
. This will allow it to find the module.
prefect register --module my_package.flows --project example
worked for me (although the flows are useless)
This is a fully working example
f
Mmm. If that is the case it is very confusing that
prefect register
would need the module installed via pip while the normal
flow.register
method would not. Is this mentioned somewhere in the documentation?
k
This is not because of the CLI. This is specific to Module storage because it loops through the flows of the module and registers them one at a time. Or do you mean
flow.register
with the
Module
storage? This is not documented. I’m considering adding it
f
Well, I have my flow setup with module storage, because file storage brought some problems with debugging. But even given the example you linked from @Jim Crist-Harif I don’t see how I should discover that the module needs to be installed via pip. But maybe I just missed this in the context. I think installing does not make to much sense for my case either. For context, we want to have the flows stored in docker as well as docker being used as run environment. We managed a setup with docker as run config and local storage for the flows. But it had some downsides for debugging and was cumbersome around the edges to register the flows and managing the imports (manipulate the sys path etc).
k
I understand the pip install was not intuitive. I will add it to the Module storage docs. About the cumbersome imports, i’ve had issues too at previous jobs with sys.paths and we went to modules and absolute paths. Putting your flows as a module and then installing that wheel in the Docker container actually may be an approach to consider. What was cumbersome when registering the flows?
Sample to add files to Docker storage
Copy code
flow.storage = Docker(
    files={"path/to/my_module": "my_module"},
    extra_dockerfile_commands=["RUN pip install -e my_module}"],
)
f
I will play around with that tomorrow. We use poetry for package management anyway. So creating and installing a module might be fairly easy. About the registering: we used a separate script to register each flow. Which made it necessary to have a
Copy code
if __name__ == “__main__”:
    flow.register()
At the bottom of each flow. Which one would need to change for debugging. With the new cli I did not manage to make it work, maybe because there is a fix upstream about the python context (https://github.com/PrefectHQ/prefect/pull/4332)
k
Got it. I think the module is a cleaner way to debug because you wouldn’t register it in the flow definition file. You can also import run a low individually to debug
from my_package.flow1 import flow
;
flow.run()
. Not definitively saying this is how to do things. Just throwing options out there, but I’ll add the documentation addition to my list 🙂
👍 1