-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read env vars in extends"
#300
Comments
Maybe https://pypi.python.org/pypi/gocept.recipe.env helps here? It automatically reads the environment variables so you can access them from buildout parts. I use this in a couple of projects. It does not seem to be working when you try to access them from the main Technically, I guess you could take In your example you extend Easier is probably to not try to let |
Hey Maurits! Thanks for the tips!
Typo, fixed.
Yeah, my use-case is much more convoluted, this is just an example to showcase the functionality :) |
@zupo Guessing your goal, are you aware that nowadays you can use env variables in zope.conf? |
@zupo a major issue with your example is that buildout doesn't seem to take expansion variables into account when working with the I suppose it would be too confusing considering that an extended configuration, or your own For keys other than For example when invoking with the following command line: export PART=py
bin/buildout buildout:PART=$PART This configuration works perfectly: [buildout]
parts =
${:PART}
[py]
recipe = zc.recipe.egg
interpreter = py
eggs =
ipython |
@do3cc: nope, not a Zope project I need this on (it's pyramid) |
@zupo I've created a buildout extension buildout.extendssubs that provides new option [buildout]
extensions = buildout.extendssubs
extends-subs = ${:LEVEL}.cfg Env vars should be passed via command-line assignment options as in @leorochael's tip. $ export LEVEL=staging
$ bin/buildout buildout:LEVEL=$LEVEL Otherwise, I have a patch that update the buildout's diff --git a/src/zc/buildout/buildout.py b/src/zc/buildout/buildout.py
index e220ee7..37ac8b7 100644
--- a/src/zc/buildout/buildout.py
+++ b/src/zc/buildout/buildout.py
@@ -1624,7 +1624,7 @@ def _open(base, filename, seen, dl_options, override, downloaded):
dl_options = _update_section(dl_options, result['buildout'])
if extends:
- extends = extends.split()
+ extends = _sub_extends(extends, override.copy())
eresult = _open(base, extends.pop(0), seen, dl_options, override,
downloaded)
for fname in extends:
@@ -1635,6 +1635,17 @@ def _open(base, filename, seen, dl_options, override, downloaded):
seen.pop()
return result
+def _sub_extends(extends, override):
+ """Apply substitution for extends option
+ """
+ data = _unannotate(dict([('buildout', override)]))
+ data['buildout']['extends'] = extends
+ data_ops = Options(data, 'buildout', data['buildout'])
+ data['buildout'] = data_ops
+ # utilize Options' _sub
+ ops = Options(data, 'buildout', data['buildout'])
+ return ops.get('extends').split()
+
ignore_directories = '.svn', 'CVS', '__pycache__'
_dir_hashes = {} |
Passing env var as commandline-assignments is not what I am aiming for and does not really solve my use-case. I mean it does provide an alternative, but since I have many such env vars, the commandline command would get too long to be readable. I need the env vars to be read directly, from the inside the buildout.cfg file. |
@zupo I think using buildout.extendssubs together with an additional recipe such as collective.recipe.environment or gocept.recipe.env will make things work as expected. [buildout]
extensions = buildout.extendssubs
extends-subs = ${env:LEVEL}.cfg
[env]
recipe = collective.recipe.environment export LEVEL=staging
bin/buildout |
@zupo, without seeing why you need to try to select between buildouts with your environment variable, it's difficult to offer you alternatives. As others have mentioned, you can use environment variables inside any buildout value, with the help of So your "I have too many variables" issue can be dealt with by using those recipes, except for selecting a different file for the However, you could use env. variables to select the a buildout configuration to run by calling:
And from all files that could be selected by
If you don't want to keep remembering to use the
So there are plenty of existing ways of achieving what you need. You just need to use the tools already at your disposal. |
We have gone too specific with this issue. The "level" example I provided is just one of many use cases where using env vars in The other example is loading the configuration from a URL protected by HTTP Basic Auth, but you don't want credentials committed to repository. Something like this: [buildout]
extends = https://${USER}:${PASS}@my.internal.code.repository/my-project/base.cfg
... |
@leorochael I am aware of the workarounds you describe and am using them. But they are workarounds. I like to have my stack as clean as possible. And having the ability to use env vars in |
I'm not using buildout anymore, so I'm closing this. |
@zupo Out of curiosity, what are you using these days? |
@mauritsvanrees: pipenv It's nowhere near the feature-set of buildout, but I no longer need most of the features buildout provides (due to hosting on Heroku). And for people outside of the Plone community, pipenv is much easier to pick up. |
I already thought you might have gone for |
Given the following buildout.cfg
I would like to be able to do
export LEVEL=staging bin/buildout
with the result being that buildout would run with
buildout.d/staging.cfg
config. However I get the following errorThe text was updated successfully, but these errors were encountered: