-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-20523: pdb searches for .pdbrc in ~ instead of $HOME #11847
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
This also solves a problem we encountered trying to launch pdb (via |
Lib/pdb.py
Outdated
if 'HOME' in os.environ: | ||
envHome = os.environ['HOME'] | ||
envHome = os.path.expanduser('~') | ||
if envHome != '~': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you test with '~' ? normally, you won't get the tilde but the full path. I have an other PR but you can check with my code and fix yours. #11855
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
envHome != '~'
is true if expanduser
succeeded in finding the full path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, but in which case can you have '~' ? never
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your solution is cleaner. We took the approach of modifying the fewest lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in fact, expanduser will replace ~
by the $HOME, $HOMEDRIVE, $HOMEPATH, etc... for Windows and unix-like, so normally, you won't get the ~
. my approach is different because I wait for an exception and sometimes, an exception is better than a condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could have ~
if the expansion fails (e.g. if it can't find anything resembling a home directory): "If the expansion fails or if the path does not begin with a tilde, the path is returned unchanged."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, it's possible.
- use python3 for the documentation (https://docs.python.org/3/library/os.path.html#os.path.expanduser)
- if you can't read the file you will get an exception, in this case, you will get OSError or Exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use your cleaner solution
Previously pdb checked the $HOME environmental variable to find the user .pdbrc. If $HOME is not set, the user .pdbrc would not be found. Change pdb to use `os.path.expanduser('~')` to determine the user's home directory. Thus, if $HOME is not set (as in tox or on Windows), os.path.expanduser('~') falls back on other techniques for locating the user's home directory. This follows pip's implementation for loading .piprc. Co-authored-by: Dan Lidral-Porter <dlp@aperiodic.org>
93cddbf
to
75c7c58
Compare
self.rcLines.extend(rcFile) | ||
except OSError: | ||
pass | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to an other solution:
for path in (os.path.expanduser('~/.pdbrc'), '.pdbrc'):
with contextlib.suppress(OSError), open(path) as rcFile:
self.rcLines.extend(rcFile)
but I am not sure. need to test it.
Sorry for the slow reviews, but I'm happy with this, so it can go in for the next releases! |
I'm having trouble backporting to |
) Previously pdb checked the $HOME environmental variable to find the user .pdbrc. If $HOME is not set, the user .pdbrc would not be found. Change pdb to use `os.path.expanduser('~')` to determine the user's home directory. Thus, if $HOME is not set (as in tox or on Windows), os.path.expanduser('~') falls back on other techniques for locating the user's home directory. This follows pip's implementation for loading .piprc. Co-authored-by: Dan Lidral-Porter <dlp@aperiodic.org> (cherry picked from commit 7ea9a85) Co-authored-by: Timothy Hopper <tdhopper@users.noreply.github.com>
GH-15084 is a backport of this pull request to the 3.7 branch. |
) Previously pdb checked the $HOME environmental variable to find the user .pdbrc. If $HOME is not set, the user .pdbrc would not be found. Change pdb to use `os.path.expanduser('~')` to determine the user's home directory. Thus, if $HOME is not set (as in tox or on Windows), os.path.expanduser('~') falls back on other techniques for locating the user's home directory. This follows pip's implementation for loading .piprc. Co-authored-by: Dan Lidral-Porter <dlp@aperiodic.org> (cherry picked from commit 7ea9a85) Co-authored-by: Timothy Hopper <tdhopper@users.noreply.github.com>
GH-15085 is a backport of this pull request to the 3.8 branch. |
Previously pdb checked the $HOME environmental variable to find the user .pdbrc. If $HOME is not set, the user .pdbrc would not be found. Change pdb to use `os.path.expanduser('~')` to determine the user's home directory. Thus, if $HOME is not set (as in tox or on Windows), os.path.expanduser('~') falls back on other techniques for locating the user's home directory. This follows pip's implementation for loading .piprc. Co-authored-by: Dan Lidral-Porter <dlp@aperiodic.org> (cherry picked from commit 7ea9a85) Co-authored-by: Timothy Hopper <tdhopper@users.noreply.github.com>
Previously pdb checked the $HOME environmental variable to find the user .pdbrc. If $HOME is not set, the user .pdbrc would not be found. Change pdb to use `os.path.expanduser('~')` to determine the user's home directory. Thus, if $HOME is not set (as in tox or on Windows), os.path.expanduser('~') falls back on other techniques for locating the user's home directory. This follows pip's implementation for loading .piprc. Co-authored-by: Dan Lidral-Porter <dlp@aperiodic.org> (cherry picked from commit 7ea9a85) Co-authored-by: Timothy Hopper <tdhopper@users.noreply.github.com>
Tim and Dan were authors for GH-11847
) Previously pdb checked the $HOME environmental variable to find the user .pdbrc. If $HOME is not set, the user .pdbrc would not be found. Change pdb to use `os.path.expanduser('~')` to determine the user's home directory. Thus, if $HOME is not set (as in tox or on Windows), os.path.expanduser('~') falls back on other techniques for locating the user's home directory. This follows pip's implementation for loading .piprc. Co-authored-by: Dan Lidral-Porter <dlp@aperiodic.org>
Tim and Dan were authors for pythonGH-11847
) Previously pdb checked the $HOME environmental variable to find the user .pdbrc. If $HOME is not set, the user .pdbrc would not be found. Change pdb to use `os.path.expanduser('~')` to determine the user's home directory. Thus, if $HOME is not set (as in tox or on Windows), os.path.expanduser('~') falls back on other techniques for locating the user's home directory. This follows pip's implementation for loading .piprc. Co-authored-by: Dan Lidral-Porter <dlp@aperiodic.org>
Tim and Dan were authors for pythonGH-11847
) Previously pdb checked the $HOME environmental variable to find the user .pdbrc. If $HOME is not set, the user .pdbrc would not be found. Change pdb to use `os.path.expanduser('~')` to determine the user's home directory. Thus, if $HOME is not set (as in tox or on Windows), os.path.expanduser('~') falls back on other techniques for locating the user's home directory. This follows pip's implementation for loading .piprc. Co-authored-by: Dan Lidral-Porter <dlp@aperiodic.org>
Tim and Dan were authors for pythonGH-11847
Previously pdb checked the $HOME environmental variable
to find the user .pdbrc. If $HOME is not set, the user
.pdbrc would not be found.
Change pdb to use
os.path.expanduser('~')
to determinethe user's home directory. Thus, if $HOME is not set (as
in tox or on Windows), os.path.expanduser('~') falls
back on other techniques for locating the user's home
directory.
This follows pip's implementation for loading .piprc.
Co-authored-by: Dan Lidral-Porter dlp@aperiodic.org
https://bugs.python.org/issue20523