Correct way to run the python interpreter from a repository rule ?

1,184 views
Skip to first unread message

vittorio....@gmail.com

unread,
Jan 5, 2017, 6:36:01 AM1/5/17
to bazel-discuss
I've made a repository rule that runs a python script by executing "python" (with no absolute path) with the script as argument.

This works in my setup because the python interpreter appears to be reacheable from the "standard" $PATH setup.

But is this the correct way to launch a python script from a repository rule ? Is there a more "portable" to execute run the python interpreter ?

Beware that I'm referring to a repository rule, because on normal rule one can just user py_binary and have the interpreter called for you. This is not possible on repository rules.


John Cater

unread,
Jan 5, 2017, 11:32:24 AM1/5/17
to vittorio....@gmail.com, bazel-discuss
The typical way to call any executable from a repository rule is to just require it to be in the user's $PATH environment variable, and then call it directly. See how the maven repository rules check dependencies and call mvn here: https://github.com/bazelbuild/bazel/blob/master/tools/build_defs/repo/maven_rules.bzl


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/feca5f45-f26c-434b-aa25-0d46a3221b9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul Johnston

unread,
Jan 5, 2017, 2:12:59 PM1/5/17
to bazel-discuss, vittorio....@gmail.com
You can also use repository_ctx.which to discover if python is in the $PATH and fail with a meaningful error if not found.

Reply all
Reply to author
Forward
0 new messages