3 ms·
Common? Yes. Canonical/ideal? No. Optional dependency specifiers in your package metadata is a much better way to go. You can use those even if you don't publis
by zbentley 1mo ago
Common? Yes. Canonical/ideal? No. Optional dependency specifiers in your package metadata is a much better way to go. You can use those even if you don't publish your package as an artifact; `pip install -e .[optional-thing]` should work, or can be made to, easily.
- rtpg 1mo agoThat's only part of the puzzle. Your program needs to branch on whether the dependency is installed or not! "Oh you don't have optional dependency? Then do X" needs to happen at runtime right?
- zbentley 29d agoI explained further here: https://news.ycombinator.com/item?id=49604462 https://news.ycombinator.com/item?id=49604462 In my preference order: an explicit CLI option/envvar which requires the optional dep, a flag file on the filesystem, or an ImportError attempt if you absolutely must. Use a stub/trampoline file in the conditionals so that static analyzers and laziness analysis on that file itself still work.