-
-
Notifications
You must be signed in to change notification settings - Fork 643
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
Support with suppress(ImportError):
in python dependency inference
#17691
Comments
This is a good suggestion! It might not be too hard to modify the dep parser to do this, if you want to take a swing at it. The crucial file is https://github.com/pantsbuild/pants/blob/68894b9918d4a1d4802888238f03cbc0c68e9bfd/src/python/pants/backend/python/dependency_inference/scripts/dependency_parser_py |
The important thing to me is that we'd support both |
Something I suggested in slack is if we just start using kbcst or equivalent |
It would be easy to check for However, I think that protecting from all possible complications goes too far and would be out of scope for this issue. I mean things like making sure the correct |
By the way, I'd prefer to also add an advanced option to Would an option |
That's a really interesting idea! I'd be open to such an option. The main thing would be that the script has to be completely self-contained (no dependencies outside the stdlib). But that seems like a reasonable constraint, at least initially. |
We should probably move that discussion somewhere else. Like a discussion 😄 |
Opened discussion #17702 for this. Although the support for |
Well everyone could benefit from the |
Yes, of course. I only thought that if a custom parser can/should be implemented, it would also make the development for this issue a bit easier. If the discussion on the details takes too long, it's easier to solve this independently. |
I agree that it wouldn't be necessary to track what the |
So I think adding support for suppress in the standard script makes sense. |
You can invoke the script directly (as of today), which is how I test this quickly. The comment at the top mentions this a bit. |
I'm not sure I agree. |
We would be looking for exactly this:
I think the intention there is very unambiguous. If that does not, in fact, suppress the import error, then the author is playing with fire... |
fixes #17691 also: - fixes the case of nested weakenings - bumps tree-sitter-python to an unreleased version (last release was a year ago) - rebuilds the generation of tree-sitter node types to support multiple symbols for a name
fixes #17691 also: - fixes the case of nested weakenings - bumps tree-sitter-python to an unreleased version (last release was a year ago) - rebuilds the generation of tree-sitter node types to support multiple symbols for a name
fixes #17691 also: - fixes the case of nested weakenings - bumps tree-sitter-python to an unreleased version (last release was a year ago) - rebuilds the generation of tree-sitter node types to support multiple symbols for a name
#19293) (#19788) fixes #17691 and fixes #19751 also: - fixes the case of nested weakenings - bumps tree-sitter-python to an unreleased version (last release was a year ago) - rebuilds the generation of tree-sitter node types to support multiple symbols for a name Co-authored-by: Daniel Goldman <danielgoldman4@gmail.com> Co-authored-by: Huon Wilson <huon@exoflare.io>
#19293) (#19789) fixes #17691 and fixes #19751 also: - fixes the case of nested weakenings - bumps tree-sitter-python to an unreleased version (last release was a year ago) - rebuilds the generation of tree-sitter node types to support multiple symbols for a name --------- Co-authored-by: Daniel Goldman <danielgoldman4@gmail.com>
Is your feature request related to a problem? Please describe.
Currently the python dependency inference of
pants
takes into account any imports within atry/except ImportError
block and marks them as "weak" dependencies, e.g. skipping the warning if they are not provided by any requirement. Using the equivalentwith contextlib.suppress(ImportError):
, the dependencies are marked as "strong" and a warning is printed.Describe the solution you'd like
Detect
with contextlib.suppress(ImportError):
orfrom contextlib import suppress; ...; with suppress(ImportError):
in the dependency parser and handle those dependencies as weak.Describe alternatives you've considered
Alternatively, to allow more freedom for special cases in user code, make the dependency parser configurable either through options of
python-infer
or a plugin interface.I experimented a bit with the latter, but could not override the default dependency parser without too much boilerplate code or wrapping of pants classes. However this might be because I'm not familiar with writing plugins.
Additional context
Tested with pants 2.14.0.
Please give feedback on what solution would be preferable.
The text was updated successfully, but these errors were encountered: