def sys_path_with_modifications(self): sys_path_mod = self._evaluator.get_sys_path() \ + sys_path.check_sys_path_modifications(self.module_context) if self.import_path and self.file_path is not None \ and self._evaluator.environment.version_info.major == 2: # Python2 uses an old strange way of importing relative imports. sys_path_mod.append(force_unicode(os.path.dirname(self.file_path))) return sys_path_mod
def _sys_path_with_modifications(self): if self._fixed_sys_path is not None: return self._fixed_sys_path sys_path_mod = ( self._evaluator.get_sys_path() + sys_path.check_sys_path_modifications(self.module_context)) if self._evaluator.environment.version_info.major == 2: file_path = self.module_context.py__file__() if file_path is not None: # Python2 uses an old strange way of importing relative imports. sys_path_mod.append(force_unicode(os.path.dirname(file_path))) return sys_path_mod
def sys_path_with_modifications(self): in_path = [] sys_path_mod = self._evaluator.project.sys_path \ + sys_path.check_sys_path_modifications(self.module_context) if self.file_path is not None: # If you edit e.g. gunicorn, there will be imports like this: # `from gunicorn import something`. But gunicorn is not in the # sys.path. Therefore look if gunicorn is a parent directory, #56. if self.import_path: # TODO is this check really needed? for path in sys_path.traverse_parents(self.file_path): if os.path.basename(path) == self.str_import_path[0]: in_path.append(os.path.dirname(path)) # Since we know nothing about the call location of the sys.path, # it's a possibility that the current directory is the origin of # the Python execution. sys_path_mod.append(os.path.dirname(self.file_path)) return in_path + sys_path_mod
def check_module_test(code): module_context = Script(code)._get_module() return check_sys_path_modifications(module_context)
def check_module_test(Script, code): module_context = Script(code)._get_module() return check_sys_path_modifications(module_context)