quaint-telephone-89068
11/30/2022, 2:29 PMpants takes into account any imports within a try/except ImportError block and marks them as "weak" dependencies, e.g. skipping the warning if they are not provided by any requirement. Using the equivalent with 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): or from 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.
pantsbuild/pants