Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Keckelt/python remote debugger #99

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Copy this file to `<workspace>/.vscode/launch.json` to run the Python debugger in Visual Studio Code
// Remember to activate the debugger in `<workspace>/config.json`
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: phovea_server",
"type": "python",
"request": "attach",
//"logToFile": true,
"port": 5678,
"host": "localhost",
"gevent": true,
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/phovea"
}
]
}
]
}
8 changes: 7 additions & 1 deletion deploy/docker-compose-debug.partial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ version: '2.0'
services:
api:
ports:
- '2222:22'
- '5678:5678'
environment:
GEVENT_SUPPORT: 'true'
PTVSD_LOG_DIR: '/phovea'
PHOVEA_ENV: 'dev'
PHOVEA_SERVICE: 'api'
command: python phovea_server/__main__.py --env ${PHOVEA_ENV} ${PHOVEA_SERVICE}
2 changes: 2 additions & 0 deletions phovea_server/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"nocache": false,
"error_stack_trace": false,

"ptvsd_debugger": false,

"port": 80,
"address": "0.0.0.0",

Expand Down
39 changes: 30 additions & 9 deletions phovea_server/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
# Licensed under the new BSD license, available at http://caleydo.org/license
###############################################################################

import logging.config
import logging
import logging.config

from . import config


Expand Down Expand Up @@ -49,6 +50,23 @@ def enable_prod_mode():
cc.set('nocache', False)


def attach_ptvsd_debugger():
if cc.getboolean('ptvsd_debugger', default=False) is False:
_log.info('Tip: You can enable the remote debugger `ptvsd` for Visual Studio Code by adding configuration `"ptvsd_debugger": true` to `phovea_server` section in the config.json of your workspace.')
return

try:
import ptvsd
ptvsd.enable_attach(address = ('0.0.0.0', 5678))
_log.info('Debugger is started')
_log.info('You can now start the debugger in Visual Studio Code')
_log.info('Waiting for a debugger to attach ...')
ptvsd.wait_for_attach()
_log.info('Debugger successfully attached')
except OSError as exc:
_log.error(exc)


def _config_files():
"""
list all known config files
Expand Down Expand Up @@ -120,8 +138,10 @@ def _resolve_commands(parser):
default_command = None

for command in list_plugins('command'):
_log.info('add command ' + command.id)
_log.info('add command: ' + command.id)

if hasattr(command, 'isDefault') and command.isDefault:
_log.info('set default command: ' + command.id)
default_command = command.id

# create a argument parser for the command
Expand Down Expand Up @@ -151,6 +171,7 @@ def _set_runtime_infos(args):
runtime = cc.view('_runtime')
runtime.set('command', args.launcherid)
runtime.set('reloader', args.use_reloader)

cc.set('absoluteDir', os.path.abspath(cc.get('dir')) + '/')


Expand Down Expand Up @@ -182,6 +203,7 @@ def run():
args = parser.parse_known_args()[0]
if args.env.startswith('dev'):
enable_dev_mode()
attach_ptvsd_debugger()
else:
enable_prod_mode()

Expand All @@ -192,17 +214,16 @@ def run():
set_default_subparser(parser, default_command)

args = parser.parse_args()

_set_runtime_infos(args)

main = args.launcher(args) # execute the launcher function, which returns another function

if args.use_reloader:
_log.info('start application using reloader...')
run_with_reloader(main, extra_files=_config_files())
else:
_log.info('start application...')
main()
# if args.use_reloader:
# _log.info('start application using reloader...')
# run_with_reloader(main, extra_files=_config_files())
# else:
_log.info('start application...')
main()


def create_embedded():
Expand Down
2 changes: 1 addition & 1 deletion phovea_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _get_config():
# append the plugin directories as primary lookup path
cc = _get_config()
# configure logging
logging.config.dictConfig(cc.logging)
# logging.config.dictConfig(cc.logging) # configuration already set in launch.py
_log = logging.getLogger(__name__)


Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pytest==5.3.5
pytest-runner==5.2
Sphinx==2.4.2
recommonmark==0.6.0
ptvsd>=5.0.0a12