Skip to content

Commit

Permalink
Switch loops maintaining their own index variable to use enumerate().
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmoor committed Dec 9, 2017
1 parent 8f6f1c8 commit dcebca4
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 33 deletions.
4 changes: 1 addition & 3 deletions cc/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,11 @@ def cc_image(name, base=None, deps=[], layers=[], binary=None, **kwargs):
elif deps:
fail("kwarg does nothing when binary is specified", "deps")

index = 0
base = base or DEFAULT_BASE
for dep in layers:
for index, dep in enumerate(layers):
this_name = "%s.%d" % (name, index)
dep_layer(name=this_name, base=base, dep=dep)
base = this_name
index += 1

visibility = kwargs.get('visibility', None)
app_layer(name=name, base=base, binary=binary, layers=layers,
Expand Down
4 changes: 1 addition & 3 deletions contrib/push-all.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def _impl(ctx):

scripts = []
runfiles = []
index = 0
for tag in images:
for index, tag in enumerate(images.keys()):
image = images[tag]
# Leverage our efficient intermediate representation to push.
legacy_base_arg = ""
Expand Down Expand Up @@ -77,7 +76,6 @@ def _impl(ctx):

scripts += [out]
runfiles += [out]
index += 1

ctx.template_action(
template = ctx.file._all_tpl,
Expand Down
4 changes: 1 addition & 3 deletions d/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ def d_image(name, base=None, deps=[], layers=[], binary=None, **kwargs):
elif deps:
fail("kwarg does nothing when binary is specified", "deps")

index = 0
base = base or DEFAULT_BASE
for dep in layers:
for index, dep in enumerate(layers):
this_name = "%s_%d" % (name, index)
dep_layer(name=this_name, base=base, dep=dep)
base = this_name
index += 1

visibility = kwargs.get('visibility', None)
app_layer(name=name, base=base, binary=binary, layers=layers,
Expand Down
4 changes: 1 addition & 3 deletions go/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ def go_image(name, base=None, deps=[], layers=[], binary=None, **kwargs):
elif deps:
fail("kwarg does nothing when binary is specified", "deps")

index = 0
base = base or DEFAULT_BASE
for dep in layers:
for index, dep in enumerate(layers):
this_name = "%s.%d" % (name, index)
dep_layer(name=this_name, base=base, dep=dep)
base = this_name
index += 1

visibility = kwargs.get('visibility', None)
app_layer(name=name, base=base, binary=binary, layers=layers,
Expand Down
8 changes: 2 additions & 6 deletions java/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,11 @@ def java_image(name, base=None, main_class=None,
deps=(deps + layers) or None, runtime_deps=runtime_deps,
jvm_flags=jvm_flags, **kwargs)

index = 0
base = base or DEFAULT_JAVA_BASE
for dep in layers:
for index, dep in enumerate(layers):
this_name = "%s.%d" % (name, index)
jar_dep_layer(name=this_name, base=base, dep=dep)
base = this_name
index += 1

visibility = kwargs.get('visibility', None)
jar_app_layer(name=name, base=base, binary=binary_name,
Expand Down Expand Up @@ -353,13 +351,11 @@ def war_image(name, base=None, deps=[], layers=[], **kwargs):

native.java_library(name=library_name, deps=deps + layers, **kwargs)

index = 0
base = base or DEFAULT_JETTY_BASE
for dep in layers:
for index, dep in enumerate(layers):
this_name = "%s.%d" % (name, index)
_war_dep_layer(name=this_name, base=base, dep=dep)
base = this_name
index += 1

visibility = kwargs.get('visibility', None)
_war_app_layer(name=name, base=base, library=library_name, layers=layers,
Expand Down
4 changes: 1 addition & 3 deletions nodejs/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,11 @@ def nodejs_image(name, base=None, data=[], layers=[],

# TODO(mattmoor): Consider making the directory into which the app
# is placed configurable.
index = 0
base = base or DEFAULT_BASE
for dep in layers:
for index, dep in enumerate(layers):
this_name = "%s.%d" % (name, index)
_dep_layer(name=this_name, base=base, dep=dep, binary=binary_name)
base = this_name
index += 1

visibility = kwargs.get('visibility', None)
app_layer(name=name, base=base, entrypoint=['sh', '-c'],
Expand Down
4 changes: 1 addition & 3 deletions python/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,11 @@ def py_image(name, base=None, deps=[], layers=[], **kwargs):

# TODO(mattmoor): Consider making the directory into which the app
# is placed configurable.
index = 0
base = base or DEFAULT_BASE
for dep in layers:
for index, dep in enumerate(layers):
this_name = "%s.%d" % (name, index)
dep_layer(name=this_name, base=base, dep=dep)
base = this_name
index += 1

visibility = kwargs.get('visibility', None)
app_layer(name=name, base=base, entrypoint=['/usr/bin/python'],
Expand Down
4 changes: 1 addition & 3 deletions python3/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,11 @@ def py3_image(name, base=None, deps=[], layers=[], **kwargs):

# TODO(mattmoor): Consider making the directory into which the app
# is placed configurable.
index = 0
base = base or DEFAULT_BASE
for dep in layers:
for index, dep in enumerate(layers):
this_name = "%s.%d" % (name, index)
dep_layer(name=this_name, base=base, dep=dep)
base = this_name
index += 1

visibility = kwargs.get('visibility', None)
app_layer(name=name, base=base, entrypoint=['/usr/bin/python'],
Expand Down
4 changes: 1 addition & 3 deletions rust/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ def rust_image(name, base=None, deps=[], layers=[], binary=None, **kwargs):
elif deps:
fail("kwarg does nothing when binary is specified", "deps")

index = 0
base = base or DEFAULT_BASE
for dep in layers:
for index, dep in enumerate(layers):
this_name = "%s_%d" % (name, index)
dep_layer(name=this_name, base=base, dep=dep)
base = this_name
index += 1

visibility = kwargs.get('visibility', None)
app_layer(name=name, base=base, binary=binary, layers=layers,
Expand Down
4 changes: 1 addition & 3 deletions scala/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ def scala_image(name, base=None, main_class=None,
deps=(deps + layers) or None, runtime_deps=runtime_deps,
jvm_flags=jvm_flags, **kwargs)

index = 0
base = base or DEFAULT_JAVA_BASE
for dep in layers:
for index, dep in enumerate(layers):
this_name = "%s.%d" % (name, index)
jar_dep_layer(name=this_name, base=base, dep=dep)
base = this_name
index += 1

visibility = kwargs.get('visibility', None)
jar_app_layer(name=name, base=base, binary=binary_name,
Expand Down

0 comments on commit dcebca4

Please sign in to comment.