Fix #1108: Launch module from VSC broken in master (#1109)

Add '' to sys.path for -m and -c.

Make sure that sys.argv is properly updated by main(), even if input is a different list.
This commit is contained in:
Pavel Minaev 2019-01-17 15:02:36 -08:00 committed by GitHub
parent 72c549c6f5
commit f3289d040d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -256,6 +256,9 @@ def run_module():
if sys.version_info < (3,) and not isinstance(target, bytes): if sys.version_info < (3,) and not isinstance(target, bytes):
target = target.encode(sys.getfilesystemencoding()) target = target.encode(sys.getfilesystemencoding())
# Add current directory to path, like Python itself does for -m.
sys.path.insert(0, '')
# Docs say that runpy.run_module is equivalent to -m, but it's not actually # Docs say that runpy.run_module is equivalent to -m, but it's not actually
# the case for packages - -m sets __name__ to '__main__', but run_module sets # the case for packages - -m sets __name__ to '__main__', but run_module sets
# it to `pkg.__main__`. This breaks everything that uses the standard pattern # it to `pkg.__main__`. This breaks everything that uses the standard pattern
@ -270,6 +273,8 @@ def run_module():
def run_code(): def run_code():
# Add current directory to path, like Python itself does for -c.
sys.path.insert(0, '')
code = compile(ptvsd.options.target, '<string>', 'exec') code = compile(ptvsd.options.target, '<string>', 'exec')
setup_connection() setup_connection()
eval(code, {}) eval(code, {})
@ -321,7 +326,7 @@ ptvsd.enable_attach()
def main(argv=sys.argv): def main(argv=sys.argv):
try: try:
argv[:] = [argv[0]] + list(parse(argv[1:])) sys.argv[:] = [argv[0]] + list(parse(argv[1:]))
except Exception as ex: except Exception as ex:
print(HELP + '\nError: ' + str(ex), file=sys.stderr) print(HELP + '\nError: ' + str(ex), file=sys.stderr)
sys.exit(2) sys.exit(2)