Discover fixes

Backport the fix for discovery in packages from Python bugtracker.