Skip to content
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

Fix typo in _get_exe_extensions PATHEXT fallback #1890

Merged
merged 2 commits into from
Apr 2, 2024

Conversation

EliahKagan
Copy link
Contributor

@EliahKagan EliahKagan commented Mar 31, 2024

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 PATHEXT here is still unusual, because order matters and this lists .BAT before .COM and .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 .MSC for compatibility with the fallback behavior of the Windows cmd.exe shell when PATHEXT is unset, which is what shutil.which does. (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_where should really be removed and replaced either with a call to shutil.which, which did not exist at the time py_where was 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 public Git.is_cygwin_git class method, which is the only code in GitPython that uses the is_cygwin_git function in git/util.py, for which the py_where helper 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.)

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 EliahKagan marked this pull request as ready for review March 31, 2024 21:26
@Byron
Copy link
Member

Byron commented Apr 2, 2024

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.

@Byron Byron merged commit f1a7e02 into gitpython-developers:main Apr 2, 2024
26 checks passed
@EliahKagan EliahKagan deleted the pathext branch April 2, 2024 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants