How to use the pydevd.SetupHolder.setup function in pydevd

To help you get started, we’ve selected a few pydevd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fabioz / Pydev / plugins / org.python.pydev.core / pysrc / tests_python / test_pydev_monkey.py View on Github external
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']

            self.assertEqual(pydev_monkey.patch_args(check), [
                'C:\\bin\\python.exe', 'pydevd.py', 'connect(\\"127.0.0.1\\")', 'bar'])
        finally:
            SetupHolder.setup = original
github fabioz / Pydev / plugins / org.python.pydev.core / pysrc / tests_python / test_pydev_monkey.py View on Github external
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\\")'''
            debug_command = (
                '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); '
                ''
                "from pydevd import SetupHolder; "
                "SetupHolder.setup = %s; "
                ''
                'connect("127.0.0.1")') % (pydev_src_dir, SetupHolder.setup)
            if sys.platform == "win32":
                debug_command = debug_command.replace('"', '\\"')
                debug_command = '"%s"' % debug_command
                
            self.assertEqual(
                'C:\\bin\\python.exe -u -c %s' % debug_command,
                pydev_monkey.patch_arg_str_win(check))
        finally:
            SetupHolder.setup = original
github fabioz / PyDev.Debugger / tests_python / test_pydev_monkey.py View on Github external
def test_monkey_patch_args_no_indc_without_pydevd(self):
        original = SetupHolder.setup
        from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file

        try:
            SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'}
            check = ['C:\\bin\\python.exe', 'target.py', 'connect(\\"127.0.0.1\\")', 'bar']
            self.assertEqual(pydev_monkey.patch_args(check), [
                'C:\\bin\\python.exe',
                get_pydevd_file(),
                '--port',
                '0',
                '--client',
                '127.0.0.1',
                '--protocol-quoted-line',
                '--file',
                'target.py',
                '"connect(\\\\\\"127.0.0.1\\\\\\")"' if sys.platform == 'win32' else 'connect(\\"127.0.0.1\\")',
github fabioz / PyDev.Debugger / tests_python / test_pydev_monkey.py View on Github external
def test_monkey_patch_args_no_indc_without_pydevd(self):
        original = SetupHolder.setup
        from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file

        try:
            SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'}
            check = ['C:\\bin\\python.exe', 'target.py', 'connect(\\"127.0.0.1\\")', 'bar']
            self.assertEqual(pydev_monkey.patch_args(check), [
                'C:\\bin\\python.exe',
                get_pydevd_file(),
                '--port',
                '0',
                '--client',
                '127.0.0.1',
                '--protocol-quoted-line',
                '--file',
                'target.py',
                '"connect(\\\\\\"127.0.0.1\\\\\\")"' if sys.platform == 'win32' else 'connect(\\"127.0.0.1\\")',
                'bar',
            ])
        finally:
            SetupHolder.setup = original
github fabioz / PyDev.Debugger / pydevd.py View on Github external
global _debugger_setup
    global bufferStdOutToServer
    global bufferStdErrToServer

    if not _debugger_setup:
        pydevd_vm_type.setup_type()

        if SetupHolder.setup is None:
            setup = {
                'client': host,  # dispatch expects client to be set to the host address when server is False
                'server': False,
                'port': int(port),
                'multiprocess': patch_multiprocessing,
            }
            SetupHolder.setup = setup

        debugger = get_global_debugger()
        if debugger is None:
            debugger = PyDB()
        if block_until_connected:
            debugger.connect(host, port)  # Note: connect can raise error.
        else:
            # Create a dummy writer and wait for the real connection.
            debugger.writer = WriterThread(NULL, terminate_on_socket_close=False)
            debugger.create_wait_for_connection_thread()

        # Mark connected only if it actually succeeded.
        _debugger_setup = True
        bufferStdOutToServer = stdoutToServer
        bufferStdErrToServer = stderrToServer
github fabioz / Pydev / plugins / org.python.pydev.core / pysrc / _pydev_bundle / pydev_monkey.py View on Github external
from pydevd import SetupHolder
        import sys
        new_args = []
        if len(args) == 0:
            return args

        if is_python(args[0]):
            ind_c = get_c_option_index(args)

            if ind_c != -1:
                host, port = _get_host_port()

                if port is not None:
                    new_args.extend(args)
                    new_args[ind_c + 1] = _get_python_c_args(host, port, ind_c, args, SetupHolder.setup)
                    return quote_args(new_args)
            else:
                # Check for Python ZIP Applications and don't patch the args for them.
                # Assumes the first non `-` 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
github fabioz / PyDev.Debugger / pydevd.py View on Github external
def main():

    # parse the command line. --file is our last argument that is required
    try:
        from _pydevd_bundle.pydevd_command_line_handling import process_command_line
        setup = process_command_line(sys.argv)
        SetupHolder.setup = setup
    except ValueError:
        pydev_log.exception()
        usage(1)

    if setup['print-in-debugger-startup']:
        try:
            pid = ' (pid: %s)' % os.getpid()
        except:
            pid = ''
        sys.stderr.write("pydev debugger: starting%s\n" % pid)

    pydev_log.debug("Executing file %s" % setup['file'])
    pydev_log.debug("arguments: %s" % str(sys.argv))

    pydevd_vm_type.setup_type(setup.get('vm_type', None))