|
46 | 46 | input is split at the first ';;', even if it is in the middle of a |
47 | 47 | quoted string. |
48 | 48 |
|
49 | | -If a file ".pdbrc" exists in your home directory or in the current |
50 | | -directory, it is read in and executed as if it had been typed at the |
51 | | -debugger prompt. This is particularly useful for aliases. If both |
52 | | -files exist, the one in the home directory is read first and aliases |
53 | | -defined there can be overridden by the local file. This behavior can be |
54 | | -disabled by passing the "readrc=False" argument to the Pdb constructor. |
| 49 | +If a '.pdbrc' exists in any of the supported locations, it is read with 'utf-8' |
| 50 | +encoding and executed as if it had been typed at the debugger prompt, with the |
| 51 | +exception that empty lines and lines starting with '#' are ignored. This is |
| 52 | +particularly useful for aliases. |
| 53 | +
|
| 54 | +This behavior can be disabled by passing the 'readrc=False' argument to the Pdb |
| 55 | +constructor. |
| 56 | +
|
| 57 | +Supported locations for '.pdbrc' file are |
| 58 | +
|
| 59 | +1. '$XDG_CONFIG_HOME/pdb' (defaults to '~/.config/pdb', if environment variable |
| 60 | + $XDG_CONFIG_HOME is not set) |
| 61 | +2. User's home directory |
| 62 | +3. Current working directory |
| 63 | +
|
| 64 | +If '.pdbrc' files exist in multiple locations, they are processed in order, so |
| 65 | +that '$XDG_CONFIG_HOME/pdb/.pdbrc' is loaded first, and extended by '.pdbrc' |
| 66 | +files in user's home and current directory. |
55 | 67 |
|
56 | 68 | Aside from aliases, the debugger is not directly programmable; but it |
57 | 69 | is implemented as a class from which you can derive your own debugger |
|
98 | 110 | import _colorize |
99 | 111 | import _pyrepl.utils |
100 | 112 |
|
101 | | -from contextlib import ExitStack, closing, contextmanager |
| 113 | +from contextlib import ExitStack, closing, contextmanager, suppress |
102 | 114 | from rlcompleter import Completer |
103 | 115 | from types import CodeType |
104 | 116 | from warnings import deprecated |
@@ -369,19 +381,19 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, |
369 | 381 | # c.a or c['a'], it won't be recognized as a c(ontinue) command |
370 | 382 | self.identchars = cmd.Cmd.identchars + '=.[](),"\'+-*/%@&|<>~^' |
371 | 383 |
|
372 | | - # Read ~/.pdbrc and ./.pdbrc |
| 384 | + # Read $XDG_CONFIG_HOME/pdb/.pdbrc, ~/.pdbrc, and ./.pdbrc |
373 | 385 | self.rcLines = [] |
374 | 386 | if readrc: |
375 | | - try: |
376 | | - with open(os.path.expanduser('~/.pdbrc'), encoding='utf-8') as rcFile: |
377 | | - self.rcLines.extend(rcFile) |
378 | | - except OSError: |
379 | | - pass |
380 | | - try: |
381 | | - with open(".pdbrc", encoding='utf-8') as rcFile: |
382 | | - self.rcLines.extend(rcFile) |
383 | | - except OSError: |
384 | | - pass |
| 387 | + # $XDG_CONFIG_HOME defaults to $HOME/.config |
| 388 | + config_home = os.environ.get('XDG_CONFIG_HOME', '~/.config') |
| 389 | + for rc_path in ( |
| 390 | + os.path.expanduser(os.path.join(config_home, 'pdb', '.pdbrc')), |
| 391 | + os.path.expanduser('~/.pdbrc'), |
| 392 | + '.pdbrc', |
| 393 | + ): |
| 394 | + with suppress(OSError): |
| 395 | + with open(rc_path, encoding='utf-8') as rcFile: |
| 396 | + self.rcLines.extend(rcFile) |
385 | 397 |
|
386 | 398 | self.commands = {} # associates a command list to breakpoint numbers |
387 | 399 | self.commands_defining = False # True while in the process of defining |
@@ -3492,8 +3504,8 @@ def help(): |
3492 | 3504 | an executable module or package to debug can be specified using |
3493 | 3505 | the -m switch. |
3494 | 3506 |
|
3495 | | -Initial commands are read from .pdbrc files in your home directory |
3496 | | -and in the current directory, if they exist. Commands supplied with |
| 3507 | +Initial commands are read from .pdbrc files in "$XDG_CONFIG_HOME/pdb", your home |
| 3508 | +directory, and in the current directory, if they exist. Commands supplied with |
3497 | 3509 | -c are executed after commands from .pdbrc files. |
3498 | 3510 |
|
3499 | 3511 | To let the script run until an exception occurs, use "-c continue". |
|
0 commit comments