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
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,8 @@ __pycache__/
# Transient editor files
*.swp
*~
\#*#
.#*#

# Editor configuration
nbproject
Expand Down
1 change: 1 addition & 0 deletionsAUTHORS
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -55,5 +55,6 @@ Contributors are:
-Eliah Kagan <eliah.kagan _at_ gmail.com>
-Ethan Lin <et.repositories _at_ gmail.com>
-Jonas Scharpf <jonas.scharpf _at_ checkmk.com>
-Gordon Marx

Portions derived from other open source works and are clearly marked.
3 changes: 1 addition & 2 deletionsgit/cmd.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,6 @@
from git.util import (
cygpath,
expand_path,
is_cygwin_git,
patch_env,
remove_password_if_present,
stream_copy,
Expand DownExpand Up@@ -661,7 +660,7 @@ def refresh(cls, path: Union[None, PathLike] = None) -> bool:

@classmethod
def is_cygwin(cls) -> bool:
returnis_cygwin_git(cls.GIT_PYTHON_GIT_EXECUTABLE)
return cls.GIT_PYTHON_GIT_EXECUTABLE is not None and sys.platform == "cygwin"
Copy link
Preview

CopilotAIMay 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.


@overload
@classmethod
Expand Down
84 changes: 0 additions & 84 deletionsgit/util.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -96,7 +96,6 @@
Files_TD,
Has_id_attribute,
HSH_TD,
Literal,
PathLike,
Protocol,
SupportsIndex,
Expand DownExpand Up@@ -344,44 +343,6 @@ def _get_exe_extensions() -> Sequence[str]:
return ()


def py_where(program: str, path: Optional[PathLike] = None) -> List[str]:
"""Perform a path search to assist :func:`is_cygwin_git`.

This is not robust for general use. It is an implementation detail of
:func:`is_cygwin_git`. When a search following all shell rules is needed,
:func:`shutil.which` can be used instead.

:note:
Neither this function nor :func:`shutil.which` will predict the effect of an
executable search on a native Windows system due to a :class:`subprocess.Popen`
call without ``shell=True``, because shell and non-shell executable search on
Windows differ considerably.
"""
# From: http://stackoverflow.com/a/377028/548792
winprog_exts = _get_exe_extensions()

def is_exec(fpath: str) -> bool:
return (
osp.isfile(fpath)
and os.access(fpath, os.X_OK)
and (
sys.platform != "win32" or not winprog_exts or any(fpath.upper().endswith(ext) for ext in winprog_exts)
)
)

progs = []
if not path:
path = os.environ["PATH"]
for folder in str(path).split(os.pathsep):
folder = folder.strip('"')
if folder:
exe_path = osp.join(folder, program)
for f in [exe_path] + ["%s%s" % (exe_path, e) for e in winprog_exts]:
if is_exec(f):
progs.append(f)
return progs


def _cygexpath(drive: Optional[str], path: str) -> str:
if osp.isabs(path) and not drive:
# Invoked from `cygpath()` directly with `D:Apps\123`?
Expand DownExpand Up@@ -447,51 +408,6 @@ def decygpath(path: PathLike) -> str:
return path.replace("/", "\\")


#: Store boolean flags denoting if a specific Git executable
#: is from a Cygwin installation (since `cache_lru()` unsupported on PY2).
_is_cygwin_cache: Dict[str, Optional[bool]] = {}


def _is_cygwin_git(git_executable: str) -> bool:
is_cygwin = _is_cygwin_cache.get(git_executable) # type: Optional[bool]
if is_cygwin is None:
is_cygwin = False
try:
git_dir = osp.dirname(git_executable)
if not git_dir:
res = py_where(git_executable)
git_dir = osp.dirname(res[0]) if res else ""

# Just a name given, not a real path.
uname_cmd = osp.join(git_dir, "uname")
process = subprocess.Popen([uname_cmd], stdout=subprocess.PIPE, universal_newlines=True)
uname_out, _ = process.communicate()
# retcode = process.poll()
is_cygwin = "CYGWIN" in uname_out
except Exception as ex:
_logger.debug("Failed checking if running in CYGWIN due to: %r", ex)
_is_cygwin_cache[git_executable] = is_cygwin

return is_cygwin


@overload
def is_cygwin_git(git_executable: None) -> Literal[False]: ...


@overload
def is_cygwin_git(git_executable: PathLike) -> bool: ...


def is_cygwin_git(git_executable: Union[None, PathLike]) -> bool:
if sys.platform == "win32": # TODO: See if we can use `sys.platform != "cygwin"`.
return False
elif git_executable is None:
return False
else:
return _is_cygwin_git(str(git_executable))


def get_user_id() -> str:
""":return: String identifying the currently active system user as ``name@node``"""
return "%s@%s" % (getpass.getuser(), platform.node())
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp