In the previous implementation, Jedi's traverse_parents function
traversed parent directories to the system root every time. This would
inadvertently add every folder to the system root every time. Obviously,
this is not the behavior desired for the import system.
This commit collects directories in an upward search until we:
1. Hit any directory without an __init__.py, AND
2. Are above self._path.
In the previous implementation, Jedi would's traverse_parents function
traversed parent directories to the system root every time. This would
inadvertently add every folder to the system root every time. Obviously,
this is not the behavior desired for the import system.
This pull request provides a new argument to the traverse_parents
function, "root", which represents the root parent for the search. This
argument defaults to None, thereby preserving the existing behavior of
the function.
I chose to duplicate some code for performance reasons. Since I'm trying
to avoid too much path manipulation magic, we do:
* a search to a valid specified root, OR
* a simple upward search until hitting the system root when there is no
valid root specified.
With this change we can now include all parents of the script, which will make
relative imports always work.
Now the whole meta_path is scanned and not just importlib's PathFinder.
Fixes#1183.