Skip to content

Commit

Permalink
Update vendored skylib to 0.5.0 (#1831)
Browse files Browse the repository at this point in the history
Related #1829
  • Loading branch information
jayconrod committed Nov 26, 2018
1 parent 176c51a commit 633440b
Show file tree
Hide file tree
Showing 13 changed files with 1,058 additions and 984 deletions.
2 changes: 1 addition & 1 deletion go/private/skylib/README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This directory is a copy of github.com/bazelbuild/bazel-skylib/lib.
Version 0.4.0, retrieved on 2018-06-11
Version 0.5.0, retrieved on 2018-11-26.

This is needed only until nested workspaces works.
It has to be copied in because we use the functionality inside code that
Expand Down
76 changes: 36 additions & 40 deletions go/private/skylib/lib/collections.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,56 @@

"""Skylib module containing functions that operate on collections."""


def _after_each(separator, iterable):
"""Inserts `separator` after each item in `iterable`.
Args:
separator: The value to insert after each item in `iterable`.
iterable: The list into which to intersperse the separator.
"""Inserts `separator` after each item in `iterable`.
Returns:
A new list with `separator` after each item in `iterable`.
"""
result = []
for x in iterable:
result.append(x)
result.append(separator)
Args:
separator: The value to insert after each item in `iterable`.
iterable: The list into which to intersperse the separator.
return result
Returns:
A new list with `separator` after each item in `iterable`.
"""
result = []
for x in iterable:
result.append(x)
result.append(separator)

return result

def _before_each(separator, iterable):
"""Inserts `separator` before each item in `iterable`.
"""Inserts `separator` before each item in `iterable`.
Args:
separator: The value to insert before each item in `iterable`.
iterable: The list into which to intersperse the separator.
Args:
separator: The value to insert before each item in `iterable`.
iterable: The list into which to intersperse the separator.
Returns:
A new list with `separator` before each item in `iterable`.
"""
result = []
for x in iterable:
result.append(separator)
result.append(x)

return result
Returns:
A new list with `separator` before each item in `iterable`.
"""
result = []
for x in iterable:
result.append(separator)
result.append(x)

return result

def _uniq(iterable):
"""Returns a list of unique elements in `iterable`.
Requires all the elements to be hashable.
"""Returns a list of unique elements in `iterable`.
Args:
iterable: An iterable to filter.
Requires all the elements to be hashable.
Returns:
A new list with all unique elements from `iterable`.
"""
unique_elements = {element: None for element in iterable}
return unique_elements.keys()
Args:
iterable: An iterable to filter.
Returns:
A new list with all unique elements from `iterable`.
"""
unique_elements = {element: None for element in iterable}
return unique_elements.keys()

collections = struct(
after_each=_after_each,
before_each=_before_each,
uniq=_uniq,
after_each = _after_each,
before_each = _before_each,
uniq = _uniq,
)
36 changes: 17 additions & 19 deletions go/private/skylib/lib/dicts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,28 @@

"""Skylib module containing functions that operate on dictionaries."""


def _add(*dictionaries):
"""Returns a new `dict` that has all the entries of the given dictionaries.
If the same key is present in more than one of the input dictionaries, the
last of them in the argument list overrides any earlier ones.
"""Returns a new `dict` that has all the entries of the given dictionaries.
This function is designed to take zero or one arguments as well as multiple
dictionaries, so that it follows arithmetic identities and callers can avoid
special cases for their inputs: the sum of zero dictionaries is the empty
dictionary, and the sum of a single dictionary is a copy of itself.
If the same key is present in more than one of the input dictionaries, the
last of them in the argument list overrides any earlier ones.
Args:
*dictionaries: Zero or more dictionaries to be added.
This function is designed to take zero or one arguments as well as multiple
dictionaries, so that it follows arithmetic identities and callers can avoid
special cases for their inputs: the sum of zero dictionaries is the empty
dictionary, and the sum of a single dictionary is a copy of itself.
Returns:
A new `dict` that has all the entries of the given dictionaries.
"""
result = {}
for d in dictionaries:
result.update(d)
return result
Args:
*dictionaries: Zero or more dictionaries to be added.
Returns:
A new `dict` that has all the entries of the given dictionaries.
"""
result = {}
for d in dictionaries:
result.update(d)
return result

dicts = struct(
add=_add,
add = _add,
)
Loading

0 comments on commit 633440b

Please sign in to comment.