Skip to content

Commit aca4ca9

Browse files
authored
Reformat cuquantum_configure.bzl using Buildifier (#949)
I missed this file in PR #948
1 parent 0647d00 commit aca4ca9

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

third_party/cuquantum/cuquantum_configure.bzl

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"""Setup cuQuantum as external dependency"""
1616
_CUQUANTUM_ROOT = "CUQUANTUM_ROOT"
1717

18-
1918
def _tpl(repository_ctx, tpl, substitutions = {}, out = None):
2019
if not out:
2120
out = tpl
@@ -25,14 +24,12 @@ def _tpl(repository_ctx, tpl, substitutions = {}, out = None):
2524
substitutions,
2625
)
2726

28-
2927
def _fail(msg):
3028
"""Output failure message when auto configuration fails."""
3129
red = "\033[0;31m"
3230
no_color = "\033[0m"
3331
fail("%sPython Configuration Error:%s %s\n" % (red, no_color, msg))
3432

35-
3633
def _execute(
3734
repository_ctx,
3835
cmdline,
@@ -60,7 +57,6 @@ def _execute(
6057
]))
6158
return result
6259

63-
6460
def _read_dir(repository_ctx, src_dir):
6561
"""Returns a string with all files in a directory.
6662
@@ -76,18 +72,17 @@ def _read_dir(repository_ctx, src_dir):
7672
result = find_result.stdout
7773
return result
7874

79-
8075
def _find_file(repository_ctx, filename):
8176
"""Returns a string with a directory path including the filename.
8277
8378
The returned string contains the parent path of the filename.
8479
"""
8580
result = repository_ctx.execute(
86-
["timeout", "5", "find", "/", "-name", filename, "-print", "-quit", "-not", "-path", "'*/.*'", "-quit"]).stdout
87-
result = result[:result.find(filename)+len(filename)]
81+
["timeout", "5", "find", "/", "-path", "*/.*", "-prune", "-o", "-name", filename, "-print", "-quit"],
82+
).stdout
83+
result = result[:result.find(filename) + len(filename)]
8884
return result
8985

90-
9186
def _genrule(genrule_name, command, outs):
9287
"""Returns a string with a genrule.
9388
@@ -121,7 +116,6 @@ def _norm_path(path):
121116
path = path[:-1]
122117
return path
123118

124-
125119
def _symlink_genrule_for_dir(
126120
repository_ctx,
127121
src_dir,
@@ -170,9 +164,9 @@ def _symlink_genrule_for_dir(
170164
"""
171165
if is_empty_genrule:
172166
if dest_dir != "":
173-
target_path = "%s/%s.h" % (dest_dir, genrule_name)
167+
target_path = "%s/%s.h" % (dest_dir, genrule_name)
174168
else:
175-
target_path = genrule_name
169+
target_path = genrule_name
176170
genrule = _genrule(
177171
genrule_name,
178172
"touch $(OUTS)",
@@ -208,21 +202,20 @@ def _symlink_genrule_for_dir(
208202
)
209203
return genrule
210204

211-
212205
def _cuquantum_pip_impl(repository_ctx):
213206
if _CUQUANTUM_ROOT in repository_ctx.os.environ:
214-
cuquantum_root = repository_ctx.os.environ[_CUQUANTUM_ROOT]
207+
cuquantum_root = repository_ctx.os.environ[_CUQUANTUM_ROOT]
215208
else:
216-
repository_ctx.os.environ[_CUQUANTUM_ROOT] = ""
217-
cuquantum_root = ""
209+
repository_ctx.os.environ[_CUQUANTUM_ROOT] = ""
210+
cuquantum_root = ""
218211

219212
if cuquantum_root == "":
220-
cuquantum_header_path = _find_file(repository_ctx, "custatevec.h")
221-
cuquantum_header_path = cuquantum_header_path[:cuquantum_header_path.find("/custatevec.h")]
222-
custatevec_shared_library_path = _find_file(repository_ctx, "libcustatevec.so")
213+
cuquantum_header_path = _find_file(repository_ctx, "custatevec.h")
214+
cuquantum_header_path = cuquantum_header_path[:cuquantum_header_path.find("/custatevec.h")]
215+
custatevec_shared_library_path = _find_file(repository_ctx, "libcustatevec.so")
223216
else:
224-
cuquantum_header_path = "%s/include" % cuquantum_root
225-
custatevec_shared_library_path = "%s/lib/libcustatevec.so" % (cuquantum_root)
217+
cuquantum_header_path = "%s/include" % cuquantum_root
218+
custatevec_shared_library_path = "%s/lib/libcustatevec.so" % (cuquantum_root)
226219

227220
is_empty_genrule = cuquantum_header_path == "" or custatevec_shared_library_path == ""
228221

@@ -231,7 +224,7 @@ def _cuquantum_pip_impl(repository_ctx):
231224
cuquantum_header_path,
232225
"include",
233226
"cuquantum_header_include",
234-
is_empty_genrule=is_empty_genrule,
227+
is_empty_genrule = is_empty_genrule,
235228
)
236229

237230
custatevec_shared_library_rule = _symlink_genrule_for_dir(
@@ -241,15 +234,14 @@ def _cuquantum_pip_impl(repository_ctx):
241234
"libcustatevec.so",
242235
[custatevec_shared_library_path],
243236
["libcustatevec.so"],
244-
is_empty_genrule=is_empty_genrule,
237+
is_empty_genrule = is_empty_genrule,
245238
)
246239

247240
_tpl(repository_ctx, "BUILD", {
248241
"%{CUQUANTUM_HEADER_GENRULE}": cuquantum_header_rule,
249242
"%{CUSTATEVEC_SHARED_LIBRARY_GENRULE}": custatevec_shared_library_rule,
250243
})
251244

252-
253245
cuquantum_configure = repository_rule(
254246
implementation = _cuquantum_pip_impl,
255247
environ = [

0 commit comments

Comments
 (0)