Skip to content

Commit 53547f5

Browse files
authored
Linting: Aggressive ruff pass (ruff v0.3.4, #458)
2 parents 9b579d6 + 339a93d commit 53547f5

25 files changed

+331
-357
lines changed

CHANGES

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ $ pip install --user --upgrade --pre libvcs
1717

1818
### Development
1919

20+
- Aggressive automated lint fixes via `ruff` (#458)
21+
22+
via ruff v0.3.4, all automated lint fixes, including unsafe and previews were applied:
23+
24+
```sh
25+
ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes; ruff format .
26+
```
27+
28+
Branches were treated with:
29+
30+
```sh
31+
git rebase \
32+
--strategy-option=theirs \
33+
--exec 'poetry run ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes; poetry run ruff format .; git add src tests; git commit --amend --no-edit' \
34+
origin/master
35+
```
36+
2037
- poetry: 1.7.1 -> 1.8.1
2138

2239
See also: https://github.com/python-poetry/poetry/blob/1.8.1/CHANGELOG.md

conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,3 @@ def setup(
4242
set_home: pathlib.Path,
4343
) -> None:
4444
"""Configure test fixtures for pytest."""
45-
pass

docs/conf.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,14 @@ def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]:
209209
fn,
210210
linespec,
211211
)
212-
else:
213-
return "{}/blob/v{}/{}/{}/{}{}".format(
214-
about["__github__"],
215-
about["__version__"],
216-
"src",
217-
about["__package_name__"],
218-
fn,
219-
linespec,
220-
)
212+
return "{}/blob/v{}/{}/{}/{}{}".format(
213+
about["__github__"],
214+
about["__version__"],
215+
"src",
216+
about["__package_name__"],
217+
fn,
218+
linespec,
219+
)
221220

222221

223222
def remove_tabs_js(app: "Sphinx", exc: Exception) -> None:

src/libvcs/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
from .sync.svn import SvnSync
1010

1111
__all__ = [
12+
"BaseSync",
13+
"CmdLoggingAdapter",
1214
"GitSync",
1315
"HgSync",
1416
"SvnSync",
15-
"BaseSync",
16-
"CmdLoggingAdapter",
1717
]
1818

1919
logger = logging.getLogger(__name__)

src/libvcs/_internal/query_list.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
This is an internal API not covered by versioning policy.
66
"""
77

8+
import logging
89
import re
910
import traceback
1011
import typing as t
1112
from collections.abc import Iterable, Mapping, Sequence
1213

14+
logger = logging.getLogger(__name__)
15+
1316
T = t.TypeVar("T")
1417
no_arg = object()
1518

@@ -86,7 +89,7 @@ def keygetter(
8689
dct = getattr(dct, sub_field)
8790
except Exception as e:
8891
traceback.print_stack()
89-
print(f"Above error was {e}")
92+
logger.debug(f"The above error was {e}")
9093
return None
9194
return dct
9295

@@ -120,8 +123,9 @@ def parse_lookup(obj: Mapping[str, t.Any], path: str, lookup: str) -> t.Optional
120123
field_name = path.rsplit(lookup)[0]
121124
if field_name is not None:
122125
return keygetter(obj, field_name)
123-
except Exception:
126+
except Exception as e:
124127
traceback.print_stack()
128+
logger.debug(f"The above error was {e}")
125129
return None
126130

127131

@@ -304,12 +308,12 @@ def lookup_iregex(
304308

305309

306310
class PKRequiredException(Exception):
307-
def __init__(self, *args: object):
311+
def __init__(self, *args: object) -> None:
308312
return super().__init__("items() require a pk_key exists")
309313

310314

311315
class OpNotFound(ValueError):
312-
def __init__(self, op: str, *args: object):
316+
def __init__(self, op: str, *args: object) -> None:
313317
return super().__init__(f"{op} not in LOOKUP_NAME_MAP")
314318

315319

@@ -470,7 +474,7 @@ def __init__(self, items: t.Optional["Iterable[T]"] = None) -> None:
470474

471475
def items(self) -> list[tuple[str, T]]:
472476
if self.pk_key is None:
473-
raise PKRequiredException()
477+
raise PKRequiredException
474478
return [(getattr(item, self.pk_key), item) for item in self]
475479

476480
def __eq__(
@@ -490,9 +494,8 @@ def __eq__(
490494
for key in a_keys:
491495
if abs(a[key] - b[key]) > 1:
492496
return False
493-
else:
494-
if a != b:
495-
return False
497+
elif a != b:
498+
return False
496499

497500
return True
498501
return False
@@ -529,8 +532,7 @@ def filter_lookup(obj: t.Any) -> bool:
529532
def val_match(obj: t.Union[str, list[t.Any], T]) -> bool:
530533
if isinstance(matcher, list):
531534
return obj in matcher
532-
else:
533-
return bool(obj == matcher)
535+
return bool(obj == matcher)
534536

535537
_filter = val_match
536538
else:
@@ -546,9 +548,9 @@ def get(
546548
) -> t.Optional[T]:
547549
objs = self.filter(matcher=matcher, **kwargs)
548550
if len(objs) > 1:
549-
raise MultipleObjectsReturned()
550-
elif len(objs) == 0:
551+
raise MultipleObjectsReturned
552+
if len(objs) == 0:
551553
if default == no_arg:
552-
raise ObjectDoesNotExist()
554+
raise ObjectDoesNotExist
553555
return default
554556
return objs[0]

src/libvcs/_internal/run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
from collections.abc import Iterable, Mapping, MutableMapping, Sequence
1616
from typing import IO, TYPE_CHECKING, Any, AnyStr, Callable, Optional, Protocol, Union
1717

18+
from libvcs import exc
1819
from libvcs._internal.types import StrOrBytesPath
1920

20-
from .. import exc
21-
2221
logger = logging.getLogger(__name__)
2322

2423
console_encoding = sys.__stdout__.encoding

src/libvcs/_internal/shortcuts.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919

2020

2121
class VCSNoMatchFoundForUrl(exc.LibVCSException):
22-
def __init__(self, url: str, *args: object):
22+
def __init__(self, url: str, *args: object) -> None:
2323
return super().__init__(f"No VCS found for url: {url}")
2424

2525

2626
class VCSMultipleMatchFoundForUrl(exc.LibVCSException):
27-
def __init__(self, url: str, *args: object):
27+
def __init__(self, url: str, *args: object) -> None:
2828
return super().__init__(f"Multiple VCS found for url: {url}")
2929

3030

3131
class VCSNotSupported(exc.LibVCSException):
32-
def __init__(self, url: str, vcs: str, *args: object):
32+
def __init__(self, url: str, vcs: str, *args: object) -> None:
3333
return super().__init__(f"VCS '{vcs}' not supported, based on URL: {url}")
3434

3535

@@ -110,7 +110,7 @@ def create_project(
110110
assert vcs_matches[0].vcs is not None
111111

112112
def is_vcs(val: t.Any) -> "TypeGuard[VCSLiteral]":
113-
return isinstance(val, str) and val in ["git", "hg", "svn"]
113+
return isinstance(val, str) and val in {"git", "hg", "svn"}
114114

115115
if is_vcs(vcs_matches[0].vcs):
116116
vcs = vcs_matches[0].vcs
@@ -119,13 +119,18 @@ def is_vcs(val: t.Any) -> "TypeGuard[VCSLiteral]":
119119

120120
if vcs == "git":
121121
return GitSync(
122-
url=url, path=path, progress_callback=progress_callback, **kwargs
122+
url=url,
123+
path=path,
124+
progress_callback=progress_callback,
125+
**kwargs,
123126
)
124-
elif vcs == "hg":
127+
if vcs == "hg":
125128
return HgSync(url=url, path=path, progress_callback=progress_callback, **kwargs)
126-
elif vcs == "svn":
129+
if vcs == "svn":
127130
return SvnSync(
128-
url=url, path=path, progress_callback=progress_callback, **kwargs
131+
url=url,
132+
path=path,
133+
progress_callback=progress_callback,
134+
**kwargs,
129135
)
130-
else:
131-
raise InvalidVCS("VCS %s is not a valid VCS" % vcs)
136+
raise InvalidVCS("VCS %s is not a valid VCS" % vcs)

src/libvcs/_internal/subprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868

6969
class SubprocessCheckOutputError(Exception):
70-
def __init__(self, output: str, *args: object):
70+
def __init__(self, output: str, *args: object) -> None:
7171
return super().__init__(f"output is not str or bytes: {output}")
7272

7373

src/libvcs/cmd/git.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def run(
206206
def stringify(v: Any) -> str:
207207
if isinstance(v, bool):
208208
return "true" if True else "false"
209-
elif not isinstance(v, str):
209+
if not isinstance(v, str):
210210
return str(v)
211211
return v
212212

@@ -398,7 +398,6 @@ def fetch(
398398
Union[bool, Literal["yes", "on-demand"]]
399399
] = None,
400400
submodule_prefix: Optional[StrOrBytesPath] = None,
401-
#
402401
_all: Optional[bool] = None,
403402
force: Optional[bool] = None,
404403
keep: Optional[bool] = None,
@@ -1821,9 +1820,8 @@ def rev_parse(
18211820
if parseopt is True:
18221821
if args is not None:
18231822
local_flags.extend(["--", args])
1824-
else:
1825-
if args is not None:
1826-
local_flags.append(args)
1823+
elif args is not None:
1824+
local_flags.append(args)
18271825

18281826
return self.run(
18291827
["rev-parse", *local_flags],

src/libvcs/cmd/svn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class SvnPropsetValueOrValuePathRequired(exc.LibVCSException, TypeError):
2626
"""Raised when required parameters are not passed."""
2727

28-
def __init__(self, *args: object):
28+
def __init__(self, *args: object) -> None:
2929
return super().__init__("Must enter a value or value_path")
3030

3131

@@ -783,7 +783,7 @@ def propset(
783783
elif isinstance(value_path, pathlib.Path):
784784
local_flags.extend(["--file", str(pathlib.Path(value_path).absolute())])
785785
else:
786-
raise SvnPropsetValueOrValuePathRequired()
786+
raise SvnPropsetValueOrValuePathRequired
787787

788788
if path is not None:
789789
if isinstance(path, (str, pathlib.Path)):

0 commit comments

Comments
 (0)