Reduce dependencies for generated python wrapper in common cases. #15571
Labels
P3
We're not considering working on this, but happy to review a PR. (No assignee)
team-Rules-Python
Native rules for Python
type: feature request
Description of the feature request:
The python stub template used for
py_binary
andpy_test
imports a bunch of things which are not used in most common situations. I would like for those to only be imported as necessary.Specifically,
are only used if the template parameter
%is_zipfile%
isTrue
.subprocess
is mostly only used when running from a zip archive, but is also used on Windows or if%enable_host_version_warning%
isTrue
, which is maybe a sufficiently complex set of conditions to not warrant separating it out, sincesubprocess
is present inpython3-minimal
.It's also true that
re
is only used when not running from a zipfile, but again it's part ofpython3-minimal
so it's not as much of an issue as far as I'm concerned.What underlying problem are you trying to solve with this feature?
Python's processing of imports can take a non-negligible amount of time, when multiplied by thousands of tests in a large repo. More to the point, especially in remote build contexts it would be nice to be able to use e.g.
python3-minimal
rather than the fullpython3
, for smaller container images, which this change would permit.Which operating system are you running Bazel on?
Linux
What is the output of
bazel info release
?release 5.1.1
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse master; git rev-parse HEAD
?No response
Have you found anything relevant by searching the web?
See also bazelbuild/rules_python#673.
This would also be mostly solved with bazelbuild/rules_python#42, but that is more complex to implement than simply putting an
if
guard in front of a few of a fewimport
statements, and wouldn't address the performance cost of processing those additional imports.Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: