-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Lots of repositories cause "Argument list too long" for py_binary #14640
Comments
This can also happen when the $TMPDIR location is long so that the absolute paths to the import locations are long. Even with only python repos on the PYTHONPATH you can exceed this limit. |
This can also happen when you are using the |
So what would be solution for this? |
The long term solution is to use the site packages import mechanism for external repos instead of PYTHONPATH. |
@arunkant I included two workarounds in my bug report: #14640 (comment) The first is better than the second, unless you are using third-party Python targets, e.g. in rules_docker. |
Any workaround for rules_docker? |
How to do that? @hrfuller any docs or config I can use. We are migrating our codebase to monorepo and consolidate all python deps at one location and I don't want all that effort to be blocked by this issue |
@arunkant in that case, see my second workaround: use usercustomize.py. Monkeypatch |
Thanks @pauldraper. That looks reasonable workaround. I'll try it |
I hit this issue recently which took a while to debug. Any plan to have it fixed? In fact if the |
The way to fix it is to have everyone make their rules compatible with |
@arunkant rules_docker merged this which fixes |
If you're running the latest
You can grab the patch file with: % gh pr diff https://github.com/bazelbuild/rules_docker/pull/2171 > github.com_bazelbuild_rules_docker_pull_2171.patch |
Problem
The Python wrapper is finding every repository in the runfiles tree, creating a huge PYTHONPATH variable, and then crashing when it exceeds the system's env var limits.
I encountered this on Ubuntu 20.04, Python 3.8.
A large number (hundreds) of external repositories is quite possible with Maven and npm projects. In my case, I have utility tools written in Python used in the runtime tree of a Node.js binary (that pulls in npm repositories).
Solution
Ideally,
py_binary
would only add Python dependencies to the PYTHONPATH. Besides prevent a crash, it's also more efficient for loading modules.Workarounds
import_all
An undocumented option
--experimental_python_import_all_repositories=false
prevents automatically adding these repositories.However, it requires specifying the
imports
attribute, at least in some executions contexts, and of course the general Bazel ecosystem (e.g. rules_docker) doesn't do that.usercustomize
Use usercustomize to change PYTHONPATH when execv is run.
~/.local/lib/python3.8/site-packages/usercustomize.py
The text was updated successfully, but these errors were encountered: