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

lint: switch Black with ruff-format #1865

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 0 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@ jobs:
- uses: pre-commit/[email protected]
with:
extra_args: --all-files --hook-stage manual
env:
SKIP: black-format
18 changes: 2 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black
alias: black-check
name: black (check)
args: [--check, --diff]
exclude: ^git/ext/
stages: [manual]

- id: black
alias: black-format
name: black (format)
exclude: ^git/ext/

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
hooks:
#- id: ruff-format # todo: eventually replace Black with Ruff for consistency
# args: ["--preview"]
- id: ruff-format
exclude: ^git/ext/
- id: ruff
args: ["--fix"]
exclude: ^doc|^git/ext/
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ all:
@awk -F: '/^[[:alpha:]].*:/ && !/^all:/ {print $$1}' Makefile

lint:
SKIP=black-format pre-commit run --all-files --hook-stage manual
SKIP=pre-commit run --all-files --hook-stage manual
Borda marked this conversation as resolved.
Show resolved Hide resolved

clean:
rm -rf build/ dist/ .eggs/ .tox/
Expand Down
72 changes: 29 additions & 43 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,8 @@ def refresh(cls, path: Union[None, PathLike] = None) -> bool:
if mode in quiet:
pass
elif mode in warn or mode in error:
err = (
dedent(
"""\
err = dedent(
"""\
%s
All git commands will error until this is rectified.

Expand All @@ -510,40 +509,35 @@ def refresh(cls, path: Union[None, PathLike] = None) -> bool:
Example:
export %s=%s
"""
)
% (
err,
cls._refresh_env_var,
"|".join(quiet),
"|".join(warn),
"|".join(error),
cls._refresh_env_var,
quiet[0],
)
) % (
err,
cls._refresh_env_var,
"|".join(quiet),
"|".join(warn),
"|".join(error),
cls._refresh_env_var,
quiet[0],
)

if mode in warn:
_logger.critical(err)
else:
raise ImportError(err)
else:
err = (
dedent(
"""\
err = dedent(
"""\
%s environment variable has been set but it has been set with an invalid value.

Use only the following values:
- %s: for no message or exception
- %s: for a warning message (logging level CRITICAL, displayed by default)
- %s: for a raised exception
"""
)
% (
cls._refresh_env_var,
"|".join(quiet),
"|".join(warn),
"|".join(error),
)
) % (
cls._refresh_env_var,
"|".join(quiet),
"|".join(warn),
"|".join(error),
)
raise ImportError(err)

Expand All @@ -565,13 +559,11 @@ def is_cygwin(cls) -> bool:

@overload
@classmethod
def polish_url(cls, url: str, is_cygwin: Literal[False] = ...) -> str:
...
def polish_url(cls, url: str, is_cygwin: Literal[False] = ...) -> str: ...
Borda marked this conversation as resolved.
Show resolved Hide resolved

@overload
@classmethod
def polish_url(cls, url: str, is_cygwin: Union[None, bool] = None) -> str:
...
def polish_url(cls, url: str, is_cygwin: Union[None, bool] = None) -> str: ...

@classmethod
def polish_url(cls, url: str, is_cygwin: Union[None, bool] = None) -> PathLike:
Expand Down Expand Up @@ -932,8 +924,7 @@ def execute(
command: Union[str, Sequence[Any]],
*,
as_process: Literal[True],
) -> "AutoInterrupt":
...
) -> "AutoInterrupt": ...

@overload
def execute(
Expand All @@ -942,8 +933,7 @@ def execute(
*,
as_process: Literal[False] = False,
stdout_as_string: Literal[True],
) -> Union[str, Tuple[int, str, str]]:
...
) -> Union[str, Tuple[int, str, str]]: ...

@overload
def execute(
Expand All @@ -952,8 +942,7 @@ def execute(
*,
as_process: Literal[False] = False,
stdout_as_string: Literal[False] = False,
) -> Union[bytes, Tuple[int, bytes, str]]:
...
) -> Union[bytes, Tuple[int, bytes, str]]: ...

@overload
def execute(
Expand All @@ -963,8 +952,7 @@ def execute(
with_extended_output: Literal[False],
as_process: Literal[False],
stdout_as_string: Literal[True],
) -> str:
...
) -> str: ...

@overload
def execute(
Expand All @@ -974,8 +962,7 @@ def execute(
with_extended_output: Literal[False],
as_process: Literal[False],
stdout_as_string: Literal[False],
) -> bytes:
...
) -> bytes: ...

def execute(
self,
Expand Down Expand Up @@ -1387,8 +1374,9 @@ def __call__(self, **kwargs: Any) -> "Git":
return self

@overload
def _call_process(self, method: str, *args: None, **kwargs: None) -> str:
... # If no args were given, execute the call with all defaults.
def _call_process(
self, method: str, *args: None, **kwargs: None
) -> str: ... # If no args were given, execute the call with all defaults.

@overload
def _call_process(
Expand All @@ -1398,14 +1386,12 @@ def _call_process(
as_process: Literal[True],
*args: Any,
**kwargs: Any,
) -> "Git.AutoInterrupt":
...
) -> "Git.AutoInterrupt": ...

@overload
def _call_process(
self, method: str, *args: Any, **kwargs: Any
) -> Union[str, bytes, Tuple[int, Union[str, bytes], str], "Git.AutoInterrupt"]:
...
) -> Union[str, bytes, Tuple[int, Union[str, bytes], str], "Git.AutoInterrupt"]: ...

def _call_process(
self, method: str, *args: Any, **kwargs: Any
Expand Down
18 changes: 6 additions & 12 deletions git/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@


@overload
def safe_decode(s: None) -> None:
...
def safe_decode(s: None) -> None: ...


@overload
def safe_decode(s: AnyStr) -> str:
...
def safe_decode(s: AnyStr) -> str: ...


def safe_decode(s: Union[AnyStr, None]) -> Optional[str]:
Expand All @@ -91,13 +89,11 @@ def safe_decode(s: Union[AnyStr, None]) -> Optional[str]:


@overload
def safe_encode(s: None) -> None:
...
def safe_encode(s: None) -> None: ...


@overload
def safe_encode(s: AnyStr) -> bytes:
...
def safe_encode(s: AnyStr) -> bytes: ...


def safe_encode(s: Optional[AnyStr]) -> Optional[bytes]:
Expand All @@ -113,13 +109,11 @@ def safe_encode(s: Optional[AnyStr]) -> Optional[bytes]:


@overload
def win_encode(s: None) -> None:
...
def win_encode(s: None) -> None: ...


@overload
def win_encode(s: AnyStr) -> bytes:
...
def win_encode(s: AnyStr) -> bytes: ...


def win_encode(s: Optional[AnyStr]) -> Optional[bytes]:
Expand Down
6 changes: 3 additions & 3 deletions git/index/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ def read_cache(
# 4 bytes length of chunk
# Repeated 0 - N times
extension_data = stream.read(~0)
assert (
len(extension_data) > 19
), "Index Footer was not at least a sha on content as it was only %i bytes in size" % len(extension_data)
assert len(extension_data) > 19, (
"Index Footer was not at least a sha on content as it was only %i bytes in size" % len(extension_data)
)

content_sha = extension_data[-20:]

Expand Down
6 changes: 2 additions & 4 deletions git/objects/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,11 @@ def _find_by_name(tree_data: MutableSequence[EntryTupOrNone], name: str, is_dir:


@overload
def _to_full_path(item: None, path_prefix: str) -> None:
...
def _to_full_path(item: None, path_prefix: str) -> None: ...


@overload
def _to_full_path(item: EntryTup, path_prefix: str) -> EntryTup:
...
def _to_full_path(item: EntryTup, path_prefix: str) -> EntryTup: ...


def _to_full_path(item: EntryTupOrNone, path_prefix: str) -> EntryTupOrNone:
Expand Down
2 changes: 1 addition & 1 deletion git/objects/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class Tree(IndexObject, git_diff.Diffable, util.Traversable, util.Serializable):
_map_id_to_type: Dict[int, Type[IndexObjUnion]] = {
commit_id: Submodule,
blob_id: Blob,
symlink_id: Blob
symlink_id: Blob,
# Tree ID added once Tree is defined.
}

Expand Down
12 changes: 4 additions & 8 deletions git/objects/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,7 @@ def list_traverse(self: T_TIobj, *args: Any, **kwargs: Any) -> IterableList[T_TI
return super()._list_traverse(*args, **kwargs)

@overload # type: ignore
def traverse(self: T_TIobj) -> Iterator[T_TIobj]:
...
def traverse(self: T_TIobj) -> Iterator[T_TIobj]: ...

@overload
def traverse(
Expand All @@ -633,8 +632,7 @@ def traverse(
visit_once: bool,
ignore_self: Literal[True],
as_edge: Literal[False],
) -> Iterator[T_TIobj]:
...
) -> Iterator[T_TIobj]: ...

@overload
def traverse(
Expand All @@ -646,8 +644,7 @@ def traverse(
visit_once: bool,
ignore_self: Literal[False],
as_edge: Literal[True],
) -> Iterator[Tuple[Union[T_TIobj, None], T_TIobj]]:
...
) -> Iterator[Tuple[Union[T_TIobj, None], T_TIobj]]: ...

@overload
def traverse(
Expand All @@ -659,8 +656,7 @@ def traverse(
visit_once: bool,
ignore_self: Literal[True],
as_edge: Literal[True],
) -> Iterator[Tuple[T_TIobj, T_TIobj]]:
...
) -> Iterator[Tuple[T_TIobj, T_TIobj]]: ...

def traverse(
self: T_TIobj,
Expand Down
11 changes: 4 additions & 7 deletions git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,19 @@ def add_progress(


@overload
def to_progress_instance(progress: None) -> RemoteProgress:
...
def to_progress_instance(progress: None) -> RemoteProgress: ...


@overload
def to_progress_instance(progress: Callable[..., Any]) -> CallableRemoteProgress:
...
def to_progress_instance(progress: Callable[..., Any]) -> CallableRemoteProgress: ...


@overload
def to_progress_instance(progress: RemoteProgress) -> RemoteProgress:
...
def to_progress_instance(progress: RemoteProgress) -> RemoteProgress: ...


def to_progress_instance(
progress: Union[Callable[..., Any], RemoteProgress, None]
progress: Union[Callable[..., Any], RemoteProgress, None],
) -> Union[RemoteProgress, CallableRemoteProgress]:
"""Given the `progress` return a suitable object derived from
:class:`~git.util.RemoteProgress`."""
Expand Down
9 changes: 3 additions & 6 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,11 @@ def decygpath(path: PathLike) -> str:


@overload
def is_cygwin_git(git_executable: None) -> Literal[False]:
...
def is_cygwin_git(git_executable: None) -> Literal[False]: ...


@overload
def is_cygwin_git(git_executable: PathLike) -> bool:
...
def is_cygwin_git(git_executable: PathLike) -> bool: ...


def is_cygwin_git(git_executable: Union[None, PathLike]) -> bool:
Expand Down Expand Up @@ -494,8 +492,7 @@ def finalize_process(proc: Union[subprocess.Popen, "Git.AutoInterrupt"], **kwarg


@overload
def expand_path(p: None, expand_vars: bool = ...) -> None:
...
def expand_path(p: None, expand_vars: bool = ...) -> None: ...


@overload
Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ source = ["git"]
include = ["*/git/*"]
omit = ["*/git/ext/*"]

[tool.black]
line-length = 120
target-version = ["py37"]
extend-exclude = "git/ext/gitdb"

[tool.ruff]
target-version = "py37"
line-length = 120
Expand Down
Loading
Loading