| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,12 +6,16 @@ | |||
| 6 | 6 | ) | |
| 7 | 7 | from gitdb.db import GitDB # @UnusedImport | |
| 8 | 8 | from gitdb.db import LooseObjectDB | |
| 9 | + from gitdb.exc import BadObject | ||
| 9 | 10 | ||
| 10 | - from .exc import ( | ||
| 11 | - GitCommandError, | ||
| 12 | - BadObject | ||
| 13 | - ) | ||
| 11 | + from .exc import GitCommandError | ||
| 12 | + | ||
| 13 | + # typing------------------------------------------------- | ||
| 14 | + | ||
| 15 | + from .cmd import Git | ||
| 16 | + from .types import PathLike, TBD | ||
| 14 | 17 | ||
| 18 | + # -------------------------------------------------------- | ||
| 15 | 19 | ||
| 16 | 20 | __all__ = ('GitCmdObjectDB', 'GitDB') | |
| 17 | 21 | ||
@@ -28,23 +32,23 @@ class GitCmdObjectDB(LooseObjectDB): | |||
| 28 | 32 | have packs and the other implementations | |
| 29 | 33 | """ | |
| 30 | 34 | ||
| 31 | - def __init__(self, root_path, git): | ||
| 35 | + def __init__(self, root_path: PathLike, git: Git) -> None: | ||
| 32 | 36 | """Initialize this instance with the root and a git command""" | |
| 33 | 37 | super(GitCmdObjectDB, self).__init__(root_path) | |
| 34 | 38 | self._git = git | |
| 35 | 39 | ||
| 36 | - def info(self, sha): | ||
| 40 | + def info(self, sha: bytes) -> OInfo: | ||
| 37 | 41 | hexsha, typename, size = self._git.get_object_header(bin_to_hex(sha)) | |
| 38 | 42 | return OInfo(hex_to_bin(hexsha), typename, size) | |
| 39 | 43 | ||
| 40 | - def stream(self, sha): | ||
| 44 | + def stream(self, sha: bytes) -> OStream: | ||
| 41 | 45 | """For now, all lookup is done by git itself""" | |
| 42 | 46 | hexsha, typename, size, stream = self._git.stream_object_data(bin_to_hex(sha)) | |
| 43 | 47 | return OStream(hex_to_bin(hexsha), typename, size, stream) | |
| 44 | 48 | ||
| 45 | 49 | # { Interface | |
| 46 | 50 | ||
| 47 | - def partial_to_complete_sha_hex(self, partial_hexsha): | ||
| 51 | + def partial_to_complete_sha_hex(self, partial_hexsha: str) -> bytes: | ||
| 48 | 52 | """:return: Full binary 20 byte sha from the given partial hexsha | |
| 49 | 53 | :raise AmbiguousObjectName: | |
| 50 | 54 | :raise BadObject: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,13 @@ | |||
| 8 | 8 | from gitdb.exc import * # NOQA @UnusedWildImport skipcq: PYL-W0401, PYL-W0614 | |
| 9 | 9 | from git.compat import safe_decode | |
| 10 | 10 | ||
| 11 | + # typing ---------------------------------------------------- | ||
| 12 | + | ||
| 13 | + from git.repo.base import Repo | ||
| 14 | + from git.types import PathLike | ||
| 15 | + from typing import IO, List, Optional, Sequence, Tuple, Union | ||
| 16 | + | ||
| 17 | + # ------------------------------------------------------------------ | ||
| 11 | 18 | ||
| 12 | 19 | class GitError(Exception): | |
| 13 | 20 | """ Base class for all package exceptions """ | |
@@ -37,7 +44,9 @@ class CommandError(GitError): | |||
| 37 | 44 | #: "'%s' failed%s" | |
| 38 | 45 | _msg = "Cmd('%s') failed%s" | |
| 39 | 46 | ||
| 40 | - def __init__(self, command, status=None, stderr=None, stdout=None): | ||
| 47 | + def __init__(self, command: Union[List[str], Tuple[str, ...], str], | ||
| 48 | + status: Union[str, None, Exception] = None, | ||
| 49 | + stderr: Optional[IO[str]] = None, stdout: Optional[IO[str]] = None) -> None: | ||
| 41 | 50 | if not isinstance(command, (tuple, list)): | |
| 42 | 51 | command = command.split() | |
| 43 | 52 | self.command = command | |
@@ -53,28 +62,33 @@ def __init__(self, command, status=None, stderr=None, stdout=None): | |||
| 53 | 62 | status = "'%s'" % s if isinstance(status, str) else s | |
| 54 | 63 | ||
| 55 | 64 | self._cmd = safe_decode(command[0]) | |
| 56 | - self._cmdline = ' '.join(safe_decode(i) for i in command) | ||
| 65 | + self._cmdline = ' '.join(str(safe_decode(i)) for i in command) | ||
| 57 | 66 | self._cause = status and " due to: %s" % status or "!" | |
| 58 | - self.stdout = stdout and "\n stdout: '%s'" % safe_decode(stdout) or '' | ||
| 59 | - self.stderr = stderr and "\n stderr: '%s'" % safe_decode(stderr) or '' | ||
| 67 | + self.stdout = stdout and "\n stdout: '%s'" % safe_decode(str(stdout)) or '' | ||
| 68 | + self.stderr = stderr and "\n stderr: '%s'" % safe_decode(str(stderr)) or '' | ||
| 60 | 69 | ||
| 61 | - def __str__(self): | ||
| 70 | + def __str__(self) -> str: | ||
| 62 | 71 | return (self._msg + "\n cmdline: %s%s%s") % ( | |
| 63 | 72 | self._cmd, self._cause, self._cmdline, self.stdout, self.stderr) | |
| 64 | 73 | ||
| 65 | 74 | ||
| 66 | 75 | class GitCommandNotFound(CommandError): | |
| 67 | 76 | """Thrown if we cannot find the `git` executable in the PATH or at the path given by | |
| 68 | 77 | the GIT_PYTHON_GIT_EXECUTABLE environment variable""" | |
| 69 | - def __init__(self, command, cause): | ||
| 78 | + | ||
| 79 | + def __init__(self, command: Union[List[str], Tuple[str], str], cause: Union[str, Exception]) -> None: | ||
| 70 | 80 | super(GitCommandNotFound, self).__init__(command, cause) | |
| 71 | 81 | self._msg = "Cmd('%s') not found%s" | |
| 72 | 82 | ||
| 73 | 83 | ||
| 74 | 84 | class GitCommandError(CommandError): | |
| 75 | 85 | """ Thrown if execution of the git command fails with non-zero status code. """ | |
| 76 | 86 | ||
| 77 | - def __init__(self, command, status, stderr=None, stdout=None): | ||
| 87 | + def __init__(self, command: Union[List[str], Tuple[str, ...], str], | ||
| 88 | + status: Union[str, None, Exception] = None, | ||
| 89 | + stderr: Optional[IO[str]] = None, | ||
| 90 | + stdout: Optional[IO[str]] = None, | ||
| 91 | + ) -> None: | ||
| 78 | 92 | super(GitCommandError, self).__init__(command, status, stderr, stdout) | |
| 79 | 93 | ||
| 80 | 94 | ||
@@ -92,13 +106,13 @@ class CheckoutError(GitError): | |||
| 92 | 106 | were checked out successfully and hence match the version stored in the | |
| 93 | 107 | index""" | |
| 94 | 108 | ||
| 95 | - def __init__(self, message, failed_files, valid_files, failed_reasons): | ||
| 109 | + def __init__(self, message: str, failed_files: List[PathLike], valid_files: List[PathLike], failed_reasons: List[str]) -> None: | ||
| 96 | 110 | Exception.__init__(self, message) | |
| 97 | 111 | self.failed_files = failed_files | |
| 98 | 112 | self.failed_reasons = failed_reasons | |
| 99 | 113 | self.valid_files = valid_files | |
| 100 | 114 | ||
| 101 | - def __str__(self): | ||
| 115 | + def __str__(self) -> str: | ||
| 102 | 116 | return Exception.__str__(self) + ":%s" % self.failed_files | |
| 103 | 117 | ||
| 104 | 118 | ||
@@ -116,17 +130,18 @@ class HookExecutionError(CommandError): | |||
| 116 | 130 | """Thrown if a hook exits with a non-zero exit code. It provides access to the exit code and the string returned | |
| 117 | 131 | via standard output""" | |
| 118 | 132 | ||
| 119 | - def __init__(self, command, status, stderr=None, stdout=None): | ||
| 133 | + def __init__(self, command: Union[List[str], Tuple[str, ...], str], status: Optional[str], | ||
| 134 | + stderr: Optional[IO[str]] = None, stdout: Optional[IO[str]] = None) -> None: | ||
| 120 | 135 | super(HookExecutionError, self).__init__(command, status, stderr, stdout) | |
| 121 | 136 | self._msg = "Hook('%s') failed%s" | |
| 122 | 137 | ||
| 123 | 138 | ||
| 124 | 139 | class RepositoryDirtyError(GitError): | |
| 125 | 140 | """Thrown whenever an operation on a repository fails as it has uncommitted changes that would be overwritten""" | |
| 126 | 141 | ||
| 127 | - def __init__(self, repo, message): | ||
| 142 | + def __init__(self, repo: Repo, message: str) -> None: | ||
| 128 | 143 | self.repo = repo | |
| 129 | 144 | self.message = message | |
| 130 | 145 | ||
| 131 | - def __str__(self): | ||
| 146 | + def __str__(self) -> str: | ||
| 132 | 147 | return "Operation cannot be performed on %r: %s" % (self.repo, self.message) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,3 +2,5 @@ | |||
| 2 | 2 | [mypy] | |
| 3 | 3 | ||
| 4 | 4 | disallow_untyped_defs = True | |
| 5 | + | ||
| 6 | + mypy_path = 'git' | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments