Skip to content

Commit 70b08f5

Browse files
committed
chore(ruff): Run automated fixes (73 fixed)
ruff --show-fixes --fix . Fixed 73 errors: - conftest.py: 1 × UP006 (non-pep585-annotation) - docs/conf.py: 1 × I001 (unsorted-imports) 1 × SIM108 (if-else-block-instead-of-if-exp) 1 × RUF100 (unused-noqa) - scripts/generate_gitlab.py: 1 × I001 (unsorted-imports) 1 × SIM300 (yoda-conditions) 1 × UP031 (printf-string-formatting) 1 × UP032 (f-string) 1 × UP024 (os-error-alias) - src/vcspull/__init__.py: 1 × RUF100 (unused-noqa) - src/vcspull/_internal/config_reader.py: 5 × UP006 (non-pep585-annotation) - src/vcspull/cli/__init__.py: 3 × UP006 (non-pep585-annotation) - src/vcspull/cli/sync.py: 1 × UP006 (non-pep585-annotation) - src/vcspull/config.py: 5 × UP006 (non-pep585-annotation) 5 × B006 (mutable-argument-default) 4 × RUF013 (implicit-optional) 1 × I001 (unsorted-imports) 1 × UP018 (native-literals) - src/vcspull/log.py: 1 × SIM210 (if-expr-with-true-false) - src/vcspull/types.py: 1 × I001 (unsorted-imports) 1 × UP006 (non-pep585-annotation) - src/vcspull/util.py: 1 × UP006 (non-pep585-annotation) - src/vcspull/validator.py: 1 × UP006 (non-pep585-annotation) 1 × PERF102 (incorrect-dict-iterator) 1 × SIM102 (collapsible-if) 1 × B007 (unused-loop-control-variable) - tests/__init__.py: 1 × RUF100 (unused-noqa) - tests/helpers.py: 2 × UP006 (non-pep585-annotation) 1 × C408 (unnecessary-collection-call) - tests/test_cli.py: 3 × SIM105 (suppressible-exception) 2 × I001 (unsorted-imports) 1 × UP006 (non-pep585-annotation) - tests/test_config.py: 6 × UP006 (non-pep585-annotation) - tests/test_config_file.py: 2 × B007 (unused-loop-control-variable) 1 × SIM117 (multiple-with-statements) - tests/test_repo.py: 2 × SIM300 (yoda-conditions) 1 × I001 (unsorted-imports) 1 × PERF102 (incorrect-dict-iterator) 1 × B007 (unused-loop-control-variable) - tests/test_sync.py: 2 × SIM118 (in-dict-keys) 2 × PERF102 (incorrect-dict-iterator) 1 × I001 (unsorted-imports) 1 × UP006 (non-pep585-annotation)
1 parent 5c73af5 commit 70b08f5

19 files changed

+76
-73
lines changed

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@pytest.fixture(autouse=True)
99
def add_doctest_fixtures(
1010
request: pytest.FixtureRequest,
11-
doctest_namespace: t.Dict[str, t.Any],
11+
doctest_namespace: dict[str, t.Any],
1212
) -> None:
1313
from _pytest.doctest import DoctestItem
1414

docs/conf.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# flake8: noqa: E501
22
import inspect
3+
import pathlib
34
import sys
45
import typing as t
56
from os.path import relpath
6-
import pathlib
77

88
import vcspull
99

@@ -180,7 +180,7 @@
180180

181181
def linkcode_resolve(
182182
domain: str, info: dict[str, str]
183-
) -> t.Union[None, str]: # NOQA: C901
183+
) -> t.Union[None, str]:
184184
"""
185185
Determine the URL corresponding to Python object
186186
@@ -228,10 +228,7 @@ def linkcode_resolve(
228228
except Exception:
229229
lineno = None
230230

231-
if lineno:
232-
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1)
233-
else:
234-
linespec = ""
231+
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1) if lineno else ""
235232

236233
fn = relpath(fn, start=pathlib.Path(vcspull.__file__).parent)
237234

scripts/generate_gitlab.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import requests
88
import yaml
9-
109
from libvcs.sync.git import GitRemote
10+
1111
from vcspull.cli.sync import guess_vcs
1212
from vcspull.types import RawConfig
1313

@@ -58,17 +58,17 @@
5858
sys.exit(0)
5959

6060
config_file = open(config_filename, "w")
61-
except IOError:
61+
except OSError:
6262
print("File %s not accesible" % (config_filename))
6363
sys.exit(1)
6464

6565
response = requests.get(
66-
"%s/api/v4/groups/%s/projects" % (gitlab_host, gitlab_namespace),
66+
f"{gitlab_host}/api/v4/groups/{gitlab_namespace}/projects",
6767
params={"include_subgroups": "true", "per_page": "100"},
6868
headers={"Authorization": "Bearer %s" % (gitlab_token)},
6969
)
7070

71-
if 200 != response.status_code:
71+
if response.status_code != 200:
7272
print("Error: ", response)
7373
sys.exit(1)
7474

src/vcspull/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
import logging
1313
from logging import NullHandler
1414

15-
from . import cli # NOQA
15+
from . import cli
1616

1717
logging.getLogger(__name__).addHandler(NullHandler())

src/vcspull/_internal/config_reader.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
FormatLiteral = Literal["json", "yaml"]
1111

12-
RawConfigData: TypeAlias = t.Dict[t.Any, t.Any]
12+
RawConfigData: TypeAlias = dict[t.Any, t.Any]
1313

1414

1515
class ConfigReader:
@@ -26,7 +26,7 @@ def __init__(self, content: "RawConfigData") -> None:
2626
self.content = content
2727

2828
@staticmethod
29-
def _load(format: "FormatLiteral", content: str) -> t.Dict[str, t.Any]:
29+
def _load(format: "FormatLiteral", content: str) -> dict[str, t.Any]:
3030
"""Load raw config data and directly return it.
3131
3232
>>> ConfigReader._load("json", '{ "session_name": "my session" }')
@@ -37,14 +37,14 @@ def _load(format: "FormatLiteral", content: str) -> t.Dict[str, t.Any]:
3737
"""
3838
if format == "yaml":
3939
return t.cast(
40-
t.Dict[str, t.Any],
40+
dict[str, t.Any],
4141
yaml.load(
4242
content,
4343
Loader=yaml.SafeLoader,
4444
),
4545
)
4646
elif format == "json":
47-
return t.cast(t.Dict[str, t.Any], json.loads(content))
47+
return t.cast(dict[str, t.Any], json.loads(content))
4848
else:
4949
raise NotImplementedError(f"{format} not supported in configuration")
5050

@@ -72,7 +72,7 @@ def load(cls, format: "FormatLiteral", content: str) -> "ConfigReader":
7272
)
7373

7474
@classmethod
75-
def _from_file(cls, path: pathlib.Path) -> t.Dict[str, t.Any]:
75+
def _from_file(cls, path: pathlib.Path) -> dict[str, t.Any]:
7676
r"""Load data from file path directly to dictionary.
7777
7878
**YAML file**

src/vcspull/cli/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
@overload
3636
def create_parser(
3737
return_subparsers: t.Literal[True],
38-
) -> t.Tuple[argparse.ArgumentParser, t.Any]:
38+
) -> tuple[argparse.ArgumentParser, t.Any]:
3939
...
4040

4141

@@ -46,7 +46,7 @@ def create_parser(return_subparsers: t.Literal[False]) -> argparse.ArgumentParse
4646

4747
def create_parser(
4848
return_subparsers: bool = False,
49-
) -> t.Union[argparse.ArgumentParser, t.Tuple[argparse.ArgumentParser, t.Any]]:
49+
) -> t.Union[argparse.ArgumentParser, tuple[argparse.ArgumentParser, t.Any]]:
5050
parser = argparse.ArgumentParser(
5151
prog="vcspull",
5252
formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -80,7 +80,7 @@ def create_parser(
8080
return parser
8181

8282

83-
def cli(_args: t.Optional[t.List[str]] = None) -> None:
83+
def cli(_args: t.Optional[list[str]] = None) -> None:
8484
parser, sync_parser = create_parser(return_subparsers=True)
8585
args = parser.parse_args(_args)
8686

src/vcspull/cli/sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def create_sync_subparser(parser: argparse.ArgumentParser) -> argparse.ArgumentP
5555

5656

5757
def sync(
58-
repo_patterns: t.List[str],
58+
repo_patterns: list[str],
5959
config: pathlib.Path,
6060
exit_on_error: bool,
6161
parser: t.Optional[

src/vcspull/config.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import typing as t
1313

1414
from libvcs.sync.git import GitRemote
15+
1516
from vcspull.validator import is_valid_config
1617

1718
from . import exc
@@ -73,7 +74,7 @@ def extract_repos(
7374
for directory, repos in config.items():
7475
assert isinstance(repos, dict)
7576
for repo, repo_data in repos.items():
76-
conf: t.Dict[str, t.Any] = {}
77+
conf: dict[str, t.Any] = {}
7778

7879
"""
7980
repo_name: http://myrepo.com/repo.git
@@ -134,9 +135,11 @@ def is_valid_config_dict(val: t.Any) -> "TypeGuard[ConfigDict]":
134135

135136

136137
def find_home_config_files(
137-
filetype: list[str] = ["json", "yaml"]
138+
filetype: t.Optional[list[str]] = None
138139
) -> list[pathlib.Path]:
139140
"""Return configs of ``.vcspull.{yaml,json}`` in user's home directory."""
141+
if filetype is None:
142+
filetype = ["json", "yaml"]
140143
configs: list[pathlib.Path] = []
141144

142145
yaml_config = pathlib.Path(os.path.expanduser("~/.vcspull.yaml"))
@@ -151,7 +154,7 @@ def find_home_config_files(
151154
" quickstart."
152155
)
153156
else:
154-
if sum(filter(None, [has_json_config, has_yaml_config])) > int(1):
157+
if sum(filter(None, [has_json_config, has_yaml_config])) > 1:
155158
raise exc.MultipleConfigWarning()
156159
if has_yaml_config:
157160
configs.append(yaml_config)
@@ -163,12 +166,12 @@ def find_home_config_files(
163166

164167
def find_config_files(
165168
path: t.Optional[t.Union[list[pathlib.Path], pathlib.Path]] = None,
166-
match: t.Union[list[str], str] = ["*"],
169+
match: t.Optional[t.Union[list[str], str]] = None,
167170
filetype: t.Union[
168171
t.Literal["json", "yaml", "*"], list[t.Literal["json", "yaml", "*"]]
169-
] = ["json", "yaml"],
172+
] = None,
170173
include_home: bool = False,
171-
) -> t.List[pathlib.Path]:
174+
) -> list[pathlib.Path]:
172175
"""Return repos from a directory and match. Not recursive.
173176
174177
Parameters
@@ -192,6 +195,10 @@ def find_config_files(
192195
list :
193196
list of absolute paths to config files.
194197
"""
198+
if filetype is None:
199+
filetype = ["json", "yaml"]
200+
if match is None:
201+
match = ["*"]
195202
config_files = []
196203
if path is None:
197204
path = get_config_dir()
@@ -221,7 +228,7 @@ def find_config_files(
221228

222229
def load_configs(
223230
files: list[pathlib.Path], cwd: pathlib.Path = pathlib.Path.cwd()
224-
) -> t.List["ConfigDict"]:
231+
) -> list["ConfigDict"]:
225232
"""Return repos from a list of files.
226233
227234
Parameters
@@ -303,8 +310,8 @@ def detect_duplicate_repos(
303310

304311
def in_dir(
305312
config_dir: t.Optional[pathlib.Path] = None,
306-
extensions: list[str] = [".yml", ".yaml", ".json"],
307-
) -> t.List[str]:
313+
extensions: t.Optional[list[str]] = None,
314+
) -> list[str]:
308315
"""Return a list of configs in ``config_dir``.
309316
310317
Parameters
@@ -318,6 +325,8 @@ def in_dir(
318325
-------
319326
list
320327
"""
328+
if extensions is None:
329+
extensions = [".yml", ".yaml", ".json"]
321330
if config_dir is not None:
322331
config_dir = get_config_dir()
323332
configs = []
@@ -330,7 +339,7 @@ def in_dir(
330339

331340

332341
def filter_repos(
333-
config: t.List["ConfigDict"],
342+
config: list["ConfigDict"],
334343
dir: t.Union[pathlib.Path, t.Literal["*"], str, None] = None,
335344
vcs_url: t.Union[str, None] = None,
336345
name: t.Union[str, None] = None,
@@ -382,7 +391,7 @@ def filter_repos(
382391

383392

384393
def is_config_file(
385-
filename: str, extensions: t.Union[list[str], str] = [".yml", ".yaml", ".json"]
394+
filename: str, extensions: t.Optional[t.Union[list[str], str]] = None
386395
) -> bool:
387396
"""Return True if file has a valid config file type.
388397
@@ -397,5 +406,7 @@ def is_config_file(
397406
-------
398407
bool : True if is a valid config file type
399408
"""
409+
if extensions is None:
410+
extensions = [".yml", ".yaml", ".json"]
400411
extensions = [extensions] if isinstance(extensions, str) else extensions
401412
return any(filename.endswith(e) for e in extensions)

src/vcspull/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,4 @@ class RepoFilter(logging.Filter):
191191

192192
def filter(self, record: logging.LogRecord) -> bool:
193193
"""Only return a record if a keyword object."""
194-
return True if "keyword" in record.__dict__ else False
194+
return "keyword" in record.__dict__

src/vcspull/types.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import pathlib
22
import typing as t
33

4-
from typing_extensions import NotRequired, TypedDict
5-
64
from libvcs._internal.types import StrPath, VCSLiteral
75
from libvcs.sync.git import GitSyncRemoteDict
6+
from typing_extensions import NotRequired, TypedDict
87

98

109
class RawConfigDict(t.TypedDict):
@@ -25,7 +24,7 @@ class ConfigDict(TypedDict):
2524
dir: pathlib.Path
2625
url: str
2726
remotes: NotRequired[t.Optional[GitSyncRemoteDict]]
28-
shell_command_after: NotRequired[t.Optional[t.List[str]]]
27+
shell_command_after: NotRequired[t.Optional[list[str]]]
2928

3029

3130
ConfigDir = dict[str, ConfigDict]

0 commit comments

Comments
 (0)