Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace all wildcard imports with explicit imports #1880

Merged
merged 34 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1e5a944
Add a script to validate refactored imports
EliahKagan Mar 17, 2024
5b2771d
Add regression tests of the git.util aliasing situation
EliahKagan Mar 18, 2024
fc86a23
Incompletely change git.index imports to test modattrs.py
EliahKagan Feb 24, 2024
4badc19
Fix git.index imports
EliahKagan Mar 18, 2024
1c9bda2
Improve relative order of import groups, and __all__, in git.index
EliahKagan Mar 18, 2024
8b51af3
Improve order of imports and __all__ in git.refs submodules
EliahKagan Mar 18, 2024
b25dd7e
Replace wildcard imports in git.refs
EliahKagan Mar 18, 2024
b32ef65
Improve order of imports and __all__ in git.repo submodules
EliahKagan Mar 18, 2024
0ba06e9
Add git.repo.__all__ and make submodules explicit
EliahKagan Mar 18, 2024
c946906
Improve order of imports and __all__ in git.objects.*
EliahKagan Mar 18, 2024
4e9a2f2
Improve order of imports and __all__ in git.object.submodule.*
EliahKagan Mar 18, 2024
c58be4c
Remove a bit of old commented-out code in git.objects.*
EliahKagan Mar 18, 2024
01c95eb
Don't patch IndexObject and Object into git.objects.submodule.util
EliahKagan Mar 18, 2024
f89d065
Fix git.objects.__all__ and make submodules explicit
EliahKagan Mar 18, 2024
3786307
Make git.objects.util module docstring more specific
EliahKagan Mar 18, 2024
de540b7
Add __all__ and imports in git.objects.submodule
EliahKagan Mar 18, 2024
a05597a
Improve how imports and __all__ are written in git.util
EliahKagan Mar 18, 2024
2053a3d
Remove old commented-out change_type assertions in git.diff
EliahKagan Mar 18, 2024
b8bab43
Remove old commented-out flagKeyLiteral assertions in git.remote
EliahKagan Mar 19, 2024
3d4e476
Improve how second-level imports and __all__ are written
EliahKagan Mar 19, 2024
6318eea
Make F401 "unused import" suppressions more specific
EliahKagan Mar 19, 2024
31bc8a4
Remove unneeded F401 "Unused import" suppressions
EliahKagan Mar 19, 2024
abbe74d
Fix a tiny import sorting nit
EliahKagan Mar 19, 2024
7745250
Replace wildcard imports in top-level git module
EliahKagan Mar 19, 2024
64c9efd
Restore relative order to fix circular import error
EliahKagan Mar 19, 2024
31f89a1
Add the nonpublic indirect submodule aliases back for now
EliahKagan Mar 19, 2024
9bbbcb5
Further improve git.objects.util module docstring
EliahKagan Mar 19, 2024
00f4cbc
Add missing submodule imports in git.objects
EliahKagan Mar 19, 2024
fcc7418
Don't explicitly list direct submodules in __all__
EliahKagan Mar 19, 2024
78055a8
Pick a consistent type for __all__ (for now, list)
EliahKagan Mar 19, 2024
ecdb6aa
Save diff of non-__all__ attributes across import changes
EliahKagan Mar 19, 2024
f705fd6
Remove modattrs.py and related
EliahKagan Mar 19, 2024
4a4d880
Improve test suite import grouping/sorting, __all__ placement
EliahKagan Mar 19, 2024
d524c76
Fix slightly unsorted imports in setup.py
EliahKagan Mar 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 97 additions & 17 deletions git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# @PydevCodeAnalysisIgnore

__all__ = [ # noqa: F405
__all__ = [
"Actor",
"AmbiguousObjectName",
"BadName",
Expand Down Expand Up @@ -88,32 +88,112 @@

__version__ = "git"

from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING
from typing import List, Optional, Sequence, TYPE_CHECKING, Tuple, Union

from gitdb.util import to_hex_sha
from git.exc import * # noqa: F403 # @NoMove @IgnorePep8

from git.exc import (
AmbiguousObjectName,
BadName,
BadObject,
BadObjectType,
CacheError,
CheckoutError,
CommandError,
GitCommandError,
GitCommandNotFound,
GitError,
HookExecutionError,
InvalidDBRoot,
InvalidGitRepositoryError,
NoSuchPathError,
ODBError,
ParseError,
RepositoryDirtyError,
UnmergedEntriesError,
UnsafeOptionError,
UnsafeProtocolError,
UnsupportedOperation,
WorkTreeRepositoryUnsupported,
)
from git.types import PathLike

try:
from git.compat import safe_decode # @NoMove @IgnorePep8
from git.config import GitConfigParser # @NoMove @IgnorePep8
from git.objects import * # noqa: F403 # @NoMove @IgnorePep8
from git.refs import * # noqa: F403 # @NoMove @IgnorePep8
from git.diff import * # noqa: F403 # @NoMove @IgnorePep8
from git.db import * # noqa: F403 # @NoMove @IgnorePep8
from git.cmd import Git # @NoMove @IgnorePep8
from git.repo import Repo # @NoMove @IgnorePep8
from git.remote import * # noqa: F403 # @NoMove @IgnorePep8
from git.index import * # noqa: F403 # @NoMove @IgnorePep8
from git.util import ( # @NoMove @IgnorePep8
LockFile,
from git.compat import safe_decode # @NoMove
from git.config import GitConfigParser # @NoMove
from git.objects import ( # @NoMove
Blob,
Commit,
IndexObject,
Object,
RootModule,
RootUpdateProgress,
Submodule,
TagObject,
Tree,
TreeModifier,
UpdateProgress,
)
from git.refs import ( # @NoMove
HEAD,
Head,
RefLog,
RefLogEntry,
Reference,
RemoteReference,
SymbolicReference,
Tag,
TagReference,
head, # noqa: F401 # Nonpublic. May disappear! Use git.refs.head.
log, # noqa: F401 # Nonpublic. May disappear! Use git.refs.log.
reference, # noqa: F401 # Nonpublic. May disappear! Use git.refs.reference.
symbolic, # noqa: F401 # Nonpublic. May disappear! Use git.refs.symbolic.
tag, # noqa: F401 # Nonpublic. May disappear! Use git.refs.tag.
)
from git.diff import ( # @NoMove
INDEX,
NULL_TREE,
Diff,
DiffConstants,
DiffIndex,
Diffable,
)
from git.db import GitCmdObjectDB, GitDB # @NoMove
from git.cmd import Git # @NoMove
from git.repo import Repo # @NoMove
from git.remote import FetchInfo, PushInfo, Remote, RemoteProgress # @NoMove
from git.index import ( # @NoMove
BaseIndexEntry,
BlobFilter,
CheckoutError,
IndexEntry,
IndexFile,
StageType,
base, # noqa: F401 # Nonpublic. May disappear! Use git.index.base.
fun, # noqa: F401 # Nonpublic. May disappear! Use git.index.fun.
typ, # noqa: F401 # Nonpublic. May disappear! Use git.index.typ.
#
# NOTE: The expression `git.util` evaluates to git.index.util, and the import
# `from git import util` imports git.index.util, NOT git.util. It may not be
# feasible to change this until the next major version, to avoid breaking code
# inadvertently relying on it. If git.index.util really is what you want, use or
# import from that name, to avoid confusion. To use the "real" git.util module,
# write `from git.util import ...`, or access it as `sys.modules["git.util"]`.
# (This differs from other historical indirect-submodule imports that are
# unambiguously nonpublic and are subject to immediate removal. Here, the public
# git.util module, even though different, makes it less discoverable that the
# expression `git.util` refers to a non-public attribute of the git module.)
util, # noqa: F401
)
from git.util import ( # @NoMove
Actor,
BlockingLockFile,
LockFile,
Stats,
Actor,
remove_password_if_present,
rmtree,
)
except GitError as _exc: # noqa: F405
except GitError as _exc:
raise ImportError("%s: %s" % (_exc.__class__.__name__, _exc)) from _exc

# { Initialize git executable path
Expand Down
15 changes: 7 additions & 8 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@

from __future__ import annotations

import re
__all__ = ["Git"]

import contextlib
import io
import itertools
import logging
import os
import re
import signal
from subprocess import Popen, PIPE, DEVNULL
import subprocess
from subprocess import DEVNULL, PIPE, Popen
import sys
import threading
from textwrap import dedent
import threading

from git.compat import defenc, force_bytes, safe_decode
from git.exc import (
Expand Down Expand Up @@ -57,12 +59,11 @@
overload,
)

from git.types import PathLike, Literal, TBD
from git.types import Literal, PathLike, TBD

if TYPE_CHECKING:
from git.repo.base import Repo
from git.diff import DiffIndex

from git.repo.base import Repo

# ---------------------------------------------------------------------------------

Expand All @@ -84,8 +85,6 @@

_logger = logging.getLogger(__name__)

__all__ = ("Git",)


# ==============================================================================
## @name Utilities
Expand Down
14 changes: 7 additions & 7 deletions git/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
import os
import sys

from gitdb.utils.encoding import force_bytes, force_text # noqa: F401 # @UnusedImport
from gitdb.utils.encoding import force_bytes, force_text # noqa: F401

# typing --------------------------------------------------------------------

from typing import ( # noqa: F401
Any,
from typing import (
Any, # noqa: F401
AnyStr,
Dict,
IO,
Dict, # noqa: F401
IO, # noqa: F401
Optional,
Tuple,
Type,
Tuple, # noqa: F401
Type, # noqa: F401
Union,
overload,
)
Expand Down
7 changes: 4 additions & 3 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

"""Parser for reading and writing configuration files."""

__all__ = ["GitConfigParser", "SectionConstraint"]

import abc
import configparser as cp
import fnmatch
Expand Down Expand Up @@ -40,9 +42,10 @@
from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, assert_never, _T

if TYPE_CHECKING:
from git.repo.base import Repo
from io import BytesIO

from git.repo.base import Repo

T_ConfigParser = TypeVar("T_ConfigParser", bound="GitConfigParser")
T_OMD_value = TypeVar("T_OMD_value", str, bytes, int, float, bool)

Expand All @@ -58,8 +61,6 @@

# -------------------------------------------------------------

__all__ = ("GitConfigParser", "SectionConstraint")

_logger = logging.getLogger(__name__)

CONFIG_LEVELS: ConfigLevels_Tup = ("system", "user", "global", "repository")
Expand Down
13 changes: 6 additions & 7 deletions git/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@

"""Module with our own gitdb implementation - it uses the git command."""

from git.util import bin_to_hex, hex_to_bin
from gitdb.base import OInfo, OStream
from gitdb.db import GitDB
from gitdb.db import LooseObjectDB
__all__ = ["GitCmdObjectDB", "GitDB"]

from gitdb.base import OInfo, OStream
from gitdb.db import GitDB, LooseObjectDB
from gitdb.exc import BadObject

from git.util import bin_to_hex, hex_to_bin
from git.exc import GitCommandError

# typing-------------------------------------------------

from typing import TYPE_CHECKING

from git.types import PathLike

if TYPE_CHECKING:
from git.cmd import Git


# --------------------------------------------------------

__all__ = ("GitCmdObjectDB", "GitDB")


class GitCmdObjectDB(LooseObjectDB):
"""A database representing the default git object store, which includes loose
Expand Down
30 changes: 11 additions & 19 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = ["DiffConstants", "NULL_TREE", "INDEX", "Diffable", "DiffIndex", "Diff"]

import enum
import re

from git.cmd import handle_process_output
from git.compat import defenc
from git.objects.blob import Blob
from git.objects.util import mode_str_to_int
from git.util import finalize_process, hex_to_bin

from .objects.blob import Blob
from .objects.util import mode_str_to_int


# typing ------------------------------------------------------------------

from typing import (
Expand All @@ -23,34 +23,27 @@
Match,
Optional,
Tuple,
TYPE_CHECKING,
TypeVar,
Union,
TYPE_CHECKING,
cast,
)
from git.types import Literal, PathLike

if TYPE_CHECKING:
from .objects.tree import Tree
from .objects import Commit
from git.repo.base import Repo
from git.objects.base import IndexObject
from subprocess import Popen
from git import Git

Lit_change_type = Literal["A", "D", "C", "M", "R", "T", "U"]

from git.cmd import Git
from git.objects.base import IndexObject
from git.objects.commit import Commit
from git.objects.tree import Tree
from git.repo.base import Repo

# def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
# # return True
# return inp in ['A', 'D', 'C', 'M', 'R', 'T', 'U']
Lit_change_type = Literal["A", "D", "C", "M", "R", "T", "U"]

# ------------------------------------------------------------------------


__all__ = ("DiffConstants", "NULL_TREE", "INDEX", "Diffable", "DiffIndex", "Diff")


@enum.unique
class DiffConstants(enum.Enum):
"""Special objects for :meth:`Diffable.diff`.
Expand Down Expand Up @@ -693,7 +686,6 @@ def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex) -> Non
# Change type can be R100
# R: status letter
# 100: score (in case of copy and rename)
# assert is_change_type(_change_type[0]), f"Unexpected value for change_type received: {_change_type[0]}"
change_type: Lit_change_type = cast(Lit_change_type, _change_type[0])
score_str = "".join(_change_type[1:])
score = int(score_str) if score_str.isdigit() else None
Expand Down
4 changes: 3 additions & 1 deletion git/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@
ParseError,
UnsupportedOperation,
)

from git.compat import safe_decode
from git.util import remove_password_if_present

# typing ----------------------------------------------------

from typing import List, Sequence, Tuple, Union, TYPE_CHECKING
from typing import List, Sequence, Tuple, TYPE_CHECKING, Union

from git.types import PathLike

if TYPE_CHECKING:
Expand Down
13 changes: 11 additions & 2 deletions git/index/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@

"""Initialize the index package."""

from .base import * # noqa: F401 F403
from .typ import * # noqa: F401 F403
__all__ = [
"BaseIndexEntry",
"BlobFilter",
"CheckoutError",
"IndexEntry",
"IndexFile",
"StageType",
]

from .base import CheckoutError, IndexFile
from .typ import BaseIndexEntry, BlobFilter, IndexEntry, StageType
Loading
Loading