mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
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:
parent
72c549c6f5
commit
f3289d040d
1 changed files with 6 additions and 1 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue