Skip to content

Commit 27d3297

Browse files
committed
style: Apply ruff linting and formatting fixes
Applied automatic fixes from ruff including: - Remove unused variables and replace with underscore prefix - Fix import ordering - Remove trailing whitespace - Add trailing commas - Fix type annotation formatting - Simplify conditional logic
1 parent 17f218c commit 27d3297

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

src/vcspull/cli/fmt.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,16 @@ def normalize_repo_config(repo_data: t.Any) -> dict[str, t.Any]:
5656
if isinstance(repo_data, str):
5757
# Convert compact format to verbose format
5858
return {"repo": repo_data}
59-
elif isinstance(repo_data, dict):
59+
if isinstance(repo_data, dict):
6060
# If it has 'url' key but not 'repo', convert to use 'repo'
6161
if "url" in repo_data and "repo" not in repo_data:
6262
normalized = repo_data.copy()
6363
normalized["repo"] = normalized.pop("url")
6464
return normalized
6565
# Already in correct format or has other fields
6666
return repo_data
67-
else:
68-
# Return as-is for other types
69-
return t.cast(dict[str, t.Any], repo_data)
67+
# Return as-is for other types
68+
return t.cast("dict[str, t.Any]", repo_data)
7069

7170

7271
def format_config(config_data: dict[str, t.Any]) -> tuple[dict[str, t.Any], int]:
@@ -202,7 +201,7 @@ def format_single_config(
202201

203202
for directory, repos in raw_config.items():
204203
if isinstance(repos, dict):
205-
for repo_name, repo_data in repos.items():
204+
for repo_data in repos.values():
206205
if isinstance(repo_data, str):
207206
compact_to_verbose += 1
208207
elif isinstance(repo_data, dict):
@@ -273,7 +272,7 @@ def format_single_config(
273272
Fore.CYAN,
274273
Style.RESET_ALL,
275274
)
276-
275+
277276
return True
278277

279278

@@ -296,25 +295,25 @@ def format_config_file(
296295
if format_all:
297296
# Format all discovered config files
298297
config_files = find_config_files(include_home=True)
299-
298+
300299
# Also check for local .vcspull.yaml
301300
local_yaml = pathlib.Path.cwd() / ".vcspull.yaml"
302301
if local_yaml.exists() and local_yaml not in config_files:
303302
config_files.append(local_yaml)
304-
303+
305304
# Also check for local .vcspull.json
306305
local_json = pathlib.Path.cwd() / ".vcspull.json"
307306
if local_json.exists() and local_json not in config_files:
308307
config_files.append(local_json)
309-
308+
310309
if not config_files:
311310
log.error(
312311
"%s✗%s No configuration files found.",
313312
Fore.RED,
314313
Style.RESET_ALL,
315314
)
316315
return
317-
316+
318317
log.info(
319318
"%si%s Found %s%d%s configuration %s to format:",
320319
Fore.CYAN,
@@ -324,7 +323,7 @@ def format_config_file(
324323
Style.RESET_ALL,
325324
"file" if len(config_files) == 1 else "files",
326325
)
327-
326+
328327
for config_file in config_files:
329328
log.info(
330329
" %s•%s %s%s%s",
@@ -334,14 +333,14 @@ def format_config_file(
334333
config_file,
335334
Style.RESET_ALL,
336335
)
337-
336+
338337
log.info("") # Empty line for readability
339-
338+
340339
success_count = 0
341340
for config_file in config_files:
342341
if format_single_config(config_file, write):
343342
success_count += 1
344-
343+
345344
# Summary
346345
if success_count == len(config_files):
347346
log.info(
@@ -385,5 +384,5 @@ def format_config_file(
385384
return
386385
else:
387386
config_file_path = home_configs[0]
388-
387+
389388
format_single_config(config_file_path, write)

tests/cli/test_fmt.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import logging
6-
import pathlib
76
import typing as t
87

98
import pytest
@@ -12,6 +11,8 @@
1211
from vcspull.cli.fmt import format_config, format_config_file, normalize_repo_config
1312

1413
if t.TYPE_CHECKING:
14+
import pathlib
15+
1516
from _pytest.logging import LogCaptureFixture
1617

1718

@@ -31,9 +32,9 @@ def reset_logging() -> t.Generator[None, None, None]:
3132
logger = logging.getLogger(logger_name)
3233
logger.handlers.clear()
3334
logger.propagate = True # Re-enable propagation so pytest can capture logs
34-
35+
3536
yield
36-
37+
3738
# Clear again after test
3839
for logger_name in cli_loggers:
3940
logger = logging.getLogger(logger_name)
@@ -107,7 +108,7 @@ def test_sort_repositories(self) -> None:
107108
"zebra": "url1",
108109
"alpha": "url2",
109110
"beta": "url3",
110-
}
111+
},
111112
}
112113
formatted, changes = format_config(config)
113114
assert list(formatted["~/projects/"].keys()) == ["alpha", "beta", "zebra"]
@@ -120,21 +121,21 @@ def test_compact_format_conversion(self) -> None:
120121
"repo1": "git+https://github.com/user/repo1.git",
121122
"repo2": {"url": "git+https://github.com/user/repo2.git"},
122123
"repo3": {"repo": "git+https://github.com/user/repo3.git"},
123-
}
124+
},
124125
}
125126
formatted, changes = format_config(config)
126127

127128
# repo1 should be converted from compact to verbose
128129
assert formatted["~/projects/"]["repo1"] == {
129-
"repo": "git+https://github.com/user/repo1.git"
130+
"repo": "git+https://github.com/user/repo1.git",
130131
}
131132
# repo2 should have url converted to repo
132133
assert formatted["~/projects/"]["repo2"] == {
133-
"repo": "git+https://github.com/user/repo2.git"
134+
"repo": "git+https://github.com/user/repo2.git",
134135
}
135136
# repo3 should stay the same
136137
assert formatted["~/projects/"]["repo3"] == {
137-
"repo": "git+https://github.com/user/repo3.git"
138+
"repo": "git+https://github.com/user/repo3.git",
138139
}
139140
assert changes == 2 # repo1 and repo2 changed
140141

@@ -362,40 +363,42 @@ def test_format_all_configs(
362363
# Create test config directory structure
363364
config_dir = tmp_path / ".config" / "vcspull"
364365
config_dir.mkdir(parents=True)
365-
366+
366367
# Create home config (already formatted correctly)
367368
home_config = tmp_path / ".vcspull.yaml"
368369
home_config.write_text(
369370
yaml.dump({"~/projects/": {"repo1": {"repo": "url1"}}}),
370371
encoding="utf-8",
371372
)
372-
373+
373374
# Create config in config directory (needs sorting)
374375
config1 = config_dir / "work.yaml"
375376
config1_content = """~/work/:
376377
repo2: url2
377378
repo1: url1
378379
"""
379380
config1.write_text(config1_content, encoding="utf-8")
380-
381+
381382
# Create local config
382383
local_config = tmp_path / "project" / ".vcspull.yaml"
383384
local_config.parent.mkdir()
384385
local_config.write_text(
385386
yaml.dump({"./": {"repo3": {"url": "url3"}}}),
386387
encoding="utf-8",
387388
)
388-
389+
389390
# Mock find functions to return our test configs
390391
def mock_find_config_files(include_home: bool = False) -> list[pathlib.Path]:
391392
files = [config1]
392393
if include_home:
393394
files.insert(0, home_config)
394395
return files
395-
396-
def mock_find_home_config_files(filetype: list[str] | None = None) -> list[pathlib.Path]:
396+
397+
def mock_find_home_config_files(
398+
filetype: list[str] | None = None,
399+
) -> list[pathlib.Path]:
397400
return [home_config]
398-
401+
399402
# Change to project directory
400403
monkeypatch.chdir(local_config.parent)
401404
monkeypatch.setattr(
@@ -406,19 +409,21 @@ def mock_find_home_config_files(filetype: list[str] | None = None) -> list[pathl
406409
"vcspull.cli.fmt.find_home_config_files",
407410
mock_find_home_config_files,
408411
)
409-
412+
410413
with caplog.at_level(logging.INFO):
411414
format_config_file(None, write=False, format_all=True)
412-
415+
413416
# Check that all configs were found
414417
assert "Found 3 configuration files to format" in caplog.text
415418
assert str(home_config) in caplog.text
416419
assert str(config1) in caplog.text
417420
assert str(local_config) in caplog.text
418-
421+
419422
# Check processing messages
420423
assert "already formatted correctly" in caplog.text # home_config
421-
assert "3 formatting issues" in caplog.text # config1 has 2 compact + needs sorting
424+
assert (
425+
"3 formatting issues" in caplog.text
426+
) # config1 has 2 compact + needs sorting
422427
assert "2 repositories from compact to verbose format" in caplog.text # config1
423428
assert "Repositories in ~/work/ will be sorted" in caplog.text # config1
424429
assert "1 repository from 'url' to 'repo' key" in caplog.text # local_config

0 commit comments

Comments
 (0)