-
Notifications
You must be signed in to change notification settings - Fork 550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specify different interpreter for py_binary rules #62
Comments
I strongly disagree. Python 2 should not even be supported imho, but it definitely should NOT be made default less than 2 years before upstream's extended support ends. Unfortunately a lot of Bazel's internal stuff is still thinking that Python 2 is system default, this would be a good time to update it instead of keeping it on life support even longer. End the suffering.
I agree, especially keeping in mind that there are several Python interpreters out there (cPython just being one of them - there's also pypy, jython, cython...) and that it would be nice to be able to easily choose from a variety of them for releases, tests and benchmarks. |
Thanks for your feedback, just to clarify when I said:
I meant as a workaround (unless you don't agree with the workaround if so I would love to hear better alternatives), b/c as you said it's the current state of some Bazel extensions, I would love if we don't have to support Python2 anymore and that what we did in my current company, but since we adopted Bazel we are back to supporting it, and defaulting to Python2 in build seems to do it, for now at least, things will be much worse if there are extensions that require Python3 and other Python2, especially since setting up Python version is a global thing, so in this move toward Python3 please make sure to both are supported until transitions end. IMHO the most important thing that I am trying to emphasize is to not make python version a global thing, which the mistake that |
I think one of the questions is if a I guess most people would expect the latter and at that point I would rather see PEP394 (https://www.python.org/dev/peps/pep-0394/) being used instead of some environment variable decorator magic. A There is the problem that Bazel itself also depends on Python being present on the host system for some of its scripts/rules and it mostly expects Python2 there (see bazelbuild/bazel#1580). I don't know if that's going to be phased out, now that the skylark language runtime has been rewritten in go and if they might be convinced to rewrite the remaining few helpers in go. Alternatively Bazel would need some way to have a vendored Python binary that it uses to run its internal rule scripts instead of relying on Python being present on its host machine. The Python rules here seem to suffer a bit from this assumption that Python (unlike e.g. the |
I agree about the self-contained Python IMHO self-contained Python package is nice to have but not necessary, however about using
From the good side, I can see it fixing issues when containerizing python code b/c currently if you use host machine python path in
Isn't this already feasible with
I can see that you're looking at this from the lenses of Bazel core developer, from a user perspective I can tell you that Python suffers the assumption that by just pointing code to an interpreter and that's it, sadly it's not that easy, besides it seems that Google use Python a bit different, hence the awkward support of Python in Bazel that probably was inherited from Blaze, in theory you should:
|
I am not a Bazel core developer or even employed by Google, I'm a normal user... |
@MarkusTeufelberger Ahh sorry for the confusion, but then just to reiterate, our experience has shown that the workaround above works for us, most of our issues concerning python version were due to extensions and not Bazel internal, but it's possible that our use cases are different than yours, that's why we see different issues. |
Yes, it's good to remember that Python, and software developing in general, happens in a wide variety of environments, and so people's requirements can legitimately be very different. One person's "must have feature" is another's "we would never use this", and that's fine. Here's a discussion group that may be of interest: https://groups.google.com/forum/#!forum/bazel-sig-python Here's a document proposing a |
Is there already a solution to this feature request? I can't see how all these issues relate to the question or if they avoid the initially mentioned workaround. If it is fixed by now, can you please provide a small example code. |
I managed to make that work properly for me by specifying
In addition, I added I use Bazel 0.26.0 (I think python toolchains have been introduced in 0.25-ish) and the following
|
Checking the "Goals" section of the original issue description:
The Python toolchain is not available at WORKSPACE evaluation time, but with the pip_install(
name = "foo_pip",
python_interpreter_target = "@python3//:bin/python3",
requirements = "//tools/build/dependencies/python:requirements.txt",
)
Bazel Toolchains work with the Python rules now.
With Given the above, I think this issue can be closed, but please let me know if there's something still missing and we can create a new more specific issue. |
Unfortunately it's not possible to use
Toolchains seem overly complicated for our use-case (we have multiple |
I would also be interested in this feature being available. |
Hey all,
Problem Statement
It's quite confusing how a user can specify that a given rule need to use Python3 or that rule need Python2, where we have multiple attributes documented like
default_python_version
,srcs_version
and undocumented like:py_interpreter
(which can't be used but out of curiosity what is the prefix:
doing), however I am still confused regarding what does what, in the end, what I think we should have is a way to tell py_binary to execute using the interpreter X, I know aboutpy_runtime
which is supposed to be the future but there are multiplepy_binary
rules out there with unspecify python version which lead to issues of python3 and 2 compatibilities, beside there is an assumption with the introduced with--python_top
argument that all code need one interepreter instead of having local to each target.Workaround
Currently we use the following workaround, maybe useful for others that suffer same issue:
The Decorator Pattern
force_python3.py
:(This assume that we expose a
PYTHON3_PATH
environment variable with--action_env=PYTHON3_PATH=<path>
).py_binary
rule by pointingmain
attribute to the file above:FYI we have a workaround of our own to specify which python to use for pip requirements.
Goals
What I would like to see are the followings:
py_binary
andpy_test
rules to specify which python interpreter to use, it should be a label and point to apy_runtime
, if not specified revert to default py_runtime (for backward compatibility too).--python_top
argument b/c the assumption that you need one global Python version is bogus as explained above.py_runtime
should be specified in WORKSPACE so that rules that download dependencies can use it, e.g. https://github.com/bazelbuild/rules_python#importing-pip-dependencies.py_runtime
works in same say way go rules do, which use the new toolchains idea it will be awesome.py_runtime
to an host binary path).The text was updated successfully, but these errors were encountered: