Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ select = [

[tool.ruff.lint.per-file-ignores]
"noxfile.py" = ["D", "PTH"]
"tests/**" = ["S", "ARG001", "ARG002", "ANN"]
"tests/**" = ["S", "ARG001", "ARG002", "ANN", "TID251", "TID253"]
"docs/**" = ["INP"]
"src/scmrepo/git/backend/gitpython.py" = ["TID251"]

[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
Expand All @@ -203,6 +204,14 @@ parametrize-names-type = "csv"
[tool.ruff.lint.flake8-type-checking]
strict = true

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"git".msg = "importing from 'git' is not allowed except inside `gitpython` backend"

[tool.ruff.lint.flake8-tidy-imports]
# Ban certain modules from being imported at module level, instead requiring
# that they're imported lazily (e.g., within a function definition).
banned-module-level-imports = ["git"]

[tool.ruff.lint.isort]
known-first-party = ["scmrepo"]

Expand Down
22 changes: 13 additions & 9 deletions src/scmrepo/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def code2desc(op_code):
from git import RootUpdateProgress as OP # noqa: N814
from git import RootUpdateProgress as OP # noqa: N814, TID251

ops = {
OP.COUNTING: "Counting",
Expand Down Expand Up @@ -44,16 +44,20 @@ def parsed_from_gitpython(

class GitProgressReporter:
def __init__(self, fn) -> None:
from git.util import CallableRemoteProgress

self._reporter = CallableRemoteProgress(self.wrap_fn(fn))
try:
from git.util import CallableRemoteProgress # noqa: TID251
except ImportError:
self._reporter = None
else:
self._reporter = CallableRemoteProgress(self.wrap_fn(fn))

def __call__(self, msg: Union[str, bytes]) -> None:
self._reporter._parse_progress_line(
msg.decode("utf-8", errors="replace").strip()
if isinstance(msg, bytes)
else msg
)
if self._reporter is not None:
self._reporter._parse_progress_line(
msg.decode("utf-8", errors="replace").strip()
if isinstance(msg, bytes)
else msg
)

@staticmethod
def wrap_fn(fn):
Expand Down
Loading