From ef907902c8aeb1b24fef97b6ecb45c182ade96a5 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sat, 6 Aug 2011 12:23:12 -0700 Subject: [PATCH] Better path surgery in autoreload --- tornado/autoreload.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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() -- 2.47.2