Here are the examples of the python api sys.original_argv taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
8 Examples
3
Example 1
Project: PyDev.Debugger Source File: test_pydev_monkey.py
def test_monkey(self):
original = SetupHolder.setup
try:
SetupHolder.setup = {'client':'127.0.0.1', 'port': '0'}
check='''C:\\bin\\python.exe -u -c "
connect(\\"127.0.0.1\\")
"'''
sys.original_argv = []
self.assertEqual(
'"C:\\bin\\python.exe" "-u" "-c" "import sys; '
'sys.path.append(r\'%s\'); '
'import pydevd; pydevd.settrace(host=\'127.0.0.1\', port=0, suspend=False, '
'trace_only_current_thread=False, patch_multiprocessing=True); '
'\nconnect(\\"127.0.0.1\\")\n"' % pydev_src_dir,
pydev_monkey.patch_arg_str_win(check)
)
finally:
SetupHolder.setup = original
3
Example 2
Project: PyDev.Debugger Source File: test_pydev_monkey.py
def test_monkey_patch_args_indc(self):
original = SetupHolder.setup
try:
SetupHolder.setup = {'client':'127.0.0.1', 'port': '0'}
check=['C:\\bin\\python.exe', '-u', '-c', 'connect(\\"127.0.0.1\\")']
sys.original_argv = []
self.assertEqual(pydev_monkey.patch_args(check), [
'C:\\bin\\python.exe',
'-u',
'-c',
(
'import sys; sys.path.append(r\'%s\'); import pydevd; '
'pydevd.settrace(host=\'127.0.0.1\', port=0, suspend=False, trace_only_current_thread=False, patch_multiprocessing=True); '
'connect(\\"127.0.0.1\\")'
) % pydev_src_dir
])
finally:
SetupHolder.setup = original
3
Example 3
Project: PyDev.Debugger Source File: test_pydev_monkey.py
def test_monkey_patch_args_no_indc(self):
original = SetupHolder.setup
try:
SetupHolder.setup = {'client':'127.0.0.1', 'port': '0'}
check=['C:\\bin\\python.exe', 'connect(\\"127.0.0.1\\")']
sys.original_argv = ['my', 'original', 'argv']
if sys.platform == 'win32':
self.assertEqual(pydev_monkey.patch_args(check), [
'C:\\bin\\python.exe', '"my"', '"original"', '"argv"', 'connect(\\"127.0.0.1\\")'])
else:
self.assertEqual(pydev_monkey.patch_args(check), [
'C:\\bin\\python.exe', 'my', 'original', 'argv', 'connect(\\"127.0.0.1\\")'])
finally:
SetupHolder.setup = original
3
Example 4
Project: PyDev.Debugger Source File: test_pydev_monkey.py
def test_monkey_patch_args_no_indc_with_pydevd(self):
original = SetupHolder.setup
try:
SetupHolder.setup = {'client':'127.0.0.1', 'port': '0'}
check=['C:\\bin\\python.exe', 'pydevd.py', 'connect(\\"127.0.0.1\\")', 'bar']
sys.original_argv = ['my', 'original', 'argv']
self.assertEqual(pydev_monkey.patch_args(check), [
'C:\\bin\\python.exe', 'pydevd.py', 'connect(\\"127.0.0.1\\")', 'bar'])
finally:
SetupHolder.setup = original
0
Example 5
Project: PyDev.Debugger Source File: test_pydev_monkey.py
def test_monkey_patch_args_module(self):
original = SetupHolder.setup
try:
SetupHolder.setup = {'client':'127.0.0.1', 'port': '0'}
check=['C:\\bin\\python.exe', '-m', 'test']
sys.original_argv = ['pydevd', '--multiprocess']
if sys.platform == 'win32':
self.assertEqual(pydev_monkey.patch_args(check), [
'C:\\bin\\python.exe',
'"pydevd"',
'"--module"',
'"--multiprocess"',
'test',
])
else:
self.assertEqual(pydev_monkey.patch_args(check), [
'C:\\bin\\python.exe',
'pydevd',
'--module',
'--multiprocess',
'test',
])
finally:
SetupHolder.setup = original
0
Example 6
Project: PyDev.Debugger Source File: test_pydev_monkey.py
def test_monkey_patch_args_no_indc_without_pydevd(self):
original = SetupHolder.setup
try:
SetupHolder.setup = {'client':'127.0.0.1', 'port': '0'}
check=['C:\\bin\\python.exe', 'target.py', 'connect(\\"127.0.0.1\\")', 'bar']
sys.original_argv = ['pydevd.py', '--a=1', 'b', '--c=2', '--file', 'ignore_this.py']
if sys.platform == 'win32':
self.assertEqual(pydev_monkey.patch_args(check), [
'C:\\bin\\python.exe',
'"pydevd.py"',
'"--a=1"',
'"b"',
'"--c=2"',
'"--file"',
'target.py',
'connect(\\"127.0.0.1\\")',
'bar',
])
else:
self.assertEqual(pydev_monkey.patch_args(check), [
'C:\\bin\\python.exe',
'pydevd.py',
'--a=1',
'b',
'--c=2',
'--file',
'target.py',
'connect(\\"127.0.0.1\\")',
'bar',
])
finally:
SetupHolder.setup = original
0
Example 7
def patch_args(args):
try:
log_debug("Patching args: %s"% str(args))
import sys
new_args = []
i = 0
if len(args) == 0:
return args
if is_python(args[0]):
try:
indC = args.index('-c')
except ValueError:
indC = -1
if indC != -1:
host, port = _get_host_port()
if port is not None:
new_args.extend(args)
new_args[indC + 1] = _get_python_c_args(host, port, indC, args)
return new_args
else:
# Check for Python ZIP Applications and don't patch the args for them.
# Assumes the first non `-<flag>` argument is what we need to check.
# There's probably a better way to determine this but it works for most cases.
continue_next = False
for i in range(1, len(args)):
if continue_next:
continue_next = False
continue
arg = args[i]
if arg.startswith('-'):
# Skip the next arg too if this flag expects a value.
continue_next = arg in ['-m', '-W', '-X']
continue
if arg.rsplit('.')[-1] in ['zip', 'pyz', 'pyzw']:
log_debug('Executing a PyZip, returning')
return args
break
new_args.append(args[0])
else:
log_debug("Process is not python, returning.")
return args
i = 1
# Original args should be something as:
# ['X:\\pysrc\\pydevd.py', '--multiprocess', '--print-in-debugger-startup',
# '--vm_type', 'python', '--client', '127.0.0.1', '--port', '56352', '--file', 'x:\\snippet1.py']
original = sys.original_argv[:]
while i < len(args):
if args[i] == '-m':
# Always insert at pos == 1 (i.e.: pydevd "--module" --multiprocess ...)
original.insert(1, '--module')
else:
if args[i].startswith('-'):
new_args.append(args[i])
else:
break
i += 1
# Note: undoing https://github.com/Elizaveta239/PyDev.Debugger/commit/053c9d6b1b455530bca267e7419a9f63bf51cddf
# (i >= len(args) instead of i < len(args))
# in practice it'd raise an exception here and would return original args, which is not what we want... providing
# a proper fix for https://youtrack.jetbrains.com/issue/PY-9767 elsewhere.
if i < len(args) and _is_managed_arg(args[i]): # no need to add pydevd twice
return args
for x in original: # @UndefinedVariable
if sys.platform == "win32" and not x.endswith('"'):
arg = '"%s"' % x
else:
arg = x
new_args.append(arg)
if x == '--file':
break
while i < len(args):
new_args.append(args[i])
i += 1
return new_args
except:
traceback.print_exc()
return args
0
Example 8
def patch_args(args):
try:
log_debug("Patching args: %s"% str(args))
import sys
new_args = []
i = 0
if len(args) == 0:
return args
if is_python(args[0]):
try:
indC = args.index('-c')
except ValueError:
indC = -1
if indC != -1:
host, port = _get_host_port()
if port is not None:
new_args.extend(args)
new_args[indC + 1] = _get_python_c_args(host, port, indC, args)
return new_args
else:
# Check for Python ZIP Applications and don't patch the args for them.
# Assumes the first non `-<flag>` argument is what we need to check.
# There's probably a better way to determine this but it works for most cases.
continue_next = False
for i in range(1, len(args)):
if continue_next:
continue_next = False
continue
arg = args[i]
if arg.startswith('-'):
# Skip the next arg too if this flag expects a value.
continue_next = arg in ['-m', '-W', '-X']
continue
if arg.rsplit('.')[-1] in ['zip', 'pyz', 'pyzw']:
log_debug('Executing a PyZip, returning')
return args
break
new_args.append(args[0])
else:
log_debug("Process is not python, returning.")
return args
i = 1
# Original args should be something as:
# ['X:\\pysrc\\pydevd.py', '--multiprocess', '--print-in-debugger-startup',
# '--vm_type', 'python', '--client', '127.0.0.1', '--port', '56352', '--file', 'x:\\snippet1.py']
original = sys.original_argv[:]
while i < len(args):
if args[i] == '-m':
# Always insert at pos == 1 (i.e.: pydevd "--module" --multiprocess ...)
original.insert(1, '--module')
else:
if args[i].startswith('-'):
new_args.append(args[i])
else:
break
i += 1
# Note: undoing https://github.com/Elizaveta239/PyDev.Debugger/commit/053c9d6b1b455530bca267e7419a9f63bf51cddf
# (i >= len(args) instead of i < len(args))
# in practice it'd raise an exception here and would return original args, which is not what we want... providing
# a proper fix for https://youtrack.jetbrains.com/issue/PY-9767 elsewhere.
if i >= len(args) or _is_managed_arg(args[i]): # no need to add pydevd twice
return args
for x in original: # @UndefinedVariable
if sys.platform == "win32" and not x.endswith('"'):
arg = '"%s"' % x
else:
arg = x
new_args.append(arg)
if x == '--file':
break
while i < len(args):
new_args.append(args[i])
i += 1
return new_args
except:
traceback.print_exc()
return args