|
26 | 26 |
|
27 | 27 | log = logging.getLogger(__name__) |
28 | 28 |
|
| 29 | +RepoConfigData: t.TypeAlias = str | pathlib.Path | t.Mapping[str, object] |
| 30 | + |
29 | 31 |
|
30 | 32 | class FmtAction(enum.Enum): |
31 | 33 | """Action resolved for each repo entry during ``vcspull fmt``.""" |
@@ -64,12 +66,12 @@ def create_fmt_subparser(parser: argparse.ArgumentParser) -> None: |
64 | 66 | parser.set_defaults(merge_roots=True) |
65 | 67 |
|
66 | 68 |
|
67 | | -def normalize_repo_config(repo_data: object) -> dict[str, object]: |
| 69 | +def normalize_repo_config(repo_data: RepoConfigData) -> dict[str, object]: |
68 | 70 | """Normalize repository configuration to verbose format. |
69 | 71 |
|
70 | 72 | Parameters |
71 | 73 | ---------- |
72 | | - repo_data : Any |
| 74 | + repo_data : str | pathlib.Path | Mapping[str, object] |
73 | 75 | Repository configuration (string URL or dict) |
74 | 76 |
|
75 | 77 | Returns |
@@ -104,16 +106,16 @@ def normalize_repo_config(repo_data: object) -> dict[str, object]: |
104 | 106 | if isinstance(repo_data, str): |
105 | 107 | # Convert compact format to verbose format |
106 | 108 | return {"repo": repo_data} |
107 | | - if isinstance(repo_data, dict): |
108 | | - # If it has 'url' key but not 'repo', convert to use 'repo' |
109 | | - if "url" in repo_data and "repo" not in repo_data: |
110 | | - normalized = repo_data.copy() |
111 | | - normalized["repo"] = normalized.pop("url") |
112 | | - return normalized |
113 | | - # Already in correct format or has other fields |
114 | | - return t.cast("dict[str, object]", repo_data) |
115 | | - # Return as-is for other types |
116 | | - return t.cast("dict[str, object]", repo_data) |
| 109 | + if isinstance(repo_data, pathlib.Path): |
| 110 | + return {"repo": str(repo_data)} |
| 111 | + repo_map = dict(repo_data) |
| 112 | + # If it has 'url' key but not 'repo', convert to use 'repo' |
| 113 | + if "url" in repo_map and "repo" not in repo_map: |
| 114 | + normalized = repo_map.copy() |
| 115 | + normalized["repo"] = normalized.pop("url") |
| 116 | + return normalized |
| 117 | + # Already in correct format or has other fields |
| 118 | + return repo_map |
117 | 119 |
|
118 | 120 |
|
119 | 121 | def _classify_fmt_action(repo_data: t.Any) -> tuple[FmtAction, t.Any]: |
|
0 commit comments