|
5 | 5 | # the BSD License: https://opensource.org/license/bsd-3-clause/ |
6 | 6 |
|
7 | 7 | fromabcimportabstractmethod |
8 | | -importos.pathasosp |
9 | | -from .compatimportis_win |
10 | 8 | importcontextlib |
11 | 9 | fromfunctoolsimportwraps |
12 | 10 | importgetpass |
13 | 11 | importlogging |
14 | 12 | importos |
| 13 | +importos.pathasosp |
| 14 | +importpathlib |
15 | 15 | importplatform |
16 | | -importsubprocess |
17 | 16 | importre |
18 | 17 | importshutil |
19 | 18 | importstat |
20 | | -fromsysimportmaxsize |
| 19 | +importsubprocess |
| 20 | +importsys |
21 | 21 | importtime |
22 | 22 | fromurllib.parseimporturlsplit, urlunsplit |
23 | 23 | importwarnings |
24 | 24 |
|
25 | | -# from git.objects.util import Traversable |
| 25 | +from.compatimportis_win |
26 | 26 |
|
27 | 27 | # typing --------------------------------------------------------- |
28 | 28 |
|
|
42 | 42 | Tuple, |
43 | 43 | TypeVar, |
44 | 44 | Union, |
45 | | -cast, |
46 | 45 | TYPE_CHECKING, |
| 46 | +cast, |
47 | 47 | overload, |
48 | 48 | ) |
49 | 49 |
|
50 | | -importpathlib |
51 | | - |
52 | 50 | ifTYPE_CHECKING: |
53 | 51 | fromgit.remoteimportRemote |
54 | 52 | fromgit.repo.baseimportRepo |
55 | 53 | fromgit.configimportGitConfigParser, SectionConstraint |
56 | 54 | fromgitimportGit |
57 | 55 |
|
58 | | -# from git.objects.base import IndexObject |
59 | | - |
60 | | - |
61 | 56 | from .typesimport ( |
62 | 57 | Literal, |
63 | 58 | SupportsIndex, |
|
75 | 70 |
|
76 | 71 | # --------------------------------------------------------------------- |
77 | 72 |
|
78 | | - |
79 | 73 | fromgitdb.utilimport ( # NOQA @IgnorePep8 |
80 | 74 | make_sha, |
81 | 75 | LockedFD, # @UnusedImport |
|
88 | 82 | hex_to_bin, # @UnusedImport |
89 | 83 | ) |
90 | 84 |
|
91 | | - |
92 | 85 | # NOTE: Some of the unused imports might be used/imported by others. |
93 | 86 | # Handle once test-cases are back up and running. |
94 | 87 | # Most of these are unused here, but are for use by git-python modules so these |
|
116 | 109 |
|
117 | 110 | log=logging.getLogger(__name__) |
118 | 111 |
|
119 | | -# types############################################################ |
| 112 | + |
| 113 | +def_read_env_flag(name: str, default: bool) ->bool: |
| 114 | +try: |
| 115 | +value=os.environ[name] |
| 116 | +exceptKeyError: |
| 117 | +returndefault |
| 118 | + |
| 119 | +log.warning( |
| 120 | +"The %s environment variable is deprecated. Its effect has never been documented and changes without warning.", |
| 121 | +name, |
| 122 | + ) |
| 123 | + |
| 124 | +adjusted_value=value.strip().lower() |
| 125 | + |
| 126 | +ifadjusted_valuein{"", "0", "false", "no"}: |
| 127 | +returnFalse |
| 128 | +ifadjusted_valuein{"1", "true", "yes"}: |
| 129 | +returnTrue |
| 130 | +log.warning("%s has unrecognized value %r, treating as %r.", name, value, default) |
| 131 | +returndefault |
120 | 132 |
|
121 | 133 |
|
122 | 134 | #: We need an easy way to see if Appveyor TCs start failing, |
123 | 135 | #: so the errors marked with this var are considered "acknowledged" ones, awaiting remedy, |
124 | 136 | #: till then, we wish to hide them. |
125 | | -HIDE_WINDOWS_KNOWN_ERRORS=is_winandos.environ.get("HIDE_WINDOWS_KNOWN_ERRORS", True) |
126 | | -HIDE_WINDOWS_FREEZE_ERRORS=is_winandos.environ.get("HIDE_WINDOWS_FREEZE_ERRORS", True) |
| 137 | +HIDE_WINDOWS_KNOWN_ERRORS=is_winand_read_env_flag("HIDE_WINDOWS_KNOWN_ERRORS", True) |
| 138 | +HIDE_WINDOWS_FREEZE_ERRORS=is_winand_read_env_flag("HIDE_WINDOWS_FREEZE_ERRORS", True) |
127 | 139 |
|
128 | 140 | #{Utility Methods |
129 | 141 |
|
@@ -177,25 +189,29 @@ def patch_env(name: str, value: str) -> Generator[None, None, None]: |
177 | 189 |
|
178 | 190 |
|
179 | 191 | defrmtree(path: PathLike) ->None: |
180 | | -"""Remove the given recursively. |
| 192 | +"""Remove the given directory tree recursively. |
181 | 193 |
|
182 | | - :note: we use shutilrmtree but adjust its behaviour to see whether files that |
183 | | - couldn't be deleted are read-only. Windows will not remove them in that case""" |
| 194 | + :note: We use :func:`shutil.rmtree` but adjust its behaviour to see whether files that |
| 195 | + couldn't be deleted are read-only. Windows will not remove them in that case.""" |
184 | 196 |
|
185 | | -defonerror(func: Callable, path: PathLike, exc_info: str) ->None: |
186 | | -# Is the error an access error ? |
| 197 | +defhandler(function: Callable, path: PathLike, _excinfo: Any) ->None: |
| 198 | +"""Callback for :func:`shutil.rmtree`. Works either as ``onexc`` or ``onerror``.""" |
| 199 | +# Is the error an access error? |
187 | 200 | os.chmod(path, stat.S_IWUSR) |
188 | 201 |
|
189 | 202 | try: |
190 | | -func(path)# Will scream if still not possible to delete. |
191 | | -exceptExceptionasex: |
| 203 | +function(path) |
| 204 | +exceptPermissionErrorasex: |
192 | 205 | ifHIDE_WINDOWS_KNOWN_ERRORS: |
193 | 206 | fromunittestimportSkipTest |
194 | 207 |
|
195 | | -raiseSkipTest("FIXME: fails with: PermissionError\n{}".format(ex)) fromex |
| 208 | +raiseSkipTest(f"FIXME: fails with: PermissionError\n{ex}") fromex |
196 | 209 | raise |
197 | 210 |
|
198 | | -returnshutil.rmtree(path, False, onerror) |
| 211 | +ifsys.version_info>= (3, 12): |
| 212 | +shutil.rmtree(path, onexc=handler) |
| 213 | +else: |
| 214 | +shutil.rmtree(path, onerror=handler) |
199 | 215 |
|
200 | 216 |
|
201 | 217 | defrmfile(path: PathLike) ->None: |
@@ -995,7 +1011,7 @@ def __init__( |
995 | 1011 | self, |
996 | 1012 | file_path: PathLike, |
997 | 1013 | check_interval_s: float=0.3, |
998 | | -max_block_time_s: int=maxsize, |
| 1014 | +max_block_time_s: int=sys.maxsize, |
999 | 1015 | ) ->None: |
1000 | 1016 | """Configure the instance |
1001 | 1017 |
|
|
0 commit comments