hundreds-father-404
05/05/2022, 8:58 PM[python-infer].unowned_dependency_behavior = "error"
, which errors when a dependency cannot be inferred.
We're thinking of defaulting to warning or error because this error is hopefully much better than a cryptic runtime ModuleNotFoundErrror
Feedback welcomed!hundreds-father-404
05/05/2022, 8:58 PM# pants: no-infer-dep
to the import line.
Is the import from a third-party dependency (see https://www.pantsbuild.org/v2.12/docs/python-third-party-dependencies)? Some common issues:
• Pants does not know about the requirement, i.e. there is not a python_requirement
target for it. You can run ./pants filter --target-type=python_requirement ::
to see all python_requirement
targets. If you are using requirements.txt
, Poetry, or Pipenv, make sure you have python_requirements
, poetry_requirements
, and pipenv_requirements
target generators, respectively. Double check that the requirement is in the respective file like requirements.txt
.
• The third-party requirement exposes modules different than Pants's default, e.g. ansicolors
exposing colors
. Set the modules
or module_mapping
fields.
• Ambiguity. See below.
Is the import from first-party code? Some common issues:
• The file does not exist.
• The file is missing an owning target like python_sources
. Run ./pants list path/to/file.py
to see if there are any owners. If not, run ./pants tailor
to generate targets.
• The source root is not correctly set up, which is how Pants knows for example that the file src/py/my_project/app.py
exposes the module <http://my_project.app|my_project.app>
. See https://www.pantsbuild.org/v2.12/docs/source-roots.
• Ambiguity. See below.
Some common issues with both first and third-party imports:
• Ambiguity. See above logs if there are warnings and instructions.hundreds-father-404
05/05/2022, 8:59 PMhundreds-father-404
05/05/2022, 9:00 PMresolve=
field for whichever target provides that import (and possibly use the parametrize
mechanism if that code should work with multiple resolves). See https://www.pantsbuild.org/v2.12/docs/python-third-party-dependencies#multiple-lockfiles.hundreds-father-404
05/05/2022, 9:01 PMwitty-crayon-22786
05/05/2022, 9:29 PMI’m thinking of how we can improve the multiple resolves situation, like if we can dynamically detect if there is that import but inside another resolvewe should i think… it’s really cheap to do.
hundreds-father-404
05/05/2022, 9:30 PMwitty-crayon-22786
05/05/2022, 9:30 PMhundreds-father-404
05/05/2022, 9:31 PMwitty-crayon-22786
05/05/2022, 9:33 PMWould you agree that if the module is another resolve, that is realistically the only likely cause of the failure?about a 95% chance, yea? there are overlap cases where it might be that you meant to use some sources instead of thirdparty, for example… but yea.
witty-crayon-22786
05/05/2022, 9:34 PMhundreds-father-404
05/05/2022, 9:34 PMwitty-crayon-22786
05/05/2022, 9:35 PMhundreds-father-404
05/05/2022, 9:36 PMgiven that, is https://github.com/pantsbuild/pants/pull/15334 ready, or should we wait?Totally depends how we want to approach the intersection of
unowned_dependency_behavior
and multiple resolves: to get this helpful error message for multiple resolves, do you need to have on that option?
Otherwise, we would need Yet Another warning/log and probably an option to toggle the behavior. Oofhundreds-father-404
05/05/2022, 9:36 PMunowned_dependency_behavior
in 2.11. But we can still make this improvement and then encourage users w/ multiple lockfiles to manually turn it on
2.12+ can deprecate the current default of ignorewitty-crayon-22786
05/05/2022, 9:36 PMunowned_dependency_behavior
by default? i think that we should consider it.hundreds-father-404
05/05/2022, 9:37 PMunowned_dependency_behavior
w/ multiple resolveshundreds-father-404
05/05/2022, 9:37 PMwhere are we on enabling unowned_dependency_behavior by default? i think that we should consider it.Extremely strong +1 from me. I think this is such a better experience than a ModuleError @bitter-ability-32190 over DM was +1, but not sure between error vs warn
witty-crayon-22786
05/05/2022, 9:37 PMwitty-crayon-22786
05/05/2022, 9:38 PMhundreds-father-404
05/05/2022, 9:38 PMi don’t know about coupling it per-seThe error message about multiple resolves has to come somewhere. What I'm suggested is it be included in the error message from
unownded_dependency_behavior
.
Do not invent yet another error message/logwitty-crayon-22786
05/05/2022, 9:39 PMhundreds-father-404
05/05/2022, 9:39 PMIMO, until we have a way to render all of the errors, we shouldn’t make it an error by default. too much of a pain for new users.I wonder how we could pull that off. I think we'd need to make the dependency inference plugin hook have a fallible component where you can insert *lazy error messages?
witty-crayon-22786
05/05/2022, 9:40 PMI wonder how we could pull that off.i’ve had some ideas recently (related to collecting atomic sideeffects via EngineAwareReturnType, and then committing them at the end of the run). but i don’t think that it needs to be tackled here.
hundreds-father-404
05/05/2022, 9:40 PMbitter-ability-32190
05/05/2022, 9:42 PMbitter-ability-32190
05/05/2022, 9:43 PMhundreds-father-404
05/05/2022, 9:43 PMwitty-crayon-22786
05/05/2022, 9:44 PMAgreed the repetitively iterative nature of the errors though is roughyea: that’s why not errors until we solve that problem. mentioned above (and elaborated since) that i’ve had some thoughts on it
hundreds-father-404
05/05/2022, 9:44 PMAgreed the repetitively iterative nature of the errors though is roughOn the other hand, what if you get 100 errors but fixing 1 would fix 90 of them. You give up because 100 is overwhelming?
hundreds-father-404
05/05/2022, 9:47 PMbitter-ability-32190
05/05/2022, 10:01 PMwitty-crayon-22786
05/05/2022, 10:08 PMwitty-crayon-22786
05/05/2022, 10:10 PMwitty-crayon-22786
05/09/2022, 8:20 PMi’ve had some ideas recently (related to collecting atomic sideeffects via EngineAwareReturnType, and then committing them at the end of the run).elaborated here: https://github.com/pantsbuild/pants/issues/15350#issuecomment-1121536968