#436 closed defect (fixed)
Expand environment variables in recipes
Reported by: | osimons | Owned by: | osimons |
---|---|---|---|
Priority: | major | Milestone: | 0.6 |
Component: | General | Version: | dev |
Keywords: | Cc: | ||
Operating System: | BSD |
Description
This is likely somewhat related to other needs, but I think Bitten should expand environment variables in recipes too. My projects/users are predominately Windows based, and a very common ideom is to use things like %programfiles% for paths referring to executables or arguments.
I've made a patch for this that extends the current Configuration.interpolation() method to also do environment variable expanding.
Attachments (1)
Change History (9)
Changed 15 years ago by osimons
comment:1 Changed 15 years ago by osimons
BTW, the expansion of environment variables likely has many other uses - not just paths. I'm trying to think of reasons why this isn't such a good idea, but can't quite see any.
Does anyone see reasons for this being a bad idea, or otherwise have complaints about this feature and the way of doing it?
comment:2 follow-up: ↓ 3 Changed 15 years ago by dfraser
I think this is a great idea too...
Is the syntax of ${var:default} the best though? It's not exactly the same as Bash (${var:offset} is what is meant by that in bash, and default values are ${var:-default})...
I'm quite in favour of us leaning towards fuller Genshi support in templates which would allow you to do all kinds of things; in that case the syntax would be ${var or 'default'} (unless you wanted to support empty strings in which case it would be more complicated: ${'default' if var is None else var}) - that would probably be equally parseable and make the way open for fuller Genshi support in future...
comment:3 in reply to: ↑ 2 Changed 15 years ago by dfraser
Is the syntax of ${var:default} the best though? It's not exactly the same as Bash (${var:offset} is what is meant by that in bash, and default values are ${var:-default})...
I'm quite in favour of us leaning towards fuller Genshi support in templates which would allow you to do all kinds of things; in that case the syntax would be ${var or 'default'} (unless you wanted to support empty strings in which case it would be more complicated: ${'default' if var is None else var}) - that would probably be equally parseable and make the way open for fuller Genshi support in future...
My apologies; I was reading the patch and got misled by the description of the current parameter support, and didn't read that it's actually using os.path.expandvars - you may return to your usual program...
comment:4 Changed 15 years ago by osimons
Right - supporting $USER, ${USER} and %USER% but somewhat platform dependent (and with varying case-sensitivity).
comment:5 Changed 15 years ago by osimons
- Milestone changed from 0.6 to 0.6.1
Doubts expressed on IRC channel by others - won't push this for 0.6, but may be revived in some other or adjusted form later.
comment:6 Changed 15 years ago by osimons
- Milestone changed from 0.6.1 to 0.6
cmlenz and dfraser now weighed in with 'yay' on IRC, so moving it back on track...
Just to clarify: My testing shows that $USER and ${USER} should be supported on all platforms, while %USER% will only be expanded by Windows slaves.
comment:7 Changed 15 years ago by osimons
- Resolution set to fixed
- Status changed from new to closed
I've tweaked the documentation to make the use of variables more clear, and committed it in [737].
comment:8 Changed 15 years ago by osimons
I've changed this slightly again in [744] - it now uses string.Template() whichs drops the Windows-specific syntax of %VARIABLE% in favour of making ${VARIABLE} work consistently on all platforms and python versions.
Patch that adds environment variables to interpolation (after configuration properties).