From: Ben Darnell Date: Sat, 6 Aug 2011 19:23:12 +0000 (-0700) Subject: Better path surgery in autoreload X-Git-Tag: v2.1.0~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef907902c8aeb1b24fef97b6ecb45c182ade96a5;p=thirdparty%2Ftornado.git Better path surgery in autoreload --- diff --git a/tornado/autoreload.py b/tornado/autoreload.py index 7c3ddb5cf..a312ad3c6 100644 --- a/tornado/autoreload.py +++ b/tornado/autoreload.py @@ -203,6 +203,12 @@ if __name__ == "__main__": # the former to the latter, so subsequent executions won't have the same # path as the original. Modify os.environ here to ensure that the # re-executed process will have the same path. - if sys.path[0] == '': + # Conversely, when run as path/to/tornado/autoreload.py, the directory + # containing autoreload.py gets added to the path, but we don't want + # tornado modules importable at top level, so remove it. + if (sys.path[0] == '' and + not os.environ.get("PYTHONPATH", "").startswith(".:")): os.environ["PYTHONPATH"] = ".:" + os.environ.get("PYTHONPATH", "") + elif sys.path[0] == os.path.dirname(__file__): + del sys.path[0] main()