Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

usesys.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
gcmarx wants to merge2 commits intogitpython-developers:main
base:main
Choose a base branch
Loading
fromgcmarx:sys-platform-detect-cygwin

Conversation

gcmarx
Copy link
Contributor

The current logic for detecting cygwin is:

  • ifsys.platform == "win32", then it's not cygwin
  • if the passed-in git executable is None, then it's not cygwin git
  • finally, is there auname 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 thepython 3.7 docs for sys.platform, Cygwin systems havesys.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
  • ifsys.platform == 'cygwin', then it's cygwin git

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

I don't know if there's such a thing assys.platform == 'cygwin' and thegit not being cygwingit, 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
ContributorAuthor

only this PR or#2026 should be merged

Copy link

@CopilotCopilotAI 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.

FileDescription
git/util.pyRemoved the py_where and _is_cygwin_git functions along with unused imports.
git/cmd.pyUpdated the is_cygwin method to use a simplified sys.platform check.

@gcmarxgcmarx changed the titleuse 'sys.platform == "cygwin"' to figure out when we are using cygwinusesys.platform == "cygwin" to figure out when we are using cygwinMay 23, 2025
@ByronByron requested a review fromEliahKaganMay 26, 2025 03:12
Copy link
Member

@EliahKaganEliahKagan left a comment
edited
Loading

Choose a reason for hiding this comment

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

This is preliminary and I'll try to say a little more in a forthcoming review of#2026, which I hope to do tomorrow.

I think we'll probably want to prefer the approach in#2026 over this, at least in the short term. There is a deliberate and long-standing (though not always perfectly applied) distinction throughout the code of GitPython between whether the platform is Cygwin (i.e. whether thepython interpreter running the code of GitPython is a Cygwin program) and whether thegit executable that GitPython calls is a Cygwin program.

This appears to be relevant to the treatment of absolute paths in some operations that involve cloning to an absolute path or adding a submodule. Most use ofis_cygwin_git is throughGit.is_cygwin, and searching forGit.is_cygwin reveals uses where it looks like this distinction can matter.

GitPython uses whatevergit executable it is configured to use via environment variables orrefresh or, if it is not configured to use a particulargit executable, whatever executable it finds in a path search. In either case, this executable need not be built for the same target as GitPython.

I admittedly would not recommend most such mismatches betweenpython andgit if they can be avoided. I also think we should be willing to run the risk of breaking things in what I believe to be the unusual case of using Cygwingit from outside Cygwin, if doing so is necessary in order to avoid or fix breakages when Cygwin is not used--especially for bugs that affect users on Unix-like operating systems that aren't related to Windows. This is one of the reasons I anticipate that the approach in#2026 is probably okay.

But distinguishing Cygwinpython using Cygwingit from Cygwinpython using Git for Windowsgit seems like it is at least partially working. It's also fairly easy to produce the situation of Cygwinpython using Git for Windowsgit. This can plausibly occur intentionally or by accident. Most Cygwin environments preserve WindowsPATH entries, allowing them to appear after Cygwin-specificbin directories. If GitPython is used in Cygwinpython, on a system where Cygwingit is not installed but Git for Windowsis installed, thenusually the non-Cygwingit will be found in thePATH, and GitPython will use it.

Byron reacted with heart emoji
@gcmarx
Copy link
ContributorAuthor

Thanks for the thorough review!

Neither the value ofsys.platform nor “uname in the same directory asgit” seem like a bulletproof way to tell whether thegit in question is Cygwin git or not. I’m wondering if the git executable itself can be convinced to tell us about itself, but don’t currently have a way to test that. I’ll try to poke around at that later this week.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@EliahKaganEliahKaganEliahKagan left review comments

Copilot code reviewCopilotCopilot left review comments

Assignees
No one assigned
Labels
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@gcmarx@EliahKagan

[8]ページ先頭

©2009-2025 Movatter.jp