Skip to content

Replace all wildcard imports with explicit imports #1880

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

Merged
merged 34 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve test suite import grouping/sorting, __all__ placement
There is only one __all__ in the test suite, so this is mostly the
change to imports, grouping and sorting them in a fully consistent
style that is the same as the import style in the code under test.
  • Loading branch information
EliahKagan committed Mar 19, 2024
commit 4a4d880fec4364c7d49e7708238a962942ae69f3
32 changes: 16 additions & 16 deletions test/lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = [
"fixture_path",
"fixture",
"StringProcessAdapter",
"with_rw_directory",
"with_rw_repo",
"with_rw_and_rw_remote_repo",
"TestBase",
"VirtualEnvironment",
"TestCase",
"SkipTest",
"skipIf",
"GIT_REPO",
"GIT_DAEMON_PORT",
]

import contextlib
from functools import wraps
import gc
Expand Down Expand Up @@ -31,22 +47,6 @@
GIT_REPO = os.environ.get("GIT_PYTHON_TEST_GIT_REPO_BASE", ospd(ospd(ospd(__file__))))
GIT_DAEMON_PORT = os.environ.get("GIT_PYTHON_TEST_GIT_DAEMON_PORT", "19418")

__all__ = (
"fixture_path",
"fixture",
"StringProcessAdapter",
"with_rw_directory",
"with_rw_repo",
"with_rw_and_rw_remote_repo",
"TestBase",
"VirtualEnvironment",
"TestCase",
"SkipTest",
"skipIf",
"GIT_REPO",
"GIT_DAEMON_PORT",
)

_logger = logging.getLogger(__name__)

# { Routines
Expand Down
2 changes: 2 additions & 0 deletions test/performance/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
5 changes: 3 additions & 2 deletions test/performance/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import logging
import os
import os.path as osp
import tempfile

from git import Repo
from git.db import GitCmdObjectDB, GitDB
from test.lib import TestBase
from git.util import rmtree
import os.path as osp

from test.lib import TestBase

# { Invariants

Expand Down
6 changes: 4 additions & 2 deletions test/performance/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
from time import time
import sys

from .lib import TestBigRepoRW
from git import Commit
from gitdb import IStream

from git import Commit

from test.performance.lib import TestBigRepoRW
from test.test_commit import TestCommitSerialization


Expand Down
2 changes: 1 addition & 1 deletion test/performance/test_odb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
from time import time

from .lib import TestBigRepoR
from test.performance.lib import TestBigRepoR


class TestObjDBPerformance(TestBigRepoR):
Expand Down
8 changes: 4 additions & 4 deletions test/performance/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

import gc
import os
import os.path as osp
import subprocess
import sys
from time import time

from test.lib import with_rw_repo
from git.util import bin_to_hex
from gitdb import LooseObjectDB, IStream
from gitdb.test.lib import make_memory_file

import os.path as osp
from git.util import bin_to_hex

from .lib import TestBigRepoR
from test.lib import with_rw_repo
from test.performance.lib import TestBigRepoR


class TestObjDBPerformance(TestBigRepoR):
Expand Down
3 changes: 2 additions & 1 deletion test/test_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

from test.lib import TestBase
from git import Actor

from test.lib import TestBase


class TestActor(TestBase):
def test_from_string_should_separate_name_and_email(self):
Expand Down
10 changes: 5 additions & 5 deletions test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

import gc
import os
import os.path as osp
import sys
import tempfile
from unittest import skipIf

from git import Repo
from git.objects import Blob, Tree, Commit, TagObject
from git.objects import Blob, Commit, TagObject, Tree
import git.objects.base as base
from git.objects.util import get_object_type_by_name
from test.lib import TestBase as _TestBase, with_rw_repo, with_rw_and_rw_remote_repo
from git.util import hex_to_bin, HIDE_WINDOWS_FREEZE_ERRORS
from git.util import HIDE_WINDOWS_FREEZE_ERRORS, hex_to_bin

import git.objects.base as base
import os.path as osp
from test.lib import TestBase as _TestBase, with_rw_and_rw_remote_repo, with_rw_repo


class TestBase(_TestBase):
Expand Down
3 changes: 2 additions & 1 deletion test/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

from test.lib import TestBase
from git import Blob

from test.lib import TestBase


class TestBlob(TestBase):
def test_mime_type_should_return_mime_type_for_known_types(self):
Expand Down
5 changes: 1 addition & 4 deletions test/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

import git

from .lib import (
TestBase,
with_rw_directory,
)
from test.lib import TestBase, with_rw_directory


class TestClone(TestBase):
Expand Down
20 changes: 11 additions & 9 deletions test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
import copy
from datetime import datetime
from io import BytesIO
import os.path as osp
import re
import sys
import time
from unittest.mock import Mock

from git import (
Commit,
Actor,
)
from git import Repo
from gitdb import IStream

from git import Actor, Commit, Repo
from git.objects.util import tzoffset, utc
from git.repo.fun import touch
from test.lib import TestBase, with_rw_repo, fixture_path, StringProcessAdapter
from test.lib import with_rw_directory
from gitdb import IStream

import os.path as osp
from test.lib import (
StringProcessAdapter,
TestBase,
fixture_path,
with_rw_directory,
with_rw_repo,
)


class TestCommitSerialization(TestBase):
Expand Down
2 changes: 1 addition & 1 deletion test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from git import GitConfigParser
from git.config import _OMD, cp
from git.util import rmfile
from test.lib import SkipTest, TestCase, fixture_path, with_rw_directory

from test.lib import SkipTest, TestCase, fixture_path, with_rw_directory

_tc_lock_fpaths = osp.join(osp.dirname(__file__), "fixtures/*.lock")

Expand Down
5 changes: 3 additions & 2 deletions test/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import os.path as osp

from git.db import GitCmdObjectDB
from git.exc import BadObject
from test.lib import TestBase
from git.util import bin_to_hex

import os.path as osp
from test.lib import TestBase


class TestDB(TestBase):
Expand Down
1 change: 1 addition & 0 deletions test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from git import NULL_TREE, Diff, DiffIndex, Diffable, GitCommandError, Repo, Submodule
from git.cmd import Git

from test.lib import StringProcessAdapter, TestBase, fixture, with_rw_directory


Expand Down
3 changes: 1 addition & 2 deletions test/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

import gc
import os
import os.path
import sys

import pytest

from test.lib import TestBase
from test.lib.helper import with_rw_directory

import os.path


class Tutorials(TestBase):
def tearDown(self):
Expand Down
7 changes: 4 additions & 3 deletions test/test_exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

from itertools import product
import re

import ddt

from git.exc import (
InvalidGitRepositoryError,
WorkTreeRepositoryUnsupported,
Expand All @@ -20,9 +22,8 @@
RepositoryDirtyError,
)
from git.util import remove_password_if_present
from test.lib import TestBase

import itertools as itt
from test.lib import TestBase


_cmd_argvs = (
Expand Down Expand Up @@ -79,7 +80,7 @@ def test_ExceptionsHaveBaseClass(self):
for ex_class in exception_classes:
self.assertTrue(issubclass(ex_class, GitError))

@ddt.data(*list(itt.product(_cmd_argvs, _causes_n_substrings, _streams_n_substrings)))
@ddt.data(*list(product(_cmd_argvs, _causes_n_substrings, _streams_n_substrings)))
def test_CommandError_unicode(self, case):
argv, (cause, subs), stream = case
cls = CommandError
Expand Down
17 changes: 8 additions & 9 deletions test/test_fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

from io import BytesIO
from stat import S_IFDIR, S_IFREG, S_IFLNK, S_IXUSR
from stat import S_IFDIR, S_IFLNK, S_IFREG, S_IXUSR
from os import stat
import os.path as osp

from gitdb.base import IStream
from gitdb.typ import str_tree_type

from git import Git
from git.index import IndexFile
from git.index.fun import (
aggressive_tree_merge,
stat_mode_to_index_mode,
)
from git.index.fun import aggressive_tree_merge, stat_mode_to_index_mode
from git.objects.fun import (
traverse_tree_recursive,
traverse_trees_recursive,
tree_to_stream,
tree_entries_from_data,
tree_to_stream,
)
from git.repo.fun import find_worktree_git_dir
from test.lib import TestBase, with_rw_repo, with_rw_directory
from git.util import bin_to_hex, cygpath, join_path_native
from gitdb.base import IStream
from gitdb.typ import str_tree_type

from test.lib import TestBase, with_rw_directory, with_rw_repo


class TestFun(TestBase):
Expand Down
3 changes: 2 additions & 1 deletion test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

import ddt

from git import Git, refresh, GitCommandError, GitCommandNotFound, Repo, cmd
from git import Git, GitCommandError, GitCommandNotFound, Repo, cmd, refresh
from git.util import cwd, finalize_process

from test.lib import TestBase, fixture_path, with_rw_directory


Expand Down
14 changes: 4 additions & 10 deletions test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@
import sys
import tempfile

from gitdb.base import IStream

import ddt
import pytest

from git import (
BlobFilter,
Diff,
Git,
IndexFile,
Object,
Repo,
Tree,
)
from git import BlobFilter, Diff, Git, IndexFile, Object, Repo, Tree
from git.exc import (
CheckoutError,
GitCommandError,
Expand All @@ -41,7 +35,7 @@
from git.index.util import TemporaryFileSwap
from git.objects import Blob
from git.util import Actor, cwd, hex_to_bin, rmtree
from gitdb.base import IStream

from test.lib import (
TestBase,
VirtualEnvironment,
Expand Down
5 changes: 3 additions & 2 deletions test/test_reflog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import tempfile

from git.objects import IndexObject
from git.refs import RefLogEntry, RefLog
from git.refs import RefLog, RefLogEntry
from git.util import Actor, hex_to_bin, rmtree

from test.lib import TestBase, fixture_path
from git.util import Actor, rmtree, hex_to_bin


class TestRefLog(TestBase):
Expand Down
Loading