<#17691 Support `with suppress(ImportError):` in p...
# github-notifications
q
#17691 Support `with suppress(ImportError):` in python dependency inference New issue created by dbari Is your feature request related to a problem? Please describe. Currently the python dependency inference of
pants
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