| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d5fc6e5 commit c01fe76
17 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,7 +72,7 @@ jobs: | |||
| 72 | 72 | python --version | |
| 73 | 73 | python -c 'import sys; print(sys.platform)' | |
| 74 | 74 | python -c 'import os; print(os.name)' | |
| 75 | - python -c 'import git; print(git.compat.is_win)' | ||
| 75 | + python -c 'import git; print(git.compat.is_win)' # NOTE: Deprecated. Use os.name directly. | ||
| 76 | 76 | ||
| 77 | 77 | - name: Test with pytest | |
| 78 | 78 | run: | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,7 +63,7 @@ jobs: | |||
| 63 | 63 | python --version | |
| 64 | 64 | python -c 'import sys; print(sys.platform)' | |
| 65 | 65 | python -c 'import os; print(os.name)' | |
| 66 | - python -c 'import git; print(git.compat.is_win)' | ||
| 66 | + python -c 'import git; print(git.compat.is_win)' # NOTE: Deprecated. Use os.name directly. | ||
| 67 | 67 | ||
| 68 | 68 | - name: Check types with mypy | |
| 69 | 69 | run: | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,19 +17,21 @@ | |||
| 17 | 17 | import threading | |
| 18 | 18 | from textwrap import dedent | |
| 19 | 19 | ||
| 20 | - from git.compat import ( | ||
| 21 | - defenc, | ||
| 22 | - force_bytes, | ||
| 23 | - safe_decode, | ||
| 24 | - is_posix, | ||
| 25 | - is_win, | ||
| 20 | + from git.compat import defenc, force_bytes, safe_decode | ||
| 21 | + from git.exc import ( | ||
| 22 | + CommandError, | ||
| 23 | + GitCommandError, | ||
| 24 | + GitCommandNotFound, | ||
| 25 | + UnsafeOptionError, | ||
| 26 | + UnsafeProtocolError, | ||
| 26 | 27 | ) | |
| 27 | - from git.exc import CommandError | ||
| 28 | - from git.util import is_cygwin_git, cygpath, expand_path, remove_password_if_present, patch_env | ||
| 29 | - | ||
| 30 | - from .exc import GitCommandError, GitCommandNotFound, UnsafeOptionError, UnsafeProtocolError | ||
| 31 | - from .util import ( | ||
| 28 | + from git.util import ( | ||
| 32 | 29 | LazyMixin, | |
| 30 | + cygpath, | ||
| 31 | + expand_path, | ||
| 32 | + is_cygwin_git, | ||
| 33 | + patch_env, | ||
| 34 | + remove_password_if_present, | ||
| 33 | 35 | stream_copy, | |
| 34 | 36 | ) | |
| 35 | 37 | ||
@@ -180,14 +182,13 @@ def pump_stream( | |||
| 180 | 182 | t.start() | |
| 181 | 183 | threads.append(t) | |
| 182 | 184 | ||
| 183 | - ## FIXME: Why Join?? Will block if `stdin` needs feeding... | ||
| 184 | - # | ||
| 185 | + # FIXME: Why join? Will block if stdin needs feeding... | ||
| 185 | 186 | for t in threads: | |
| 186 | 187 | t.join(timeout=kill_after_timeout) | |
| 187 | 188 | if t.is_alive(): | |
| 188 | 189 | if isinstance(process, Git.AutoInterrupt): | |
| 189 | 190 | process._terminate() | |
| 190 | - else: # Don't want to deal with the other case | ||
| 191 | + else: # Don't want to deal with the other case. | ||
| 191 | 192 | raise RuntimeError( | |
| 192 | 193 | "Thread join() timed out in cmd.handle_process_output()." | |
| 193 | 194 | f" kill_after_timeout={kill_after_timeout} seconds" | |
@@ -197,11 +198,11 @@ def pump_stream( | |||
| 197 | 198 | "error: process killed because it timed out." f" kill_after_timeout={kill_after_timeout} seconds" | |
| 198 | 199 | ) | |
| 199 | 200 | if not decode_streams and isinstance(p_stderr, BinaryIO): | |
| 200 | - # Assume stderr_handler needs binary input | ||
| 201 | + # Assume stderr_handler needs binary input. | ||
| 201 | 202 | error_str = cast(str, error_str) | |
| 202 | 203 | error_str = error_str.encode() | |
| 203 | 204 | # We ignore typing on the next line because mypy does not like | |
| 204 | - # the way we inferred that stderr takes str or bytes | ||
| 205 | + # the way we inferred that stderr takes str or bytes. | ||
| 205 | 206 | stderr_handler(error_str) # type: ignore | |
| 206 | 207 | ||
| 207 | 208 | if finalizer: | |
@@ -228,14 +229,12 @@ def dict_to_slots_and__excluded_are_none(self: object, d: Mapping[str, Any], exc | |||
| 228 | 229 | ## -- End Utilities -- @} | |
| 229 | 230 | ||
| 230 | 231 | ||
| 231 | - # value of Windows process creation flag taken from MSDN | ||
| 232 | - CREATE_NO_WINDOW = 0x08000000 | ||
| 233 | - | ||
| 234 | - ## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards, | ||
| 235 | - # see https://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal | ||
| 236 | - PROC_CREATIONFLAGS = ( | ||
| 237 | - CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP if is_win else 0 # type: ignore[attr-defined] | ||
| 238 | - ) # mypy error if not Windows. | ||
| 232 | + if os.name == "nt": | ||
| 233 | + # CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards. See: | ||
| 234 | + # https://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal | ||
| 235 | + PROC_CREATIONFLAGS = subprocess.CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP | ||
| 236 | + else: | ||
| 237 | + PROC_CREATIONFLAGS = 0 | ||
| 239 | 238 | ||
| 240 | 239 | ||
| 241 | 240 | class Git(LazyMixin): | |
@@ -551,7 +550,7 @@ def _terminate(self) -> None: | |||
| 551 | 550 | # For some reason, providing None for stdout/stderr still prints something. This is why | |
| 552 | 551 | # we simply use the shell and redirect to nul. Slower than CreateProcess. The question | |
| 553 | 552 | # is whether we really want to see all these messages. It's annoying no matter what. | |
| 554 | - if is_win: | ||
| 553 | + if os.name == "nt": | ||
| 555 | 554 | call( | |
| 556 | 555 | ("TASKKILL /F /T /PID %s 2>nul 1>nul" % str(proc.pid)), | |
| 557 | 556 | shell=True, | |
@@ -967,7 +966,7 @@ def execute( | |||
| 967 | 966 | if inline_env is not None: | |
| 968 | 967 | env.update(inline_env) | |
| 969 | 968 | ||
| 970 | - if is_win: | ||
| 969 | + if os.name == "nt": | ||
| 971 | 970 | cmd_not_found_exception = OSError | |
| 972 | 971 | if kill_after_timeout is not None: | |
| 973 | 972 | raise GitCommandError( | |
@@ -999,11 +998,11 @@ def execute( | |||
| 999 | 998 | env=env, | |
| 1000 | 999 | cwd=cwd, | |
| 1001 | 1000 | bufsize=-1, | |
| 1002 | - stdin=istream or DEVNULL, | ||
| 1001 | + stdin=(istream or DEVNULL), | ||
| 1003 | 1002 | stderr=PIPE, | |
| 1004 | 1003 | stdout=stdout_sink, | |
| 1005 | 1004 | shell=shell, | |
| 1006 | - close_fds=is_posix, # Unsupported on Windows. | ||
| 1005 | + close_fds=(os.name == "posix"), # Unsupported on Windows. | ||
| 1007 | 1006 | universal_newlines=universal_newlines, | |
| 1008 | 1007 | creationflags=PROC_CREATIONFLAGS, | |
| 1009 | 1008 | **subprocess_kwargs, | |
@@ -1073,7 +1072,7 @@ def kill_process(pid: int) -> None: | |||
| 1073 | 1072 | ) | |
| 1074 | 1073 | if not universal_newlines: | |
| 1075 | 1074 | stderr_value = stderr_value.encode(defenc) | |
| 1076 | - # strip trailing "\n" | ||
| 1075 | + # Strip trailing "\n". | ||
| 1077 | 1076 | if stdout_value.endswith(newline) and strip_newline_in_stdout: # type: ignore | |
| 1078 | 1077 | stdout_value = stdout_value[:-1] | |
| 1079 | 1078 | if stderr_value.endswith(newline): # type: ignore | |
@@ -1147,11 +1146,11 @@ def update_environment(self, **kwargs: Any) -> Dict[str, Union[str, None]]: | |||
| 1147 | 1146 | """ | |
| 1148 | 1147 | old_env = {} | |
| 1149 | 1148 | for key, value in kwargs.items(): | |
| 1150 | - # set value if it is None | ||
| 1149 | + # Set value if it is None. | ||
| 1151 | 1150 | if value is not None: | |
| 1152 | 1151 | old_env[key] = self._environment.get(key) | |
| 1153 | 1152 | self._environment[key] = value | |
| 1154 | - # remove key from environment if its value is None | ||
| 1153 | + # Remove key from environment if its value is None. | ||
| 1155 | 1154 | elif key in self._environment: | |
| 1156 | 1155 | old_env[key] = self._environment[key] | |
| 1157 | 1156 | del self._environment[key] | |
@@ -1330,7 +1329,8 @@ def _parse_object_header(self, header_line: str) -> Tuple[str, str, int]: | |||
| 1330 | 1329 | :return: (hex_sha, type_string, size_as_int) | |
| 1331 | 1330 | ||
| 1332 | 1331 | :raise ValueError: If the header contains indication for an error due to | |
| 1333 | - incorrect input sha""" | ||
| 1332 | + incorrect input sha | ||
| 1333 | + """ | ||
| 1334 | 1334 | tokens = header_line.split() | |
| 1335 | 1335 | if len(tokens) != 3: | |
| 1336 | 1336 | if not tokens: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,9 +34,20 @@ | |||
| 34 | 34 | # --------------------------------------------------------------------------- | |
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | + # DEPRECATED attributes providing shortcuts to operating system checks based on os.name. | ||
| 38 | + # | ||
| 39 | + # - is_win and is_posix are deprecated because it is clearer, and helps avoid bugs, to | ||
| 40 | + # write out the os.name checks explicitly. For example, is_win is False on Cygwin, but | ||
| 41 | + # is often assumed to be True. | ||
| 42 | + # | ||
| 43 | + # - is_darwin is deprecated because it is always False on all systems, as os.name is | ||
| 44 | + # never "darwin". For macOS, you can check for sys.platform == "darwin". (As on other | ||
| 45 | + # Unix-like systems, os.name == "posix" on macOS. This is also the case on Cygwin.) | ||
| 46 | + # | ||
| 37 | 47 | is_win: bool = os.name == "nt" | |
| 38 | 48 | is_posix = os.name == "posix" | |
| 39 | 49 | is_darwin = os.name == "darwin" | |
| 50 | + | ||
| 40 | 51 | defenc = sys.getfilesystemencoding() | |
| 41 | 52 | ||
| 42 | 53 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,28 +7,21 @@ | |||
| 7 | 7 | """Module containing module parser implementation able to properly read and write | |
| 8 | 8 | configuration files.""" | |
| 9 | 9 | ||
| 10 | - import sys | ||
| 11 | 10 | import abc | |
| 11 | + import configparser as cp | ||
| 12 | + import fnmatch | ||
| 12 | 13 | from functools import wraps | |
| 13 | 14 | import inspect | |
| 14 | 15 | from io import BufferedReader, IOBase | |
| 15 | 16 | import logging | |
| 16 | 17 | import os | |
| 18 | + import os.path as osp | ||
| 17 | 19 | import re | |
| 18 | - import fnmatch | ||
| 19 | - | ||
| 20 | - from git.compat import ( | ||
| 21 | - defenc, | ||
| 22 | - force_text, | ||
| 23 | - is_win, | ||
| 24 | - ) | ||
| 20 | + import sys | ||
| 25 | 21 | ||
| 22 | + from git.compat import defenc, force_text | ||
| 26 | 23 | from git.util import LockFile | |
| 27 | 24 | ||
| 28 | - import os.path as osp | ||
| 29 | - | ||
| 30 | - import configparser as cp | ||
| 31 | - | ||
| 32 | 25 | # typing------------------------------------------------------- | |
| 33 | 26 | ||
| 34 | 27 | from typing import ( | |
@@ -250,7 +243,7 @@ def items_all(self) -> List[Tuple[str, List[_T]]]: | |||
| 250 | 243 | def get_config_path(config_level: Lit_config_levels) -> str: | |
| 251 | 244 | # We do not support an absolute path of the gitconfig on Windows. | |
| 252 | 245 | # Use the global config instead. | |
| 253 | - if is_win and config_level == "system": | ||
| 246 | + if os.name == "nt" and config_level == "system": | ||
| 254 | 247 | config_level = "global" | |
| 255 | 248 | ||
| 256 | 249 | if config_level == "system": | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,8 +2,9 @@ | |||
| 2 | 2 | # NOTE: Autodoc hates it if this is a docstring. | |
| 3 | 3 | ||
| 4 | 4 | from io import BytesIO | |
| 5 | - from pathlib import Path | ||
| 6 | 5 | import os | |
| 6 | + import os.path as osp | ||
| 7 | + from pathlib import Path | ||
| 7 | 8 | from stat import ( | |
| 8 | 9 | S_IFDIR, | |
| 9 | 10 | S_IFLNK, | |
@@ -16,26 +17,17 @@ | |||
| 16 | 17 | import subprocess | |
| 17 | 18 | ||
| 18 | 19 | from git.cmd import PROC_CREATIONFLAGS, handle_process_output | |
| 19 | - from git.compat import ( | ||
| 20 | - defenc, | ||
| 21 | - force_text, | ||
| 22 | - force_bytes, | ||
| 23 | - is_posix, | ||
| 24 | - is_win, | ||
| 25 | - safe_decode, | ||
| 26 | - ) | ||
| 27 | - from git.exc import UnmergedEntriesError, HookExecutionError | ||
| 20 | + from git.compat import defenc, force_bytes, force_text, safe_decode | ||
| 21 | + from git.exc import HookExecutionError, UnmergedEntriesError | ||
| 28 | 22 | from git.objects.fun import ( | |
| 29 | - tree_to_stream, | ||
| 30 | 23 | traverse_tree_recursive, | |
| 31 | 24 | traverse_trees_recursive, | |
| 25 | + tree_to_stream, | ||
| 32 | 26 | ) | |
| 33 | 27 | from git.util import IndexFileSHA1Writer, finalize_process | |
| 34 | 28 | from gitdb.base import IStream | |
| 35 | 29 | from gitdb.typ import str_tree_type | |
| 36 | 30 | ||
| 37 | - import os.path as osp | ||
| 38 | - | ||
| 39 | 31 | from .typ import BaseIndexEntry, IndexEntry, CE_NAMEMASK, CE_STAGESHIFT | |
| 40 | 32 | from .util import pack, unpack | |
| 41 | 33 | ||
@@ -96,7 +88,7 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None: | |||
| 96 | 88 | env["GIT_EDITOR"] = ":" | |
| 97 | 89 | cmd = [hp] | |
| 98 | 90 | try: | |
| 99 | - if is_win and not _has_file_extension(hp): | ||
| 91 | + if os.name == "nt" and not _has_file_extension(hp): | ||
| 100 | 92 | # Windows only uses extensions to determine how to open files | |
| 101 | 93 | # (doesn't understand shebangs). Try using bash to run the hook. | |
| 102 | 94 | relative_hp = Path(hp).relative_to(index.repo.working_dir).as_posix() | |
@@ -108,7 +100,7 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None: | |||
| 108 | 100 | stdout=subprocess.PIPE, | |
| 109 | 101 | stderr=subprocess.PIPE, | |
| 110 | 102 | cwd=index.repo.working_dir, | |
| 111 | - close_fds=is_posix, | ||
| 103 | + close_fds=(os.name == "posix"), | ||
| 112 | 104 | creationflags=PROC_CREATIONFLAGS, | |
| 113 | 105 | ) | |
| 114 | 106 | except Exception as ex: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,15 +2,11 @@ | |||
| 2 | 2 | ||
| 3 | 3 | from functools import wraps | |
| 4 | 4 | import os | |
| 5 | + import os.path as osp | ||
| 5 | 6 | import struct | |
| 6 | 7 | import tempfile | |
| 7 | 8 | from types import TracebackType | |
| 8 | 9 | ||
| 9 | - from git.compat import is_win | ||
| 10 | - | ||
| 11 | - import os.path as osp | ||
| 12 | - | ||
| 13 | - | ||
| 14 | 10 | # typing ---------------------------------------------------------------------- | |
| 15 | 11 | ||
| 16 | 12 | from typing import Any, Callable, TYPE_CHECKING, Optional, Type | |
@@ -58,7 +54,7 @@ def __exit__( | |||
| 58 | 54 | exc_tb: Optional[TracebackType], | |
| 59 | 55 | ) -> bool: | |
| 60 | 56 | if osp.isfile(self.tmp_file_path): | |
| 61 | - if is_win and osp.exists(self.file_path): | ||
| 57 | + if os.name == "nt" and osp.exists(self.file_path): | ||
| 62 | 58 | os.remove(self.file_path) | |
| 63 | 59 | os.rename(self.tmp_file_path, self.file_path) | |
| 64 | 60 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | 8 | import git | |
| 9 | 9 | from git.cmd import Git | |
| 10 | - from git.compat import defenc, is_win | ||
| 10 | + from git.compat import defenc | ||
| 11 | 11 | from git.config import GitConfigParser, SectionConstraint, cp | |
| 12 | 12 | from git.exc import ( | |
| 13 | 13 | BadName, | |
@@ -353,9 +353,8 @@ def _write_git_file_and_module_config(cls, working_tree_dir: PathLike, module_ab | |||
| 353 | 353 | """ | |
| 354 | 354 | git_file = osp.join(working_tree_dir, ".git") | |
| 355 | 355 | rela_path = osp.relpath(module_abspath, start=working_tree_dir) | |
| 356 | - if is_win: | ||
| 357 | - if osp.isfile(git_file): | ||
| 358 | - os.remove(git_file) | ||
| 356 | + if os.name == "nt" and osp.isfile(git_file): | ||
| 357 | + os.remove(git_file) | ||
| 359 | 358 | with open(git_file, "wb") as fp: | |
| 360 | 359 | fp.write(("gitdir: %s" % rela_path).encode(defenc)) | |
| 361 | 360 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments