]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Better path surgery in autoreload
authorBen Darnell <ben@bendarnell.com>
Sat, 6 Aug 2011 19:23:12 +0000 (12:23 -0700)
committerBen Darnell <ben@bendarnell.com>
Sat, 6 Aug 2011 19:23:12 +0000 (12:23 -0700)
tornado/autoreload.py

index 7c3ddb5cf747b3445b49274daf0a0c747a7745d7..a312ad3c6e84a778ad15f3ff860a26ab6d7731b3 100644 (file)
@@ -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()