XDG Directory Support for PDB
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.waldemarson@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
On 18 Apr 2023, at 14:20, Gustaf Waldemarson <gustaf.waldemarson@gmail.com> wrote:
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.waldemarson@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'): I would expect .pdbrc to be first.
+ 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
Try raising a python bug and a PR with this code in it. Seems reasonable change to support. Barry
-- 2.25.1 _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/HWWWES... Code of Conduct: http://python.org/psf/codeofconduct/
I apologize for the top-post and awkward trimming, my employer just switched to o365 and won't accomodate my existing mail client so I'm stuck with a crappy webmail client on this address. :-p I agree with Barry on both points: seems like a good idea, but the search priority should be ./.pdbrc first. Not your job, but I bet you get "are there other stdlib applications that would benefit from this change?" as feedback. Eg, IDLE. 2023-04-19 02:50 に Barry さんは書きました:
+ for rcFileName in ('${XDG_CONFIG_HOME}/python/pdbrc', + '~/.config/python/pdbrc', + '~/.pdbrc', + '.pdbrc'): I would expect .pdbrc to be first.
+ 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
Try raising a python bug and a PR with this code in it. Seems reasonable change to support.
Barry
Interesting, are you both sure ./.pdbrc should be the first file? I was expecting the order to always go from "most general" to "most specific", i.e., "system" -> "home" -> "current". This way, it would be straightforward to have general configuration in a "system"/"home" configuration which can be overwritten in a more specialized one ("current"). Coincidentally, this is also the order GDB is using: https://sourceware.org/gdb/current/onlinedocs/gdb#Startup Any particular reason you guys prefer a different order?
Not your job, but I bet you get "are there other stdlib applications that would benefit from this change?" as feedback. Eg, IDLE.
Probably, but lets start the discussion somewhere! Best regards, Gustaf Den ons 19 apr. 2023 kl 17:11 skrev turnbull <turnbull@sk.tsukuba.ac.jp>:
I apologize for the top-post and awkward trimming, my employer just switched to o365 and won't accomodate my existing mail client so I'm stuck with a crappy webmail client on this address. :-p
I agree with Barry on both points: seems like a good idea, but the search priority should be ./.pdbrc first.
Not your job, but I bet you get "are there other stdlib applications that would benefit from this change?" as feedback. Eg, IDLE.
2023-04-19 02:50 に Barry さんは書きました:
+ for rcFileName in ('${XDG_CONFIG_HOME}/python/pdbrc', + '~/.config/python/pdbrc', + '~/.pdbrc', + '.pdbrc'): I would expect .pdbrc to be first.
+ 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
Try raising a python bug and a PR with this code in it. Seems reasonable change to support.
Barry
Oh i see you read all the files. Usually you need to stop looking once you find an rc file.
I guess that really depends on the program, but since pdb is modelled on gdb, I figured it made sense to do something similar :) Anyways, I'll prep a pull-request for the cpython repo, should be interesting to see what comes up. Best regards, Gustaf Den tors 20 apr. 2023 kl 17:05 skrev Barry <barry@barrys-emacs.org>:
On 20 Apr 2023, at 14:24, Gustaf Waldemarson <gustaf.waldemarson@gmail.com> wrote:
Interesting, are you both sure ./.pdbrc should be the first file? I was expecting the order to always go from "most general" to "most specific", i.e., "system" -> "home" -> "current". This way, it would be straightforward to have general configuration in a "system"/"home" configuration which can be overwritten in a more specialized one ("current").
Oh i see you read all the files. Usually you need to stop looking once you find an rc file.
Barry
Coincidentally, this is also the order GDB is using: https://sourceware.org/gdb/current/onlinedocs/gdb#Startup
Any particular reason you guys prefer a different order?
Not your job, but I bet you get "are there other stdlib applications that would benefit from this change?" as feedback. Eg, IDLE.
Probably, but lets start the discussion somewhere!
Best regards, Gustaf
Den ons 19 apr. 2023 kl 17:11 skrev turnbull <turnbull@sk.tsukuba.ac.jp>:
I apologize for the top-post and awkward trimming, my employer just switched to o365 and won't accomodate my existing mail client so I'm stuck with a crappy webmail client on this address. :-p
I agree with Barry on both points: seems like a good idea, but the search priority should be ./.pdbrc first.
Not your job, but I bet you get "are there other stdlib applications that would benefit from this change?" as feedback. Eg, IDLE.
2023-04-19 02:50 に Barry さんは書きました:
+ for rcFileName in ('${XDG_CONFIG_HOME}/python/pdbrc', + '~/.config/python/pdbrc', + '~/.pdbrc', + '.pdbrc'): I would expect .pdbrc to be first.
+ 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
Try raising a python bug and a PR with this code in it. Seems reasonable change to support.
Barry
2023-04-21 00:51 に Gustaf Waldemarson さんは書きました:
Oh i see you read all the files. Usually you need to stop looking once you find an rc file.
I guess that really depends on the program, but since pdb is modelled on gdb, I figured it made sense to do something similar :)
I don't have a problem with "cascading" configuration files, but in my understanding, $XDG_CONFIG_HOME/python/pdbrc, ~/config/python/pdbrc, and ~/.pdbrc are conceptually all the same thing: the user's personal config file. I don't know how gdb does it, but I imagine it would be a rather annoying debugging session if you had a stale ~/.pdbrc lying around and it partially overrides $XDG_CONFIG_HOME/python/pdbrc (partially because it's the ancestor version of the XDG-ly-correct file). Pragmatically I don't see a practical use case for having more than one "user" file plus the "project-local" file. I'm happy to be taught otherwise, but I suspect if *all* the files are read and last one wins for each setting, it will need to be documented emphatically. Steve
participants (3)
-
Barry
-
Gustaf Waldemarson
-
turnbull