-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add support for allow_single_file attribute to label_list and label_keyed_string_dict #5355
Comments
What would that mean in a |
I don't have a use case for this flag for So, if it does not make sense, just ignore this case. |
For |
I'd like to extend this feature request to also include the I tried to use My use case: I'd like to be able to p.s. I'm wondering why not make all "label" attributes consistent and have the same set of "filtering" parameters? |
I agree we could be more consistent here. But there's a cost to changing the API, and I wouldn't want to make it without a clearer sense of exactly what we're aiming for. Leaving this issue open but not prioritized. |
FWIW, I also just ran into this with a |
I wrote this function after inspecting the keys (pointing at files) that wound up in my def _file_from_label_keyed_string_dict_key(k):
# NB: The Targets in a label_keyed_string_dict attribute have the key's
# source file in a depset, as opposed being represented directly as in a
# label_list attribute.
files = k.files.to_list()
if len(files) != 1:
fail(msg = "Unexpected number of files in target {}: {}".format(k, len(files)))
return files[0] I have no idea whether I can count on this working in the future. |
I don't see why this isn't P2. Since other attr types have this already, label_keyed_string_dict should have it too. |
Description of the problem / feature request:
attr.label()
supportsallow_single_file
attribute which is very convenient. For some reasonattr.label_keyed_string_dict()
andattr.label_list()
do not although all of them supportallow_files
.I think it would be useful and consistent to have support for
allow_single_file
attribute in the later two.Feature requests: what underlying problem are you trying to solve with this feature?
In some private codebase I use
label_keyed_string_dict
and I have to assert that the value resolves to a single file andfail()
if not. Would be nice to remove this manual check.The text was updated successfully, but these errors were encountered: