https://prefect.io logo
Title
o

Ofir

08/26/2022, 1:29 PM
Is there a best practice for mocking the task decorators (and other decorators)? Should I do something like:
try:
    import prefect
except ImportError
    def @task(func): return func
?
👀 1
1
r

Ryan Peden

08/26/2022, 2:06 PM
If you want to keep your existing code base as-is without adding a Prefect dependency, might it be useful to import your existing functions and run them in Prefect flows and tasks? For example:
from prefect import flow, task

from your_module import preprocessing_function
from your_other_module import training_function

@task
def preprocess_data():
  preprocessing_function()

@task
def train():
  training_function()

@flow(name='My pipeline')
def process_and_train():
  preprocess_data()
  train()
This would let you introduce Prefect gradually without needing to alter your existing code - so anyone who wants to keep using the code base as-is can do so, and anyone who wants to use the Prefect flows you are building can install Prefect.
:upvote: 2
o

Ofir

08/26/2022, 2:18 PM
Thanks @Ryan Peden I appreciate that. I had exactly this plan in mind but was wondering whether it’s the way to go
The only downside is the amount of boilerplate and maintenance, it means that every change in my code (flow) structure needs to be accompanied by a change in Prefect