Create powershell environment variables with makefile, and accessing them with python os.environ

Question:

With VSCode, I’m accessing to a python project that have a makefile like this:

VARIABLES = VAR1="text1" 
    VAR2="text2" 
    VAR3="text3"

.PHONY: run
run:
    $(VARIABLES) poetry run python -m start.app

I am on a windows machine, with "make" installed on powershell by chocholately.
Launching the command make --version prints:

GNU Make 4.3
Built for Windows32
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

BUT the run command is not compatible with powershell (at best of my understanding). I think the solution is to rewrite the run command.
Given the fact that the code in pythom will access the variable this way

import os
print(os.environ["var1"])

I’m trying to solve this by having the run command using the powershell command $env:var1 = "true" before running the poetry command

Am i on the right trak? How can i achive this? Is there a smarter solution?

I tried googling with various key search but it seems i cannot find the answer or other solution to achieve this

Asked By: Valerio

||

Answers:

Do you have to have those variables set only when invoking the run target? If you’re willing to have them set for all targets you can just export them from make itself:

export VAR1 = text1
export VAR2 = text2
export VAR3 = text3

.PHONY: run
run:
        poetry run python -m start.app

Actually I guess you could also use target-specific exported variables:

.PHONY: run
run: export VAR1 = text1
run: export VAR2 = text2
run: export VAR3 = text3
run:
        poetry run python -m start.app
Answered By: MadScientist