Skip to content

Commit

Permalink
Merge pull request #1347 from adisbladis/early-pdb
Browse files Browse the repository at this point in the history
Run --pdb check early
  • Loading branch information
grahamc committed May 18, 2020
2 parents 7f38a16 + 96b8134 commit 4642152
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .flake8
Expand Up @@ -6,6 +6,9 @@ max-line-length = 80
max-complexity = 18
select = B,C,E,F,W,T4,B9

per-file-ignores =
nixops/__main__.py:E402

# # We need to configure the mypy.ini because the flake8-mypy's default
# # options don't properly override it, so if we don't specify it we get
# # half of the config from mypy.ini and half from flake8-mypy.
Expand Down
29 changes: 27 additions & 2 deletions nixops/__main__.py
@@ -1,5 +1,32 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys


def setup_debugger() -> None:
"""
"""
import traceback
import pdb
from types import TracebackType
from typing import Type

def hook(_type: Type[BaseException], value: BaseException, tb: TracebackType):
if hasattr(sys, "ps1") or not sys.stderr.isatty():
sys.__excepthook__(_type, value, tb)
else:
traceback.print_exception(_type, value, tb)
pdb.post_mortem(tb)

sys.excepthook = hook


# Run check for --pdb as early as possible so it kicks in _before_ plugin loading
# and other dynamic startup happens
if __name__ == "__main__":
if "--pdb" in sys.argv:
setup_debugger()


from argparse import ArgumentParser, _SubParsersAction, SUPPRESS, REMAINDER
import os
Expand Down Expand Up @@ -48,7 +75,6 @@
op_list_plugins,
parser_plugin_hooks,
setup_logging,
setup_debugger,
error,
)
import sys
Expand Down Expand Up @@ -673,7 +699,6 @@ def main() -> None:

args = parser.parse_args()
setup_logging(args)
setup_debugger(args)

try:
nixops.deployment.DEBUG = args.debug
Expand Down
16 changes: 0 additions & 16 deletions nixops/script_defs.py
Expand Up @@ -22,10 +22,6 @@
import pipes
from typing import Tuple, List, Optional, Union, Generator
import importlib
import traceback
import pdb
from types import TracebackType
from typing import Type
import nixops.ansi

from nixops.plugins import get_plugin_manager
Expand Down Expand Up @@ -982,18 +978,6 @@ def op_copy_closure(args):
sys.exit(res)


def setup_debugger(args: Namespace) -> None:
def hook(_type: Type[BaseException], value: BaseException, tb: TracebackType):
if hasattr(sys, "ps1") or not sys.stderr.isatty():
sys.__excepthook__(_type, value, tb)
else:
traceback.print_exception(_type, value, tb)
pdb.post_mortem(tb)

if args.pdb:
sys.excepthook = hook


# Set up logging of all commands and output
def setup_logging(args):
if os.path.exists("/dev/log") and args.op not in [
Expand Down

0 comments on commit 4642152

Please sign in to comment.