Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Script Executed with Makefile

I am writing python scripts and execute them in a Makefile. The python script is used to process data in a pipeline. I would like Makefile to execute the script every time I make a change to my python scripts.

Does anyone have an idea of how to do this?

like image 526
Patrick Avatar asked Jun 30 '09 08:06

Patrick


People also ask

Can I use Makefile for Python?

Even though Python is regarded as an interpreted language and the files need not be compiled separately, many developers are unaware that you can still use make to automate different parts of developing a Python project, like running tests, cleaning builds, and installing dependencies.

Do I need a Makefile for Python?

Nothing in your Python code needs to know that make is being used. Your Makefile simply describes the commands you would otherwise run at the command line to build your executable, whatever those might be.


2 Answers

That's not a lot of information, so this answer is a bit vague. The basic principle of Makefiles is to list dependencies for each target; in this case, your target (let's call it foo) depends on your python script (let's call it do-foo.py):

foo: do-foo.py
    python do-foo.py > foo

Now foo will be rerun whenever do-foo.py changes (provided, of course, you call make).

like image 159
Alice Purcell Avatar answered Oct 15 '22 12:10

Alice Purcell


And in case when the scripts that need to be run don't produce any useful output file that can be used as a target, you can just use a dummy target:

scripts=a.py b.py c.py
checkfile=.pipeline_up_to_date

$(checkfile): $(scripts)
    touch $(checkfile)
    echo "Launching some commands now."

default: $(checkfile)
like image 31
yacoob Avatar answered Oct 15 '22 13:10

yacoob