From 28af90cb400bb345aa60045a40a337a73a9c4ec9 Mon Sep 17 00:00:00 2001 From: Nick Drozd Date: Sat, 28 Sep 2024 10:47:18 -0400 Subject: [PATCH] Delay git imports --- pylint/testutils/_primer/package_to_lint.py | 8 +++++--- pylint/testutils/_primer/primer_prepare_command.py | 5 ++--- pylint/testutils/_primer/primer_run_command.py | 3 +-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pylint/testutils/_primer/package_to_lint.py b/pylint/testutils/_primer/package_to_lint.py index fb65a90ad9..d4dc500d23 100644 --- a/pylint/testutils/_primer/package_to_lint.py +++ b/pylint/testutils/_primer/package_to_lint.py @@ -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" @@ -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: diff --git a/pylint/testutils/_primer/primer_prepare_command.py b/pylint/testutils/_primer/primer_prepare_command.py index 27e216bd5a..72dac13ce4 100644 --- a/pylint/testutils/_primer/primer_prepare_command.py +++ b/pylint/testutils/_primer/primer_prepare_command.py @@ -5,9 +5,6 @@ import sys -from git.cmd import Git -from git.repo import Repo - from pylint.testutils._primer.primer_command import PrimerCommand @@ -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] diff --git a/pylint/testutils/_primer/primer_run_command.py b/pylint/testutils/_primer/primer_run_command.py index 96a1440e7c..1046adf8d1 100644 --- a/pylint/testutils/_primer/primer_run_command.py +++ b/pylint/testutils/_primer/primer_run_command.py @@ -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 @@ -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