Skip to content

Commit a05597a

Browse files
committed
Improve how imports and __all__ are written in git.util
+ Update the detailed comment about the unused import situation.
1 parent de540b7 commit a05597a

File tree

1 file changed

+53
-49
lines changed

1 file changed

+53
-49
lines changed

Diff for: git/util.py

+53-49
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@
33
# This module is part of GitPython and is released under the
44
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
55

6+
import sys
7+
8+
__all__ = [
9+
"stream_copy",
10+
"join_path",
11+
"to_native_path_linux",
12+
"join_path_native",
13+
"Stats",
14+
"IndexFileSHA1Writer",
15+
"IterableObj",
16+
"IterableList",
17+
"BlockingLockFile",
18+
"LockFile",
19+
"Actor",
20+
"get_user_id",
21+
"assure_directory_exists",
22+
"RemoteProgress",
23+
"CallableRemoteProgress",
24+
"rmtree",
25+
"unbare_repo",
26+
"HIDE_WINDOWS_KNOWN_ERRORS",
27+
]
28+
29+
if sys.platform == "win32":
30+
__all__.append("to_native_path_windows")
31+
632
from abc import abstractmethod
733
import contextlib
834
from functools import wraps
@@ -16,11 +42,27 @@
1642
import shutil
1743
import stat
1844
import subprocess
19-
import sys
2045
import time
2146
from urllib.parse import urlsplit, urlunsplit
2247
import warnings
2348

49+
# NOTE: Unused imports can be improved now that CI testing has fully resumed. Some of
50+
# these be used indirectly through other GitPython modules, which avoids having to write
51+
# gitdb all the time in their imports. They are not in __all__, at least currently,
52+
# because they could be removed or changed at any time, and so should not be considered
53+
# conceptually public to code outside GitPython. Linters of course do not like it.
54+
from gitdb.util import ( # noqa: F401 # @IgnorePep8
55+
LazyMixin, # @UnusedImport
56+
LockedFD, # @UnusedImport
57+
bin_to_hex, # @UnusedImport
58+
file_contents_ro_filepath, # @UnusedImport
59+
file_contents_ro, # @UnusedImport
60+
hex_to_bin, # @UnusedImport
61+
make_sha,
62+
to_bin_sha, # @UnusedImport
63+
to_hex_sha, # @UnusedImport
64+
)
65+
2466
# typing ---------------------------------------------------------
2567

2668
from typing import (
@@ -37,73 +79,36 @@
3779
Pattern,
3880
Sequence,
3981
Tuple,
82+
TYPE_CHECKING,
4083
TypeVar,
4184
Union,
42-
TYPE_CHECKING,
4385
cast,
4486
overload,
4587
)
4688

4789
if TYPE_CHECKING:
90+
from git.cmd import Git
91+
from git.config import GitConfigParser, SectionConstraint
4892
from git.remote import Remote
4993
from git.repo.base import Repo
50-
from git.config import GitConfigParser, SectionConstraint
51-
from git import Git
5294

53-
from .types import (
95+
from git.types import (
96+
Files_TD,
97+
Has_id_attribute,
98+
HSH_TD,
5499
Literal,
55-
SupportsIndex,
56-
Protocol,
57-
runtime_checkable, # because behind py version guards
58100
PathLike,
59-
HSH_TD,
101+
Protocol,
102+
SupportsIndex,
60103
Total_TD,
61-
Files_TD, # aliases
62-
Has_id_attribute,
104+
runtime_checkable,
63105
)
64106

65107
# ---------------------------------------------------------------------
66108

67-
from gitdb.util import ( # noqa: F401 # @IgnorePep8
68-
make_sha,
69-
LockedFD, # @UnusedImport
70-
file_contents_ro, # @UnusedImport
71-
file_contents_ro_filepath, # @UnusedImport
72-
LazyMixin, # @UnusedImport
73-
to_hex_sha, # @UnusedImport
74-
to_bin_sha, # @UnusedImport
75-
bin_to_hex, # @UnusedImport
76-
hex_to_bin, # @UnusedImport
77-
)
78-
79109
T_IterableObj = TypeVar("T_IterableObj", bound=Union["IterableObj", "Has_id_attribute"], covariant=True)
80110
# So IterableList[Head] is subtype of IterableList[IterableObj].
81111

82-
# NOTE: Some of the unused imports might be used/imported by others.
83-
# Handle once test-cases are back up and running.
84-
# Most of these are unused here, but are for use by git-python modules so these
85-
# don't see gitdb all the time. Flake of course doesn't like it.
86-
__all__ = [
87-
"stream_copy",
88-
"join_path",
89-
"to_native_path_linux",
90-
"join_path_native",
91-
"Stats",
92-
"IndexFileSHA1Writer",
93-
"IterableObj",
94-
"IterableList",
95-
"BlockingLockFile",
96-
"LockFile",
97-
"Actor",
98-
"get_user_id",
99-
"assure_directory_exists",
100-
"RemoteProgress",
101-
"CallableRemoteProgress",
102-
"rmtree",
103-
"unbare_repo",
104-
"HIDE_WINDOWS_KNOWN_ERRORS",
105-
]
106-
107112
_logger = logging.getLogger(__name__)
108113

109114

@@ -292,7 +297,6 @@ def to_native_path_linux(path: PathLike) -> str:
292297
path = str(path)
293298
return path.replace("\\", "/")
294299

295-
__all__.append("to_native_path_windows")
296300
to_native_path = to_native_path_windows
297301
else:
298302
# No need for any work on Linux.

0 commit comments

Comments
 (0)