-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
Support for Environment variables in BUILD files. #12797
Comments
Thanks for the suggestion! I like this - we want to reduce the need for writing custom plugins when possible. This also semi relates to #10399. FYI the reason we ban imports of -- Another consideration is how to handle data types. Would we expect the user to do this? python_tests(timeout=int(Env("MY_TIMEOUT")) That's legal because BUILD files are Python and An alternative is for the Target API to start accepting strings for non-strong fields and trying to convert. We only need to update the core definitions of python_tests(timeout=Env("MY_TIMEOUT")) |
Likely also related to #7022. |
From a users perspective, I would think having the field responsible for string-parsing would be the better option. Why should I, as a user, be responsible for making sure my fields are cast to the right type? From a developers perspective, while there are currently Int's and Floats as core fields, what about Lists-of-ints, and maps-of-floats and other more complex data structures? |
Sort of. If "target generation" lands, that will mean that you can write much more powerful macros that have access to the Rules API. Rather than using our custom plugin hooks for things like But, that still would mean writing a plugin. Iiuc this issue is about allowing you to access env vars without needing to write a plugin. Much lower barrier to entry and maintenance burden for users. --
Cool, agreed!
That should be doable :) For example, with a list of ints, it's probably too hard to implement parsing of |
I meant more that until #7022, there isn't a way to create either a macro or object that safely consumes the Env in a way that will be properly invalidated (without hacking deeply in BUILD parsing to special case this). |
Allows rules/targets to easily support values that can be pulled from the environment. Alternative solution to pantsbuild#12797.
Allows rules/targets to easily support values that can be pulled from the environment. Alternative solution to pantsbuild#12797.
Allows rules/targets to easily support values that can be pulled from the environment. Alternative solution to pantsbuild#12797.
With #7022 , how to write a macro to set by the env variable? |
Hey @da-tubi, the result of #7022 was the new Target Generator API added in Pants 2.8, the section "File-level metadata with overrides" of https://blog.pantsbuild.org/introducing-pants-2-8/. The only way currently consume environment variables in a BUILD files is by writing plugins using the Rules API, like a target generator, or the |
Is your feature request related to a problem? Please describe.
In two cases I've written a plugin that needs to access environment variables, and will need to write a third. Two of which, are documented cases for writing plugins.
$VERSION
variable and insert it intosetup_py()
$VERSION
and use it as thedocker_image(version=
.It would be much easier if by default these fields could take environment variables by default.
Describe the solution you'd like
An
Env
'function' inBUILD
files to denote the value of that field is to be taken from an environment variable.Other Considerations
Describe alternatives you've considered
Alternatively, these fields could be made to support environment variable interpolation by default. e.g.
docker_image(version='${VERSION}')
.While this would also work, it would require Pants developers to second-guess/dictate where environment variables might be used and increase the complexity.
The text was updated successfully, but these errors were encountered: