Skip to content
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

Reduce dependencies for generated python wrapper in common cases. #15571

Closed
adam-azarchs opened this issue May 25, 2022 · 0 comments
Closed

Reduce dependencies for generated python wrapper in common cases. #15571

adam-azarchs opened this issue May 25, 2022 · 0 comments
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

Comments

@adam-azarchs
Copy link
Contributor

Description of the feature request:

The python stub template used for py_binary and py_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,

import shutil
import tempfile
import zipfile

are only used if the template parameter %is_zipfile% is True.

subprocess is mostly only used when running from a zip archive, but is also used on Windows or if %enable_host_version_warning% is True, which is maybe a sufficiently complex set of conditions to not warrant separating it out, since subprocess is present in python3-minimal.

It's also true that re is only used when not running from a zipfile, but again it's part of python3-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 full python3, 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 returns development 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 few import 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

@comius comius added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@comius @adam-azarchs and others