Make Automation


We can create a Makefile in Python which helps to automate tasks like running your Python scripts, testing, or building your project. 
A Makefile is a file used by the make build automation tool to define a set of tasks that should be executed. Each task is written as a target, and it can depend on other tasks or files.

In general, structure of makefile are:

  • Target

  • Dependencies

  • Commands

Ok, lets understand this with help of an example.


Makefile(has no extensions)
# Define variables for system Python and pip for virtual environment
SYSTEM_PYTHON = python3
VENV_PYTHON = myvenv/bin/python
VENV_PIP = myvenv/bin/pip

# Target: venv
# Creates a virtual environment in 'myvenv' directory using system Python.
venv:
$(SYSTEM_PYTHON) -m venv myvenv

# Target: install
# Installs dependencies if 'requirements.txt' exists.
install: venv
$(VENV_PIP) install -r requirements.txt;


# Target: all
# Runs venv, install, and run targets.
all: venv install



In example above,

  • install is a Target.

  • Dependencies  is  requirements.txt. 

  • Command  is $(PIP) install -r requirements.txt

Now to run the make file , just type

 ---- command-----
 make all 

in the terminal, as shown in screenshot below.












This is a simple make file that automates the making of virtual environment, then inside that environment , we install pandas.



Comments

Popular posts from this blog

ML concepts (Regression, Classification, Clustering)

Retrieval-Augmented Generation (RAG)