:white_check_mark: thought for 178.7 seconds
# ask-marvin
m
thought for 178.7 seconds
You can run Makefile targets from a Prefect task using the prefect-shell integration. Steps: 1) Install the integration
Copy code
pip install prefect-shell
2) Call
shell_run_command
inside your flow (or task) and point it at the directory with your Makefile via `cwd`:
Copy code
from prefect import flow
from prefect_shell.commands import shell_run_command

@flow
def run_make():
    # Run the default target in the Makefile
    shell_run_command("make", cwd="/path/to/project")

    # Or run a specific target
    result = shell_run_command("make build", cwd="/path/to/project")
    print("Make output:", result)

if __name__ == "__main__":
    run_make()
Notes: -
cwd
should be the directory containing the Makefile (alternatively, use
make -C /path/to/project build
). - You can pass environment variables with
env
, e.g.:
Copy code
shell_run_command("make deploy", cwd="/path/to/project", env={"ENV": "prod"})
- The command’s output is captured and available as the return value; a non-zero exit status will fail the task. - Ensure
make
is installed and available on the PATH in your execution environment (e.g., your worker image). Docs: - prefect-shell integration docs - prefect-shell GitHub If you share where your Makefile lives and how you’re running (local, Docker, k8s), I can tailor the example (e.g., correct
cwd
, environment vars, or container setup).