| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6e69e89 commit c765887
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | 5 | from __future__ import print_function | |
| 6 | 6 | import os | |
| 7 | + import os.path | ||
| 7 | 8 | import sys | |
| 8 | 9 | import code | |
| 9 | 10 | from optparse import OptionParser, OptionGroup | |
@@ -110,10 +111,15 @@ def exec_code(interpreter, args): | |||
| 110 | 111 | Helper to execute code in a given interpreter. args should be a [faked] | |
| 111 | 112 | sys.argv | |
| 112 | 113 | """ | |
| 113 | - with open(args[0], 'r') as sourcefile: | ||
| 114 | + plusmain = os.path.join(args[0], '__main__.py') | ||
| 115 | + if os.path.isdir(args[0]) and os.path.exists(plusmain): | ||
| 116 | + path = plusmain | ||
| 117 | + else: | ||
| 118 | + path = args[0] | ||
| 119 | + with open(path, 'r') as sourcefile: | ||
| 114 | 120 | source = sourcefile.read() | |
| 115 | 121 | old_argv, sys.argv = sys.argv, args | |
| 116 | - sys.path.insert(0, os.path.abspath(os.path.dirname(args[0]))) | ||
| 117 | - interpreter.locals['__file__'] = args[0] | ||
| 118 | - interpreter.runsource(source, args[0], 'exec') | ||
| 122 | + sys.path.insert(0, os.path.abspath(os.path.dirname(path))) | ||
| 123 | + interpreter.locals['__file__'] = path | ||
| 124 | + interpreter.runsource(source, path, 'exec') | ||
| 119 | 125 | sys.argv = old_argv | |
| Back | FazBrowse Home | New Git URL |
0 commit comments