From f42ed9277e9d101cbca8f320de1951975ff7331f Mon Sep 17 00:00:00 2001 From: David Halter Date: Tue, 2 Oct 2012 17:57:36 +0200 Subject: [PATCH] Add Django project root to PYTHONPATH - fixes #22 --- jedi/modules.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/jedi/modules.py b/jedi/modules.py index 744e4f0c..77a192a3 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -209,7 +209,7 @@ def sys_path_with_modifications(module): try: possible_stmts = module.used_names['path'] except KeyError: - return builtin.module_find_path + return list(builtin.module_find_path) sys_path = list(builtin.module_find_path) # copy for p in possible_stmts: @@ -251,7 +251,28 @@ def sys_path_with_modifications(module): pass result = check_module(module) + result += detect_django_path(module.path) # cleanup, back to old directory os.chdir(curdir) return result + + +def detect_django_path(module_path): + """ Detects the path of the very well known Django library (if used) """ + result = [] + while True: + new = os.path.dirname(module_path) + # If the module_path doesn't change anymore, we're finished -> / + if new == module_path: + break + else: + module_path = new + + try: + with open(module_path + os.path.sep + 'manage.py'): + debug.dbg('Found django path: %s' % module_path) + result.append(module_path) + except IOError: + pass + return result