Hello,

I don't really use the Python debugger all that much, but recently I used it
quite a bit for a small side-project. That said, it kept annoying me that there
were no history associated with the prompt, so I added a few lines to the
`pdbrc` config file to store that for me. However, it seems like this file must
either exist in the user home directory, or the current working directory,
neither of which were very convenient for me.

Additionally, I strongly dislike polluting my home directory with dotfiles, thus
I did a bit of researching to see if this could be fixed. Thus, below is a small
patch to PDB that adds support for **also** reading from configuration files in
some XDG directories (currently ${XDG_CONFIG_HOME}/python/pdbrc).

So I guess the question is, would anyone else find this useful enough to the
point were I should write a PEP for it? As far as I can tell, Python haven't
been using the XDG directories, so I suppose the naming of the subdirectory
is really subject to a larger discussion.

    From d4ea8fbba3ba6c7538ccecad2a32e6b3b2059e5d Mon Sep 17 00:00:00 2001
    From: Gustaf Waldemarson <gustaf.waldemar...@gmail.com>
    Date: Thu, 13 Apr 2023 11:39:00 +0200
    Subject: [PATCH] Allow users to store PDB configuration in XDG directories.
    
    ---
     Lib/pdb.py | 22 +++++++++++-----------
     1 file changed, 11 insertions(+), 11 deletions(-)
    
    diff --git a/Lib/pdb.py b/Lib/pdb.py
    index a3553b345a..3f4ffd7719 100755
    --- a/Lib/pdb.py
    +++ b/Lib/pdb.py
    @@ -231,19 +231,19 @@ def __init__(self, completekey='tab', stdin=None, 
stdout=None, skip=None,
             self.allow_kbdint = False
             self.nosigint = nosigint
    
    -        # Read ~/.pdbrc and ./.pdbrc
    +        # Read user configuration from a set of paths.
             self.rcLines = []
             if readrc:
    -            try:
    -                with open(os.path.expanduser('~/.pdbrc'), 
encoding='utf-8') as rcFile:
    -                    self.rcLines.extend(rcFile)
    -            except OSError:
    -                pass
    -            try:
    -                with open(".pdbrc", encoding='utf-8') as rcFile:
    -                    self.rcLines.extend(rcFile)
    -            except OSError:
    -                pass
    +            for rcFileName in ('${XDG_CONFIG_HOME}/python/pdbrc',
    +                               '~/.config/python/pdbrc',
    +                               '~/.pdbrc',
    +                               '.pdbrc'):
    +                rcPath = os.path.expanduser(os.path.expandvars(rcFileName))
    +                try:
    +                    with open(rcPath, encoding='utf-8') as rcFile:
    +                        self.rcLines.extend(rcFile)
    +                except OSError:
    +                    pass
    
             self.commands = {} # associates a command list to breakpoint 
numbers
             self.commands_doprompt = {} # for each bp num, tells if the prompt
    -- 
    2.25.1
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/HWWWESO3KUCU54OU5FISD3RKLEZMKBP7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to