mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
Use generators instead of complicated return of lists
This commit is contained in:
@@ -189,24 +189,23 @@ def _get_buildout_script_paths(module_path):
|
|||||||
"""
|
"""
|
||||||
project_root = _get_parent_dir_with_file(module_path, 'buildout.cfg')
|
project_root = _get_parent_dir_with_file(module_path, 'buildout.cfg')
|
||||||
if not project_root:
|
if not project_root:
|
||||||
return []
|
return
|
||||||
bin_path = os.path.join(project_root, 'bin')
|
bin_path = os.path.join(project_root, 'bin')
|
||||||
if not os.path.exists(bin_path):
|
if not os.path.exists(bin_path):
|
||||||
return []
|
return
|
||||||
extra_module_paths = []
|
|
||||||
for filename in os.listdir(bin_path):
|
for filename in os.listdir(bin_path):
|
||||||
try:
|
try:
|
||||||
filepath = os.path.join(bin_path, filename)
|
filepath = os.path.join(bin_path, filename)
|
||||||
with open(filepath, 'r') as f:
|
with open(filepath, 'r') as f:
|
||||||
firstline = f.readline()
|
firstline = f.readline()
|
||||||
if firstline.startswith('#!') and 'python' in firstline:
|
if firstline.startswith('#!') and 'python' in firstline:
|
||||||
extra_module_paths.append(filepath)
|
yield filepath
|
||||||
except (UnicodeDecodeError, IOError) as e:
|
except (UnicodeDecodeError, IOError) as e:
|
||||||
# Probably a binary file; permission error or race cond. because file got deleted
|
# Probably a binary file; permission error or race cond. because
|
||||||
# ignore
|
# file got deleted. Ignore it.
|
||||||
debug.warning(unicode(e))
|
debug.warning(unicode(e))
|
||||||
continue
|
continue
|
||||||
return extra_module_paths
|
|
||||||
|
|
||||||
|
|
||||||
def dotted_path_in_sys_path(sys_path, module_path):
|
def dotted_path_in_sys_path(sys_path, module_path):
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ def test_parent_dir_with_file(Script):
|
|||||||
|
|
||||||
@cwd_at('test/test_evaluate/buildout_project/src/proj_name')
|
@cwd_at('test/test_evaluate/buildout_project/src/proj_name')
|
||||||
def test_buildout_detection(Script):
|
def test_buildout_detection(Script):
|
||||||
scripts = _get_buildout_script_paths(os.path.abspath('./module_name.py'))
|
scripts = list(_get_buildout_script_paths(os.path.abspath('./module_name.py')))
|
||||||
assert len(scripts) == 1
|
assert len(scripts) == 1
|
||||||
curdir = os.path.abspath(os.curdir)
|
curdir = os.path.abspath(os.curdir)
|
||||||
appdir_path = os.path.normpath(os.path.join(curdir, '../../bin/app'))
|
appdir_path = os.path.normpath(os.path.join(curdir, '../../bin/app'))
|
||||||
|
|||||||
Reference in New Issue
Block a user