I have the following Makefile:
PYTHON = python
.DEFAULT_GOAL = help
help:
@echo ------------------------------Makefile for Flask app------------------------------
@echo USAGE:
@echo make dependencies Install all project dependencies
@echo make docker Run Docker
@echo make env Set environment variables
@echo make run Run Flask app
@echo make test Run tests for app
@echo ----------------------------------------------------------------------------------
dependencies:
@pip install -r requirements.txt
@pip install -r dev-requirements.txt
docker:
docker compose up
env:
@set CS_HOST_PORT=5000
@set CS_HOST_IP=127.0.0.1
@set DATABASE_URL=postgresql://lv-python-mc:575@127.0.0.1:5482/Realty_DB
@set REDIS_IP=127.0.0.1
@set REDIS_PORT=6379
run:
${PYTHON} app.py test:
@${PYTHON} -m pytest
The set
command doesn't work and the environment variables aren't set, what may be the problem?
You can certainly set environment variables that will be in effect for programs make will invoke. But make
cannot set environment variables for shells that invoke make. So if your makefile runs a program then you can set an environment variable in your makefile that will be visible in that program.
This has nothing to do with make, by the way. This is a limitation (or feature, depending on your perspective) of the operating system. Try this experiment:
set FOO=bar
echo %FOO%
. See that it prints bar
.cmd.exe
set FOO=nobar
echo %FOO%
. See that it prints nobar
.exit
echo %FOO%
You'll see that instead of nobar
, it still prints bar
. That's because the OS does not allow a child program to modify the environment of its parent program.
So, there's nothing make can do about this.