-
Notifications
You must be signed in to change notification settings - Fork 540
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
using all_requirements causes OSError: [Errno 7] Argument list too long #792
Comments
This is an issue with the upstream native bazel rules not rules_python. The problem is that the PYTHONPATH set by the python_stub_template is longer than the allowed system limits. You can try to set |
@hrfuller, the issue happens doesn't exist with |
Our team can confirm this behavior/bug in our environment, although we have yet to make an easily reproduceable and shareable example. Additionally, the situation appears even more complicated and subtle as it depends on the host machine configuration (aka some VMs throw the error for some targets while others do not). We think this is related to perhaps different ulimits/max arg limits across machines with different memory amounts and settings. Having said that, our very large CI machines do exhibit the issue while some random developer VMs appear to not, so it's not strictly a "sizing" issue. If it were possible to simply update an OS setting without recompiling the kernel we would be happy with that as a reasonable solution. Finally, for some background, our team does not use the We'd love to help however possible with a fix. There are exciting features after |
Some further updates.
We'll try to dig in more as to exactly what specifically could have caused this from the commit. |
Just for context, all_requirements is considered a bit of an anti-pattern. Is there a way for you to explicitly list your dependencies instead? Does the same error occur? |
@groodt I just read your comment #715 (comment) and it seems very similar to our situation, except you get lucky and go just under the limit. As I mentioned in my ugly wall of text 🙃 we do not use the Really appreciate your time and efforts on this all! |
@groodt , on the |
Also, using the flag |
@anuragkanungo Yes, it's still an antipattern though. You can build tooling outside the rules to enumerate things explicitly if you need to. |
This appears to be a subtle bug arising from some latent assumptions between rules_python and the upstream bazel native python_stub_template. The change effectively doubles the length of the This occurs, afaict, b/c the template's But this is no longer valid as the modules from Thus the For many users, this may not matter, but it seems to be an unintended side effect and at worst could be viewed as an incompatibility between rules_python and upstream bazel, if we understand things correctly. If this summary is accurate, we're not clear exactly what the best next steps would be. We've found roughly 4 variables one can tweak to try and sneak under the limit if one finds themselves in the situation.
We haven't been able to make an easy test for this yet, but I imagine if one did the opposite of the suggestions (go larger for each rather than smaller) on a moderately sized package they could reproduce the error. |
Just to make sure I understand the situation: The basic problem is that, as a side-effect of using pip_parse (or pip_install?), many repos are created, and they end up on PYTHONPATH, and make it too long. These repos are just internal, implementation details. They don't need to be added to PYTHONPATH. Is the above correct?
The basic side effect is that every immediate-sub directory under the runfiles root will no longer be added to PYTHONPATH. see here The basic implication here is that Python libraries that don't include their repo name in their import statements will break. Python libraries that do include their repo name in their import statements will be OK. edit: I should clarify this is the case ignoring when something else adding things to PYTHONPATH, such as e.g. i.e.,:
Before, "import mylib1" and "import other_libs" would work. After, they will no longer work. Whether this matters or not depends on what the code in a repo expects -- "import more_repo.morelib" works in both cases, for example. Technically, you can work around this by setting e.g. But, understandably, this is not an appealing option if you have a lot of targets. It's also problematic if you have a dependency you don't control. I have some ideas that might help solve this, but gtg now.
The execve manpage says that the env limits are based on the stack size ulimit. So you can you probably do e.g.
Is there something we can change in the rules_python bzl code to also shorten these paths as a mitigation measure that would help?
The real root causes all lie in native.py_*. The repo name should never have been so tightly coupled to the Python import name, the repo roots should never have been always added to PYTHONPATH, and PYTHONPATH should never have had the closure of dependencies appended into it. As someone said upthread, the real fix for this is a site-packages like layout (or equiv) so that PYTHONPATH and sys.path don't have to scale with the dependency closure size. I've been talking to the Bazel team internally making the point that to do this efficiently, Bazel core needs some sort of feature to allow better control over where things are put within runfiles. (This might be a bit of cold-comfort insofar as rules_python is concerned, but I still think it's worth calling out to get fixed; I brought this up internally this week, actually) Ultimately, I think you want to enable that flag to remove the repo roots from path. The question then becomes how to get any imports that rely on the repo name working again. I have a couple ideas that we might be able to do on the rules_python Starlark side, but gtg right now. |
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. |
This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?" |
🐞 bug report
Affected Rule
The issue is caused by the rule:
all_requirements
Is this a regression?
Yes, the previous version in which this bug was not present was: 0.9.0
The bug exists in : 0.10.2 and 0.11.0
Description
When using
all_requirements
in a rule likeIt cause the error
🌍 Your Environment
Operating System: Ubuntu 20.04
Output of
bazel version
: 5.2.0The text was updated successfully, but these errors were encountered: