How can I (hermetically) include python
as an (executable) input to my genrule
?
Conceptually, I'm aware of the following approaches:
third_party/python
rules-go
There also seem to be a couple methods for doing so:
py_runtime
py_toolchain
(doesn't seem to be available yet)py_distribution_package
(doesn't seem to be available yet)genrules.tools
genrules.toolchains
Example:
I have a python library:
myproject
- setup.py
- mylibrary
- __init__.py
- myfunction.py
I'd like to produce a pip install
-able distribution with Bazel so that I can do:
pip install <path/to/distribution>
python
>>> from mylibrary.myfunction import helloworld
>>> helloworld()
I added a (empty) WORKSPACE
file at myproject/WORKSPACE
and followed the example in this medium article:
# myproject/BUILD
genrule(
name = "mylibrary_sdist",
srcs = glob(["**/*.py"]),
outs = ["mylibrary.tar.gz"],
cmd = "python setup.py sdist && mv dist/mylibrary*.tar.gz $(location mylibrary.tar.gz)"
)
This works (ie. produces bazel-genfiles/mylibrary.tar.gz
), but I'm shelling out to python
.
How can I (hermetically) include python
as an (executable) input to my genrule
?
As we expected, Bazel is using Python version 3.8. 3 that we compiled from scratch and not Python 3.9.
Unless I'm misunderstanding your question, this should just be a matter of passing the actual path to your target python executable. I would check the python executable into the third_party
dir and instead of invoking your genrule using simply python
I'd pass the relative path to that executable relative to WORKSPACE
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With