forked from VimPlug/jedi
Add the travere_parents function to a utility directory
This commit is contained in:
@@ -8,7 +8,7 @@ from jedi.api.exceptions import WrongVersion
|
|||||||
from jedi._compatibility import force_unicode
|
from jedi._compatibility import force_unicode
|
||||||
from jedi.evaluate.sys_path import discover_buildout_paths
|
from jedi.evaluate.sys_path import discover_buildout_paths
|
||||||
from jedi.evaluate.cache import evaluator_as_method_param_cache
|
from jedi.evaluate.cache import evaluator_as_method_param_cache
|
||||||
from jedi.evaluate.sys_path import traverse_parents
|
from jedi.common.utils import traverse_parents
|
||||||
|
|
||||||
_CONFIG_FOLDER = '.jedi'
|
_CONFIG_FOLDER = '.jedi'
|
||||||
_CONTAINS_POTENTIAL_PROJECT = 'setup.py', '.git', '.hg', 'MANIFEST.in'
|
_CONTAINS_POTENTIAL_PROJECT = 'setup.py', '.git', '.hg', 'MANIFEST.in'
|
||||||
|
|||||||
12
jedi/common/utils.py
Normal file
12
jedi/common/utils.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def traverse_parents(path, include_current=False):
|
||||||
|
if not include_current:
|
||||||
|
path = os.path.dirname(path)
|
||||||
|
|
||||||
|
previous = None
|
||||||
|
while previous != path:
|
||||||
|
yield path
|
||||||
|
previous = path
|
||||||
|
path = os.path.dirname(path)
|
||||||
@@ -5,9 +5,9 @@ from jedi._compatibility import unicode, force_unicode
|
|||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
from jedi.evaluate.base_context import ContextualizedNode
|
from jedi.evaluate.base_context import ContextualizedNode
|
||||||
from jedi.evaluate.helpers import is_string
|
from jedi.evaluate.helpers import is_string
|
||||||
|
from jedi.common.utils import traverse_parents
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.evaluate.utils import ignored
|
|
||||||
|
|
||||||
|
|
||||||
def _abs_path(module_context, path):
|
def _abs_path(module_context, path):
|
||||||
@@ -160,17 +160,6 @@ def _get_paths_from_buildout_script(evaluator, buildout_script_path):
|
|||||||
yield path
|
yield path
|
||||||
|
|
||||||
|
|
||||||
def traverse_parents(path, include_current=False):
|
|
||||||
if not include_current:
|
|
||||||
path = os.path.dirname(path)
|
|
||||||
|
|
||||||
previous = None
|
|
||||||
while previous != path:
|
|
||||||
yield path
|
|
||||||
previous = path
|
|
||||||
path = os.path.dirname(path)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_parent_dir_with_file(path, filename):
|
def _get_parent_dir_with_file(path, filename):
|
||||||
for parent in traverse_parents(path):
|
for parent in traverse_parents(path):
|
||||||
if os.path.isfile(os.path.join(parent, filename)):
|
if os.path.isfile(os.path.join(parent, filename)):
|
||||||
|
|||||||
Reference in New Issue
Block a user