Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixops
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ad078df2d919
Choose a base ref
...
head repository: NixOS/nixops
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ba0c3f6c257a
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Apr 15, 2020

  1. Add a flag to enter PDB in post-mortem debugging mode

    This is primarily something I want for developing & debugging new plugins.
    adisbladis committed Apr 15, 2020
    Copy the full SHA
    92c90b3 View commit details
  2. Merge pull request #1272 from adisbladis/pdb-flag

    Add a flag to enter PDB in post-mortem debugging mode
    grahamc authored Apr 15, 2020
    Copy the full SHA
    ba0c3f6 View commit details
Showing with 29 additions and 1 deletion.
  1. +8 −1 doc/manual/hacking.xml
  2. +4 −0 nixops/__main__.py
  3. +17 −0 nixops/script_defs.py
9 changes: 8 additions & 1 deletion doc/manual/hacking.xml
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ $ nix-build release.nix -A tests.none_backend
</screen>

</para>

<para>Some useful snippets to debug nixops:

Logging
@@ -81,6 +81,13 @@ To set breakpoint use
import sys; import pdb; pdb.Pdb(stdout=sys.__stdout__).set_trace()
</screen>

You can also avoid setting a breakpoint and enter pdb in post-mortem mode on the first exception

<screen>
$ nixops --pdb
</screen>


</para>

</appendix>
4 changes: 4 additions & 0 deletions nixops/__main__.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,9 @@
# Set up the parser.
parser = ArgumentParser(description="NixOS cloud deployment tool", prog="nixops")
parser.add_argument("--version", action="version", version="NixOps @version@")
parser.add_argument(
"--pdb", action="store_true", help="Invoke pdb on unhandled exception"
)

subparsers: _SubParsersAction = parser.add_subparsers(
help="sub-command help", metavar="operation", required=True
@@ -620,6 +623,7 @@ def main() -> None:

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

try:
nixops.deployment.DEBUG = args.debug
17 changes: 17 additions & 0 deletions nixops/script_defs.py
Original file line number Diff line number Diff line change
@@ -26,6 +26,11 @@
from datetime import datetime
from pprint import pprint
import importlib
import traceback
import pdb
from argparse import Namespace
from types import TracebackType
from typing import Type

from nixops.plugins import get_plugin_manager

@@ -977,6 +982,18 @@ 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 not args.op in [