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