<s> import os <EOL> import sys <EOL> from jedi . _compatibility import exec_function , unicode <EOL> from jedi . parser import representation as pr <EOL> from jedi import debug <EOL> from jedi import common <EOL> def get_sys_path ( ) : <EOL> def check_virtual_env ( sys_path ) : <EOL> """<STR_LIT>""" <EOL> venv = os . getenv ( '<STR_LIT>' ) <EOL> if not venv : <EOL> return <EOL> venv = os . path . abspath ( venv ) <EOL> p = os . path . join ( <EOL> venv , '<STR_LIT>' , '<STR_LIT>' % sys . version_info [ : <NUM_LIT:2> ] , '<STR_LIT>' ) <EOL> sys_path . insert ( <NUM_LIT:0> , p ) <EOL> check_virtual_env ( sys . path ) <EOL> return [ p for p in sys . path if p != "<STR_LIT>" ] <EOL> def sys_path_with_modifications ( module ) : <EOL> def execute_code ( code ) : <EOL> c = "<STR_LIT>" <EOL> variables = { '<STR_LIT>' : module . path } <EOL> try : <EOL> exec_function ( c % code , variables ) <EOL> except Exception : <EOL> debug . warning ( '<STR_LIT>' ) <EOL> return None <EOL> try : <EOL> res = variables [ '<STR_LIT:result>' ] <EOL> if isinstance ( res , str ) : <EOL> return os . path . abspath ( res ) <EOL> else : <EOL> return None <EOL> except KeyError : <EOL> return None <EOL> def check_module ( module ) : <EOL> try : <EOL> possible_stmts = module . used_names [ '<STR_LIT:path>' ] <EOL> except KeyError : <EOL> return get_sys_path ( ) <EOL> sys_path = list ( get_sys_path ( ) ) <EOL> for p in possible_stmts : <EOL> if not isinstance ( p , pr . Statement ) : <EOL> continue <EOL> expression_list = p . expression_list ( ) <EOL> if len ( expression_list ) != <NUM_LIT:1> or not isinstance ( expression_list [ <NUM_LIT:0> ] , pr . Call ) : <EOL> continue <EOL> call = expression_list [ <NUM_LIT:0> ] <EOL> n = call . name <EOL> if not isinstance ( n , pr . Name ) or len ( n . names ) != <NUM_LIT:3> : <EOL> continue <EOL> if [ unicode ( x ) for x in n . names [ : <NUM_LIT:2> ] ] != [ '<STR_LIT>' , '<STR_LIT:path>' ] : <EOL> continue <EOL> array_cmd = unicode ( n . names [ <NUM_LIT:2> ] ) <EOL> if call . execution is None : <EOL> continue <EOL> exe = call . execution <EOL> if not ( array_cmd == '<STR_LIT>' and len ( exe ) == <NUM_LIT:2> <EOL> or array_cmd == '<STR_LIT>' and len ( exe ) == <NUM_LIT:1> ) : <EOL> continue <EOL> if array_cmd == '<STR_LIT>' : <EOL> exe_type , exe . type = exe . type , pr . Array . NOARRAY <EOL> exe_pop = exe . values . pop ( <NUM_LIT:0> ) <EOL> res = execute_code ( exe . get_code ( ) ) <EOL> if res is not None : <EOL> sys_path . insert ( <NUM_LIT:0> , res ) <EOL> debug . dbg ( '<STR_LIT>' , res ) <EOL> exe . type = exe_type <EOL> exe . values . insert ( <NUM_LIT:0> , exe_pop ) <EOL> elif array_cmd == '<STR_LIT>' : <EOL> res = execute_code ( exe . get_code ( ) ) <EOL> if res is not None : <EOL> sys_path . append ( res ) <EOL> debug . dbg ( '<STR_LIT>' , res ) <EOL> return sys_path <EOL> if module . path is None : <EOL> return list ( get_sys_path ( ) ) <EOL> curdir = os . path . abspath ( os . curdir ) <EOL> with common . ignored ( OSError ) : <EOL> os . chdir ( os . path . dirname ( module . path ) ) <EOL> result = check_module ( module ) <EOL> result += _detect_django_path ( module . path ) <EOL> os . chdir ( curdir ) <EOL> return result <EOL> def _detect_django_path ( module_path ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> while True : <EOL> new = os . path . dirname ( module_path ) <EOL> if new == module_path : <EOL> break <EOL> else : <EOL> module_path = new <EOL> with common . ignored ( IOError ) : <EOL> with open ( module_path + os . path . sep + '<STR_LIT>' ) : <EOL> debug . dbg ( '<STR_LIT>' , module_path ) <EOL> result . append ( module_path ) <EOL> return result </s>
