Fix typo in _get_exe_extensions PATHEXT fallback by EliahKagan · Pull Request #1890 · gitpython-developers/GitPython
Repository navigation
Fix typo in _get_exe_extensions PATHEXT fallback - #1890
Merged
Byron merged 2 commits into gitpython-developers:main from EliahKagan:pathext Apr 2, 2024
Merged
Fix typo in _get_exe_extensions PATHEXT fallback #1890 Byron merged 2 commits into gitpython-developers:main from EliahKagan:pathext
Conversation
EliahKagan commented Mar 31, 2024 · edited Loading
Copy link Copy Markdown
Member
This applies two minor Cygwin-related clarifications, one of which is theoretically a bugfix though it affects conceptually non-public code that is currently not used in a way that could invoke the bug. Some specific details are in commit messages.
The second commit, 988d97b , which fixes COM to .COM in the fallback for the PATHEXT environment variable--whose omission is almost certainly a typo, going back to the function's introduction in e6e23ed (#533 )--is theoretically a bugfix. But as noted there, this code is only called when the Python interpreter is a native Windows program, but the function it is a part of is only called when the Python interpreter is not a native Windows program. (Also, it would be pretty unusual for the git executable to have a .com extension.)
There are some further changes related to Cygwin detection that may make sense to make in the future, some of which might be best to make after adding relevant tests. The ones that are narrowly related to the change here are that:
- This value of
PATHEXThere is still unusual, because order matters and this lists.BATbefore.COMand.EXE, and because it is missing.CMD, which is part of what a minimal value for it should typically contain . I am uncertain if this strange order is intentional. - It may also make sense for the list to include
.VBS,.JS,.WS, and.MSCfor compatibility with the fallback behavior of the Windowscmd.exeshell whenPATHEXTis unset, which is whatshutil.whichdoes . (I have verified the result of Eryk Sun's debugger check in WinDbg on recent builds of Windows 10 and Windows 11; they are the same.) py_whereshould really be removed and replaced either with a call toshutil.which, which did not exist at the timepy_wherewas introduced and would almost certainly have been used at that time if it had--or with other logic that works an altogether different way. Which should be done depends on the intent of the publicGit.is_cygwin_gitclass method, which is the only code in GitPython that uses theis_cygwin_gitfunction ingit/util.py, for which thepy_wherehelper exists.
This PR doesn't try to cover any of that. It's really just applying some clarifications that didn't seem like they fit in any other PR that I would do soon.
Regarding the last point about Git.is_cygwin_git, if the goal is to detect Cygwin git even on native Windows systems, then the code it uses will have to be significantly revised. That is because currently it always returns False on such systems. In addition, as noted in the py_where docstring and elsewhere, shell and non-shell path search differ from each other on native Windows, such that neither the nonpublic ad-hoc py_where nor the public general shutil.which will reliably tell us where git is. However, if a path search doesn't need to be done on native Windows, then it can be replaced with shutil.which unless some use has come to depend on (perhaps accidentally introduced) distinctive behavior of py_where.
I plan to open an issue about that larger matter, which I am unlikely to work on anytime soon, but that perhaps someone would be interested to take on. (If you know what Git.is_cygwin_git's semantics are supposed to be, then I can make use of that information in the forthcoming issue, but I can still open it even if its intent is currently uncertain.)
Fix wording of comment about the /cygdrive prefix
83bed19
Fix typo in _get_exe_extensions PATHEXT fallback
988d97b
PATHEXT lists file extensions with the ".". In the fallback given in _get_exe_extensions, the other extensions had this, but ".COM" was listed without the ".". This fixes that. This is very minor because _get_exe_extensions is nonpublic and not currently used on native Windows, which is the platform where the PATHEXT fallback code would be used. Specifically, _get_exe_extensions is called only in py_where, which while named with no leading underscore is nonpublic do not being (and never having been) listed in __all__. As its docstring states, it is an implementation detail of is_cygwin_git and not intended for any other use. More specifically, is_cygwin_git currently immediately returns False on *native* Windows (even if the git executable GitPython is using is a Cygwin git executable). Only on Cygwin, or other systems that are not native Windows, does it try to check the git executable (by calling its _is_cygwin_git helper, which uses py_where).EliahKagan marked this pull request as ready for review March 31, 2024 21:26
Byron commented Apr 2, 2024
Copy link Copy Markdown
Member
|
Thanks a lot for the fix, a great catch!
I don't think it is intentional and would hope it could be set to what makes most sense eventually. I agree with all the other points as well and look forward to seeing them fixed/improved eventually. |
f1a7e02
into
gitpython-developers : main
Apr 2, 2024
EliahKagan
deleted the
pathext
branch
April 2, 2024 13:36