# HG changeset patch # User Ludovic Chabant # Date 1519624135 28800 # Node ID 40228511d6005b15654a82d4bc8b7e12bf9a84cb # Parent 11b9d0c8bd62f201f387cad10f7d998fc0b4b44d chef: Add new `chef/env` config section. diff -r 11b9d0c8bd62 -r 40228511d600 docs/config.yml --- a/docs/config.yml Sat Feb 24 21:13:54 2018 -0800 +++ b/docs/config.yml Sun Feb 25 21:48:55 2018 -0800 @@ -24,6 +24,10 @@ source: api func: apiurl +chef: + env: + PATH: node_modules/.bin + baker: assets_dirs: assets: diff -r 11b9d0c8bd62 -r 40228511d600 docs/docs/99_reference/01_website-configuration.md --- a/docs/docs/99_reference/01_website-configuration.md Sat Feb 24 21:13:54 2018 -0800 +++ b/docs/docs/99_reference/01_website-configuration.md Sun Feb 25 21:48:55 2018 -0800 @@ -136,6 +136,26 @@ [tplengref]: {{docurl('reference/template-engines')}} +## Chef Command Line + +The following settings are unde the `chef` section, and all valid for _all_ chef +commands. + +* `env`: A mapping of environment variables and values to set before running the + current command. By default, variables are set to the given value. If a `+` is + added to the variable name, the value will be _appended_ instead. The `PATH` + variable's value is _always_ appended with either `:` or `;` depending on the + OS. + + For example: + + chef: + env: + PATH: node_modules/.bin + SOME_VAR: value + "OTHER_VAR+": ",append this" + + ## Preparation The following settings are under the `prepare` section, and are used by the diff -r 11b9d0c8bd62 -r 40228511d600 piecrust/main.py --- a/piecrust/main.py Sat Feb 24 21:13:54 2018 -0800 +++ b/piecrust/main.py Sun Feb 25 21:48:55 2018 -0800 @@ -246,6 +246,25 @@ return cache_key +def _setup_app_environment(env): + for k, v in env.items(): + varname = k + append = False + if k.lower() == 'path': + append = True + v = os.pathsep + v + elif k.endswith('+'): + varname = k[:-1] + append = True + + if append: + logger.debug("Env: $%s += %s" % (varname, v)) + os.environ[varname] += v + else: + logger.debug("Env: $%s = %s" % (varname, v)) + os.environ[varname] = v + + def _run_chef(pre_args, argv): # Setup the app. root = None @@ -315,6 +334,11 @@ parser.print_help() return 0 + # Do any custom setup the user wants. + custom_env = app.config.get('chef/env') + if custom_env: + _setup_app_environment(custom_env) + # Add some timing information. if app.env: app.env.stats.registerTimer('ChefStartup')