Skip to content

Commit

Permalink
Delay git imports
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Sep 28, 2024
1 parent 5b1fa73 commit 28af90c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 5 additions & 3 deletions pylint/testutils/_primer/package_to_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from pathlib import Path
from typing import Literal

from git import GitCommandError
from git.cmd import Git
from git.repo import Repo
# pylint: disable = import-outside-toplevel

PRIMER_DIRECTORY_PATH = Path("tests") / ".pylint_primer_tests"

Expand Down Expand Up @@ -120,12 +118,16 @@ def _clone_repository(self) -> str:
"depth": 1,
}
logging.info("Directory does not exists, cloning: %s", options)
from git.repo import Repo
repo = Repo.clone_from(
url=self.url, to_path=self.clone_directory, branch=self.branch, depth=1
)
return str(repo.head.object.hexsha)

def _pull_repository(self) -> str:
from git import GitCommandError
from git.cmd import Git
from git.repo import Repo
remote_sha1_commit = Git().ls_remote(self.url, self.branch).split("\t")[0]
local_sha1_commit = Repo(self.clone_directory).head.object.hexsha
if remote_sha1_commit != local_sha1_commit:
Expand Down
5 changes: 2 additions & 3 deletions pylint/testutils/_primer/primer_prepare_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

import sys

from git.cmd import Git
from git.repo import Repo

from pylint.testutils._primer.primer_command import PrimerCommand


Expand All @@ -23,10 +20,12 @@ def run(self) -> None:
commit_string += local_commit[:8] + "_"
elif self.config.check:
for package, data in self.packages.items():
from git.repo import Repo # pylint: disable = import-outside-toplevel
local_commit = Repo(data.clone_directory).head.object.hexsha
print(f"Found '{package}' at commit '{local_commit}'.")
commit_string += local_commit[:8] + "_"
elif self.config.make_commit_string:
from git.cmd import Git # pylint: disable = import-outside-toplevel
for package, data in self.packages.items():
remote_sha1_commit = (
Git().ls_remote(data.url, data.branch).split("\t")[0][:8]
Expand Down
3 changes: 1 addition & 2 deletions pylint/testutils/_primer/primer_run_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import warnings
from io import StringIO

from git.repo import Repo

from pylint.lint import Run
from pylint.message import Message
from pylint.reporters.json_reporter import JSONReporter, OldJsonExport
Expand All @@ -36,6 +34,7 @@ def run(self) -> None:
self.config.batchIdx :: self.config.batches
]
)
from git.repo import Repo # pylint: disable = import-outside-toplevel
for package, data in package_data_iter:
messages, p_fatal_msgs = self._lint_package(package, data)
fatal_msgs += p_fatal_msgs
Expand Down

0 comments on commit 28af90c

Please sign in to comment.