-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add compatibility layer for attr.string_keyed_label_dict
Also stop using `Label(...)` in local_cuda as the dev experience is really awful when components_mapping fallbacks to `attr.string_dict`
- Loading branch information
Showing
5 changed files
with
64 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
_is_attr_string_keyed_label_dict_available = getattr(attr, "string_keyed_label_dict", None) != None | ||
_is_bzlmod_enabled = str(Label("//:invalid")).startswith("@@") | ||
|
||
def _attr(*args, **kwargs): | ||
"""Compatibility layer for attr.string_keyed_label_dict(...)""" | ||
if _is_attr_string_keyed_label_dict_available: | ||
return attr.string_keyed_label_dict(*args, **kwargs) | ||
else: | ||
return attr.string_dict(*args, **kwargs) | ||
|
||
def _repo_str(repo_str_or_repo_label): | ||
"""Get mapped repo as string. | ||
Args: | ||
repo_str_or_repo_label: `"@repo"` or `Label("@repo")` """ | ||
if type(repo_str_or_repo_label) == "Label": | ||
canonical_repo_name = repo_str_or_repo_label.repo_name | ||
repo_str = ("@@{}" if _is_bzlmod_enabled else "@{}").format(canonical_repo_name) | ||
return repo_str | ||
else: | ||
return repo_str_or_repo_label | ||
|
||
components_mapping_compat = struct( | ||
attr = _attr, | ||
repo_str = _repo_str, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters