8000 use `sys.platform == "cygwin"` to figure out when we are using cygwin by gcmarx · Pull Request #2027 · gitpython-developers/GitPython · GitHub
[go: up one dir, main page]

Skip to content

use sys.platform == "cygwin" to figure out when we are using cygwin #2027

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gcmarx
Copy link
Contributor
@gcmarx gcmarx commented May 22, 2025

The current logic for detecting cygwin is:

  • if sys.platform == "win32", then it's not cygwin
  • if the passed-in git executable is None, then it's not cygwin git
  • finally, is there a uname executable in the same folder as the git executable, and if so, does the output of that command include "CYGWIN"? if so, then it's cygwin

In the python 3.7 docs for sys.platform, Cygwin systems have sys.platform == "cygwin". Since Python 3.7 is the oldest version still supported by GitPython, it stands to reason that we can rely on that being true for all supported Python versions.

The logic I propose is:

  • if the git executable you passed in is None, it's not cygwin git
  • if sys.platform == 'cygwin', then it's cygwin git

This is simple enough for a single expression, so I replaced the body of the is_cygwin function with that expression and removed is_cygwin_git and friends completely.

I don't know if there's such a thing as sys.platform == 'cygwin' and the git not being cygwin git, but if there is, I don't think the existing code deals with that anyway, so this seems to return the same result and would fail in the same way.

@gcmarx
Copy link
Contributor Author
gcmarx commented May 22, 2025

only this PR or #2026 should be merged

Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR simplifies the detection of Cygwin Git by replacing the former multi-step logic with a concise check that relies on sys.platform.

  • Removed deprecated functions and caching logic for Cygwin detection.
  • Updated the Git command interface to directly use sys.platform and the Git executable's existence.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
git/util.py Removed the py_where and _is_cygwin_git functions along with unused imports.
git/cmd.py Updated the is_cygwin method to use a simplified sys.platform check.

@@ -661,7 +660,7 @@ def refresh(cls, path: Union[None, PathLike] = None) -> bool:

@classmethod
def is_cygwin(cls) -> bool:
return is_cygwin_git(cls.GIT_PYTHON_GIT_EXECUTABLE)
return cls.GIT_PYTHON_GIT_EXECUTABLE is not None and sys.platform == "cygwin"
Copy link
Preview
Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding an inline comment explaining that sys.platform being 'cygwin' reliably indicates a Cygwin environment per Python 3.7+, to improve clarity for future maintainers.

Copilot uses AI. Check for mistakes.

@gcmarx gcmarx changed the title use 'sys.platform == "cygwin"' to figure out when we are using cygwin use sys.platform == "cygwin" to figure out when we are using cygwin May 23, 2025
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.

1 participant
0