Skip to content

Commit

Permalink
chore(ruff): Automated fixes (Fix 105 warnings)
Browse files Browse the repository at this point in the history
Fixed 105 errors:
- conftest.py:
     1 × UP006 (non-pep585-annotation)
- docs/conf.py:
     1 × RUF100 (unused-noqa)
     1 × SIM108 (if-else-block-instead-of-if-exp)
     1 × I001 (unsorted-imports)
- src/libvcs/_internal/query_list.py:
     6 × ERA001 (commented-out-code)
     1 × SIM118 (in-dict-keys)
- src/libvcs/_internal/run.py:
     3 × ERA001 (commented-out-code)
- src/libvcs/_internal/types.py:
     1 × RUF100 (unused-noqa)
- src/libvcs/cmd/git.py:
     8 × RUF005 (collection-literal-concatenation)
     1 × SIM108 (if-else-block-instead-of-if-exp)
     1 × SIM102 (collapsible-if)
- src/libvcs/cmd/hg.py:
     1 × SIM108 (if-else-block-instead-of-if-exp)
- src/libvcs/cmd/svn.py:
     2 × UP006 (non-pep585-annotation)
     1 × SIM108 (if-else-block-instead-of-if-exp)
     1 × F401 (unused-import)
- src/libvcs/pytest_plugin.py:
     2 × B006 (mutable-argument-default)
- src/libvcs/sync/base.py:
     1 × UP031 (printf-string-formatting)
     1 × UP032 (f-string)
- src/libvcs/sync/git.py:
     1 × UP031 (printf-string-formatting)
     1 × SIM102 (collapsible-if)
     1 × ERA001 (commented-out-code)
     1 × SIM108 (if-else-block-instead-of-if-exp)
- src/libvcs/sync/hg.py:
     1 × RUF100 (unused-noqa)
- src/libvcs/sync/svn.py:
     1 × RUF100 (unused-noqa)
     1 × ERA001 (commented-out-code)
     1 × SIM108 (if-else-block-instead-of-if-exp)
     1 × B007 (unused-loop-control-variable)
- src/libvcs/url/git.py:
     1 × RUF100 (unused-noqa)
     1 × C416 (unnecessary-comprehension)
     1 × B010 (set-attr-with-constant)
- src/libvcs/url/hg.py:
     1 × RUF100 (unused-noqa)
     1 × B010 (set-attr-with-constant)
- src/libvcs/url/registry.py:
     6 × UP006 (non-pep585-annotation)
- src/libvcs/url/svn.py:
     2 × RUF100 (unused-noqa)
     1 × ERA001 (commented-out-code)
     1 × B010 (set-attr-with-constant)
- tests/_internal/test_query_list.py:
    28 × C408 (unnecessary-collection-call)
     2 × SIM300 (yoda-conditions)
- tests/sync/test_base.py:
     2 × SIM300 (yoda-conditions)
     1 × RUF010 (explicit-f-string-type-conversion)
- tests/sync/test_git.py:
     3 × SIM300 (yoda-conditions)
     1 × C416 (unnecessary-comprehension)
     1 × I001 (unsorted-imports)
- tests/test_pytest_plugin.py:
     1 × ERA001 (commented-out-code)
     1 × RUF015 (unnecessary-iterable-allocation-for-first-element)
- tests/url/test_git.py:
     1 × ERA001 (commented-out-code)
- tests/url/test_hg.py:
     1 × ERA001 (commented-out-code)
- tests/url/test_registry.py:
     3 × UP006 (non-pep585-annotation)
     1 × B007 (unused-loop-control-variable)
- tests/url/test_svn.py:
     1 × ERA001 (commented-out-code)
  • Loading branch information
tony committed Aug 20, 2023
1 parent 3795f92 commit 7b6515a
Show file tree
Hide file tree
Showing 25 changed files with 102 additions and 143 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@pytest.fixture(autouse=True)
def add_doctest_fixtures(
request: pytest.FixtureRequest,
doctest_namespace: t.Dict[str, t.Any],
doctest_namespace: dict[str, t.Any],
) -> None:
from _pytest.doctest import DoctestItem

Expand Down
12 changes: 4 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# flake8: NOQA: E501
import inspect
import sys
from os.path import relpath
import pathlib
import sys
import typing as t
from os.path import relpath

import libvcs


if t.TYPE_CHECKING:
from sphinx.application import Sphinx

Expand Down Expand Up @@ -185,7 +184,7 @@

def linkcode_resolve(
domain: str, info: dict[str, str]
) -> t.Union[None, str]: # NOQA: C901
) -> t.Union[None, str]:
"""
Determine the URL corresponding to Python object
Expand Down Expand Up @@ -233,10 +232,7 @@ def linkcode_resolve(
except Exception:
lineno = None

if lineno:
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1)
else:
linespec = ""
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1) if lineno else ""

fn = relpath(fn, start=pathlib.Path(libvcs.__file__).parent)

Expand Down
8 changes: 1 addition & 7 deletions src/libvcs/_internal/query_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def lookup_icontains(
if isinstance(data, str):
return rhs.lower() in data.lower()
if isinstance(data, Mapping):
return rhs.lower() in [k.lower() for k in data.keys()]
return rhs.lower() in [k.lower() for k in data]

return False

Expand Down Expand Up @@ -233,7 +233,6 @@ def lookup_in(
return rhs in data
# TODO: Add a deep Mappingionary matcher
# if isinstance(rhs, Mapping) and isinstance(data, Mapping):
# return rhs.items() not in data.items()
except Exception:
return False
return False
Expand All @@ -255,7 +254,6 @@ def lookup_nin(
return rhs not in data
# TODO: Add a deep Mappingionary matcher
# if isinstance(rhs, Mapping) and isinstance(data, Mapping):
# return rhs.items() not in data.items()
except Exception:
return False
return False
Expand Down Expand Up @@ -457,10 +455,6 @@ def __eq__(
self,
other: object,
# other: Union[
# "QueryList[T]",
# List[Mapping[str, str]],
# List[Mapping[str, int]],
# List[Mapping[str, Union[str, Mapping[str, Union[List[str], str]]]]],
# ],
) -> bool:
data = other
Expand Down
3 changes: 0 additions & 3 deletions src/libvcs/_internal/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def run(
extra_groups: Optional[Iterable[Union[str, int]]] = None,
umask: int = -1,
# Not until sys.version_info >= (3, 10)
# pipesize: int = -1,
# custom
log_in_real_time: bool = False,
check_returncode: bool = True,
Expand Down Expand Up @@ -205,8 +204,6 @@ def progress_cb(output: AnyStr, timestamp: datetime.datetime) -> None:
while code is None:
code = proc.poll()

# output = console_to_str(proc.stdout.readline())
# all_output.append(output)
if callback and callable(callback) and proc.stderr is not None:
line = console_to_str(proc.stderr.read(128))
if line:
Expand Down
2 changes: 1 addition & 1 deletion src/libvcs/_internal/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:class:`StrPath` and :class:`StrOrBytesPath` is based on `typeshed's`_.
.. _typeshed's: https://github.com/python/typeshed/blob/5df8de7/stdlib/_typeshed/__init__.pyi#L115-L118
""" # NOQA E501
""" # E501
from os import PathLike
from typing import TYPE_CHECKING, Literal, Union

Expand Down
26 changes: 11 additions & 15 deletions src/libvcs/cmd/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ def run(
"usage: git [...--version] [...--help] [-C <path>]..."
"""

if isinstance(args, Sequence):
cli_args = ["git", *args]
else:
cli_args = ["git", args]
cli_args = ["git", *args] if isinstance(args, Sequence) else ["git", args]

if "cwd" not in kwargs:
kwargs["cwd"] = self.dir
Expand Down Expand Up @@ -1963,9 +1960,8 @@ def rev_list(
(max_age, "--max-age"),
(min_age, "--min-age"),
]:
if datetime_kwarg is not None:
if isinstance(datetime, str):
local_flags.extend([datetime_shell_flag, datetime_kwarg])
if datetime_kwarg is not None and isinstance(datetime, str):
local_flags.extend([datetime_shell_flag, datetime_kwarg])

for int_flag, int_shell_flag in [
(max_count, "--max-count"),
Expand Down Expand Up @@ -2257,7 +2253,7 @@ def init(

return self.run(
"init",
local_flags=local_flags + ["--"] + required_flags,
local_flags=[*local_flags, "--", *required_flags],
check_returncode=check_returncode,
log_in_real_time=log_in_real_time,
)
Expand Down Expand Up @@ -2320,7 +2316,7 @@ def update(

return self.run(
"update",
local_flags=local_flags + ["--"] + required_flags,
local_flags=[*local_flags, "--", *required_flags],
check_returncode=check_returncode,
log_in_real_time=log_in_real_time,
)
Expand Down Expand Up @@ -2442,7 +2438,7 @@ def add(
local_flags.append("--mirror")
return self.run(
"add",
local_flags=local_flags + ["--"] + required_flags,
local_flags=[*local_flags, "--", *required_flags],
check_returncode=check_returncode,
log_in_real_time=log_in_real_time,
)
Expand Down Expand Up @@ -2540,7 +2536,7 @@ def show(

return self.run(
"show",
local_flags=local_flags + ["--"] + required_flags,
local_flags=[*local_flags, "--", *required_flags],
check_returncode=check_returncode,
log_in_real_time=log_in_real_time,
)
Expand Down Expand Up @@ -2573,7 +2569,7 @@ def prune(

return self.run(
"prune",
local_flags=local_flags + ["--"] + required_flags,
local_flags=[*local_flags, "--", *required_flags],
check_returncode=check_returncode,
log_in_real_time=log_in_real_time,
)
Expand Down Expand Up @@ -2612,7 +2608,7 @@ def get_url(

return self.run(
"get-url",
local_flags=local_flags + ["--"] + required_flags,
local_flags=[*local_flags, "--", *required_flags],
check_returncode=check_returncode,
log_in_real_time=log_in_real_time,
)
Expand Down Expand Up @@ -2678,7 +2674,7 @@ def set_url(

return self.run(
"set-url",
local_flags=local_flags + ["--"] + required_flags,
local_flags=[*local_flags, "--", *required_flags],
check_returncode=check_returncode,
log_in_real_time=log_in_real_time,
)
Expand Down Expand Up @@ -2823,7 +2819,7 @@ def push(

return self.run(
"push",
local_flags=local_flags + ["--"] + required_flags,
local_flags=[*local_flags, "--", *required_flags],
check_returncode=check_returncode,
log_in_real_time=log_in_real_time,
)
Expand Down
5 changes: 1 addition & 4 deletions src/libvcs/cmd/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ def run(
"Mercurial Distributed SCM..."
"""

if isinstance(args, Sequence):
cli_args = ["hg", *args]
else:
cli_args = ["hg", args]
cli_args = ["hg", *args] if isinstance(args, Sequence) else ["hg", args]

if "cwd" not in kwargs:
kwargs["cwd"] = self.dir
Expand Down
11 changes: 4 additions & 7 deletions src/libvcs/cmd/svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""
import pathlib
from collections.abc import Sequence
from typing import Any, List, Literal, Optional, Union
from typing import Any, Literal, Optional, Union

from libvcs._internal.run import ProgressCallbackProtocol, run
from libvcs._internal.types import StrOrBytesPath, StrPath
Expand Down Expand Up @@ -110,10 +110,7 @@ def run(
"usage: svn <subcommand> [options] [args]..."
"""

if isinstance(args, Sequence):
cli_args = ["svn", *args]
else:
cli_args = ["svn", args]
cli_args = ["svn", *args] if isinstance(args, Sequence) else ["svn", args]

if "cwd" not in kwargs:
kwargs["cwd"] = self.dir
Expand Down Expand Up @@ -565,7 +562,7 @@ def info(
self,
target: Optional[StrPath] = None,
targets: Optional[Union[list[StrPath], StrPath]] = None,
changelist: Optional[List[str]] = None,
changelist: Optional[list[str]] = None,
revision: Optional[str] = None,
depth: DepthLiteral = None,
incremental: Optional[bool] = None,
Expand Down Expand Up @@ -1095,7 +1092,7 @@ def unlock(
def update(
self,
accept: Optional[str] = None,
changelist: Optional[List[str]] = None,
changelist: Optional[list[str]] = None,
diff3_cmd: Optional[str] = None,
editor_cmd: Optional[str] = None,
force: Optional[bool] = None,
Expand Down
8 changes: 6 additions & 2 deletions src/libvcs/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ def _create_git_remote_repo(
remote_repos_path: pathlib.Path,
remote_repo_name: str,
remote_repo_post_init: Optional[CreateProjectCallbackProtocol] = None,
init_cmd_args: InitCmdArgs = ["--bare"],
init_cmd_args: InitCmdArgs = None,
) -> pathlib.Path:
if init_cmd_args is None:
init_cmd_args = ["--bare"]
if init_cmd_args is None:
init_cmd_args = []
remote_repo_path = remote_repos_path / remote_repo_name
Expand All @@ -231,8 +233,10 @@ def fn(
remote_repos_path: pathlib.Path = remote_repos_path,
remote_repo_name: Optional[str] = None,
remote_repo_post_init: Optional[CreateProjectCallbackProtocol] = None,
init_cmd_args: InitCmdArgs = ["--bare"],
init_cmd_args: InitCmdArgs = None,
) -> pathlib.Path:
if init_cmd_args is None:
init_cmd_args = ["--bare"]
return _create_git_remote_repo(
remote_repos_path=remote_repos_path,
remote_repo_name=remote_repo_name
Expand Down
3 changes: 1 addition & 2 deletions src/libvcs/sync/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ def ensure_dir(self, *args: Any, **kwargs: Any) -> bool:

if not self.dir.exists():
self.log.debug(
"Project directory for %s does not exist @ %s"
% (self.repo_name, self.dir)
f"Project directory for {self.repo_name} does not exist @ {self.dir}"
)
self.dir.mkdir(parents=True)

Expand Down
32 changes: 13 additions & 19 deletions src/libvcs/sync/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ def convert_pip_url(pip_url: str) -> VCSLocation:
url = url.replace("ssh://", "")
elif "github.com:" in pip_url:
raise exc.LibVCSException(
"Repo %s is malformatted, please use the convention %s for "
"ssh / private GitHub repositories."
% (pip_url, "git+https://github.com/username/repo.git")
"Repo {} is malformatted, please use the convention {} for "
"ssh / private GitHub repositories.".format(pip_url, "git+https://github.com/username/repo.git")
)
else:
url, rev = base_convert_pip_url(pip_url)
Expand Down Expand Up @@ -276,17 +275,16 @@ def set_remotes(self, overwrite: bool = False) -> None:
)
# refresh if we're setting it, so push can be checked
existing_remote = self.remote(remote_name)
if git_remote_repo.push_url:
if (
not existing_remote
or existing_remote.push_url != git_remote_repo.push_url
):
self.set_remote(
name=remote_name,
url=git_remote_repo.push_url,
push=True,
overwrite=overwrite,
)
if git_remote_repo.push_url and (
not existing_remote
or existing_remote.push_url != git_remote_repo.push_url
):
self.set_remote(
name=remote_name,
url=git_remote_repo.push_url,
push=True,
overwrite=overwrite,
)
else:
if (
not existing_remote
Expand All @@ -305,7 +303,6 @@ def obtain(self, *args: Any, **kwargs: Any) -> None:
url = self.url

self.log.info("Cloning.")
# todo: log_in_real_time
self.cmd.clone(
url=url,
progress=True,
Expand Down Expand Up @@ -343,10 +340,7 @@ def update_repo(self, set_remotes: bool = False, *args: Any, **kwargs: Any) -> N
if not git_tag:
self.log.debug("No git revision set, defaulting to origin/master")
symref = self.cmd.symbolic_ref(name="HEAD", short=True)
if symref:
git_tag = symref.rstrip()
else:
git_tag = "origin/master"
git_tag = symref.rstrip() if symref else "origin/master"
self.log.debug("git_tag: %s" % git_tag)

self.log.info("Updating to '%s'." % git_tag)
Expand Down
2 changes: 1 addition & 1 deletion src/libvcs/sync/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- [`HgSync.convert_pip_url`](libvcs.hg.convert_pip_url)
- [`HgSync.get_url`](libvcs.hg.HgSync.get_url)
- [`HgSync.get_revision`](libvcs.hg.HgSync.get_revision)
""" # NOQA E5
""" # E5
import logging
import pathlib
from typing import Any
Expand Down
10 changes: 3 additions & 7 deletions src/libvcs/sync/svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- [`SvnSync.get_url`](libvcs.svn.SvnSync.get_url)
- [`SvnSync.get_revision`](libvcs.svn.SvnSync.get_revision)
""" # NOQA: E5
"""
import logging
import os
import pathlib
Expand Down Expand Up @@ -110,7 +110,7 @@ def get_revision(self, location: Optional[str] = None) -> int:
# Note: taken from setuptools.command.egg_info
revision = 0

for base, dirs, files in os.walk(location):
for base, dirs, _files in os.walk(location):
if ".svn" not in dirs:
dirs[:] = []
continue # no sense walking uncontrolled subdirs
Expand Down Expand Up @@ -177,7 +177,6 @@ def _get_svn_url_rev(cls, location: str) -> tuple[Optional[str], int]:
revs = [int(m.group(1)) for m in _svn_rev_re.finditer(data)] + [0]
else:
try:
# subversion >= 1.7
# Note that using get_remote_call_options is not necessary here
# because `svn info` is being run against a local directory.
# We don't need to worry about making sure interactive mode
Expand All @@ -193,9 +192,6 @@ def _get_svn_url_rev(cls, location: str) -> tuple[Optional[str], int]:
except Exception:
url, revs = None, []

if revs:
rev = max(revs)
else:
rev = 0
rev = max(revs) if revs else 0

return url, rev
Loading

0 comments on commit 7b6515a

Please sign in to comment.