pipreqs icon indicating copy to clipboard operation
pipreqs copied to clipboard

Get the correct version when passed multiple paths

Open solstag opened this issue 3 years ago • 4 comments

This emulates more closely the behavior of an actual import statement by:

  1. traversing sys.path in reverse so we keep the first module found.
  2. 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.

solstag avatar Apr 26 '21 23:04 solstag

Coverage Status

Coverage remained the same at 88.679% when pulling 5d02bed770a537282e5fcb7d3ab1cec127dd6f40 on solstag:patch-1 into cb4add28efb73cc50892045ad60464e5583d3bfb on bndr:master.

coveralls avatar Apr 26 '21 23:04 coveralls

Coverage Status

Coverage remained the same at 88.679% when pulling 5d02bed770a537282e5fcb7d3ab1cec127dd6f40 on solstag:patch-1 into cb4add28efb73cc50892045ad60464e5583d3bfb on bndr:master.

coveralls avatar Apr 26 '21 23:04 coveralls

Coverage Status

Coverage remained the same at 88.679% when pulling 5d02bed770a537282e5fcb7d3ab1cec127dd6f40 on solstag:patch-1 into cb4add28efb73cc50892045ad60464e5583d3bfb on bndr:master.

coveralls avatar Apr 26 '21 23:04 coveralls

Coverage Status

Coverage remained the same at 88.679% when pulling 5d02bed770a537282e5fcb7d3ab1cec127dd6f40 on solstag:patch-1 into cb4add28efb73cc50892045ad60464e5583d3bfb on bndr:master.

coveralls avatar Apr 26 '21 23:04 coveralls

Ni! Looking at current code it seems this PR is no longer needed. Closing.

solstag avatar Oct 07 '23 23:10 solstag