pipreqs
pipreqs copied to clipboard
Get the correct version when passed multiple paths
This emulates more closely the behavior of an actual import statement by:
- traversing
sys.path
in reverse so we keep the first module found. - checking if there is actually a module at
path / i_item
to avoid false positives.
I've checked both behaviors in concrete cases and they both match the python interpreter now, when previously they didn't.
An example where both 1. and 2. are necessary is when sys.path
is
'/usr/lib:/usr/local/lib/pythonX.Y/site-packages/:/usr/lib/pythonX.Y/site-packages/'
and different versions of the package are installed in the last two paths.
Notice how os.walk
will traverse '/lib/pythonX.Y/site-packages/' for the first path
('/usr/lib'), despite the fact that there's nothing to import from there, and that
traversing the paths in direct order would result in the last path overwriting the
version from the middle path, which comes first in import order.
Coverage remained the same at 88.679% when pulling 5d02bed770a537282e5fcb7d3ab1cec127dd6f40 on solstag:patch-1 into cb4add28efb73cc50892045ad60464e5583d3bfb on bndr:master.
Coverage remained the same at 88.679% when pulling 5d02bed770a537282e5fcb7d3ab1cec127dd6f40 on solstag:patch-1 into cb4add28efb73cc50892045ad60464e5583d3bfb on bndr:master.
Coverage remained the same at 88.679% when pulling 5d02bed770a537282e5fcb7d3ab1cec127dd6f40 on solstag:patch-1 into cb4add28efb73cc50892045ad60464e5583d3bfb on bndr:master.
Coverage remained the same at 88.679% when pulling 5d02bed770a537282e5fcb7d3ab1cec127dd6f40 on solstag:patch-1 into cb4add28efb73cc50892045ad60464e5583d3bfb on bndr:master.
Ni! Looking at current code it seems this PR is no longer needed. Closing.