Skip to content

Commit 536653b

Browse files
Refactoring for parameter extensions (#44)
1 parent 30d8477 commit 536653b

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

defs.bzl

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ load("//:repositories.bzl", "all_requirements")
22

33
DEFAULT_REPOSITORY_NAME = "pip"
44

5-
65
def _pip_repository_impl(rctx):
76
python_interpreter = rctx.attr.python_interpreter
87
if rctx.attr.python_interpreter_target != None:
@@ -25,33 +24,34 @@ def _pip_repository_impl(rctx):
2524
]
2625
pypath = ":".join([str(p) for p in [rules_root] + thirdparty_roots])
2726

27+
args = [
28+
python_interpreter,
29+
"-m",
30+
"extract_wheels",
31+
"--requirements",
32+
rctx.path(rctx.attr.requirements),
33+
"--repo",
34+
"@%s" % rctx.attr.name,
35+
]
36+
2837
result = rctx.execute(
29-
[
30-
python_interpreter,
31-
"-m",
32-
"extract_wheels",
33-
"--requirements",
34-
rctx.path(rctx.attr.requirements),
35-
"--repo",
36-
"@%s" % rctx.attr.name,
37-
],
38-
environment={
38+
args,
39+
environment = {
3940
# Manually construct the PYTHONPATH since we cannot use the toolchain here
40-
"PYTHONPATH": pypath
41+
"PYTHONPATH": pypath,
4142
},
42-
timeout=rctx.attr.timeout,
43+
timeout = rctx.attr.timeout,
4344
)
4445
if result.return_code:
4546
fail("rules_python_external failed: %s (%s)" % (result.stdout, result.stderr))
4647

4748
return
4849

49-
5050
pip_repository = repository_rule(
51-
attrs={
52-
"requirements": attr.label(allow_single_file=True, mandatory=True,),
51+
attrs = {
52+
"requirements": attr.label(allow_single_file = True, mandatory = True),
5353
"wheel_env": attr.string_dict(),
54-
"python_interpreter": attr.string(default="python3"),
54+
"python_interpreter": attr.string(default = "python3"),
5555
"python_interpreter_target": attr.label(allow_single_file = True, doc = """
5656
If you are using a custom python interpreter built by another repository rule,
5757
use this attribute to specify its BUILD target. This allows pip_repository to invoke
@@ -61,11 +61,12 @@ python_interpreter.
6161
# 600 is documented as default here: https://docs.bazel.build/versions/master/skylark/lib/repository_ctx.html#execute
6262
"timeout": attr.int(default = 600),
6363
},
64-
implementation=_pip_repository_impl,
64+
implementation = _pip_repository_impl,
6565
)
6666

67-
68-
def pip_install(requirements, name=DEFAULT_REPOSITORY_NAME, **kwargs):
67+
def pip_install(requirements, name = DEFAULT_REPOSITORY_NAME, **kwargs):
6968
pip_repository(
70-
name=name, requirements=requirements, **kwargs
69+
name = name,
70+
requirements = requirements,
71+
**kwargs
7172
)

extract_wheels/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ def main() -> None:
6565
)
6666
args = parser.parse_args()
6767

68+
pip_args = [sys.executable, "-m", "pip", "wheel", "-r", args.requirements]
6869
# Assumes any errors are logged by pip so do nothing. This command will fail if pip fails
6970
subprocess.check_output(
70-
[sys.executable, "-m", "pip", "wheel", "-r", args.requirements]
71+
pip_args
7172
)
7273

7374
extras = requirements.parse_extras(args.requirements)

0 commit comments

Comments
 (0)