Conditionally include or remove code portion, according to the environment. It support offline and on-thy-fly preprocessing.
Let's say you want to release a version of your code with or without a feature, like unlimited life in a game. It can be useful during development, but you don't want the code to be available in production.
Condiment recognize the environment variables that starts with the prefix
"WITH_" all uppercase. We could name our feature: WITH_GODMODE
.
In python, you need to include condiment, and install it. You can put it in
exclude block, in order to be removed during the offline preprocessing.
#exclude
import condiment; condiment.install()
#endexclude
class Player:
def die(self):
if not WITH_GODMODE:
self.life -= 1
return self.life
You can run it without the godmode:
$ python main.py
Or by activating the godmode at runtime:
$ WITH_GODMODE=1 python main.py
You can generate the final version for production too:
$ WITH_GODMODE=1 condiment main.py > prod_main.py
$ cat prod_main.py
class Player:
def die(self):
self.life -= 1
return self.life
If you want to set an initial value, all the token founds in the environment
will be replaced during the generation. For example, a WITH_LIFE
token could
have the initial number of life.
#exclude
import condiment; condiment.install()
#endexclude
class Player:
def __init__(self):
Player.__init__(self)
self.life = 10
if WITH_LIFE:
self.life = WITH_LIFE
def die(self):
if not WITH_GODMODE:
self.life -= 1
return self.life
Compared to others existing preprocessor: