Skip to content

Commit 311dafc

Browse files
committed
config(refactor[typing]): Tighten raw config aliases
why: Reflect the workspace->repo mapping shape and allow simple repo shorthands. what: - Define RawConfigDict/RawRepoConfigValue aliases with nested dict patterns - Accept pathlib.Path shorthand in extract_repos without type errors - Narrow config reader key type and simplify test typing
1 parent 111de23 commit 311dafc

4 files changed

Lines changed: 14 additions & 19 deletions

File tree

src/vcspull/_internal/config_reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import yaml
99

1010
FormatLiteral = t.Literal["json", "yaml"]
11-
RawConfigData: t.TypeAlias = dict[t.Any, t.Any]
11+
RawConfigData: t.TypeAlias = dict[str, t.Any]
1212

1313

1414
class ConfigReader:

src/vcspull/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def extract_repos(
9090
also assures the repo is a :py:class:`dict`.
9191
"""
9292

93-
if isinstance(repo_data, str):
94-
conf["url"] = repo_data
93+
if isinstance(repo_data, (str, pathlib.Path)):
94+
conf["url"] = str(repo_data)
9595
else:
9696
conf = update_dict(conf, repo_data)
9797

src/vcspull/types.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,18 @@
3636
from typing_extensions import NotRequired, TypedDict
3737

3838
if t.TYPE_CHECKING:
39-
from libvcs._internal.types import StrPath, VCSLiteral
39+
from libvcs._internal.types import VCSLiteral
4040
from libvcs.sync.git import GitSyncRemoteDict
4141

42+
RawRepoFieldValue: TypeAlias = (
43+
str | list[str] | dict[str, str] | dict[str, dict[str, str]] | None
44+
)
45+
RawRepoConfigValue: TypeAlias = str | pathlib.Path | dict[str, RawRepoFieldValue]
46+
RawWorkspaceConfig: TypeAlias = dict[str, RawRepoConfigValue]
47+
RawConfigDict: TypeAlias = dict[str, RawWorkspaceConfig]
4248

43-
class RawConfigDict(t.TypedDict):
44-
"""Configuration dictionary without any type marshalling or variable resolution."""
45-
46-
vcs: VCSLiteral
47-
name: str
48-
path: StrPath
49-
url: str
50-
remotes: GitSyncRemoteDict
51-
52-
53-
RawConfigDir = dict[str, RawConfigDict]
54-
RawConfig = dict[str, RawConfigDir]
49+
RawConfigDir: TypeAlias = RawWorkspaceConfig
50+
RawConfig: TypeAlias = RawConfigDict
5551

5652

5753
class ConfigDict(TypedDict):

tests/test_config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class ExtractWorkspaceFixture(t.NamedTuple):
123123
)
124124
def test_extract_repos_injects_workspace_root(
125125
test_id: str,
126-
raw_config: dict[str, dict[str, str | dict[str, str]]],
126+
raw_config: RawConfigDict,
127127
expected_roots: dict[str, str],
128128
tmp_path: pathlib.Path,
129129
monkeypatch: pytest.MonkeyPatch,
@@ -134,8 +134,7 @@ def test_extract_repos_injects_workspace_root(
134134
monkeypatch.setenv("HOME", str(tmp_path))
135135
monkeypatch.chdir(tmp_path)
136136

137-
typed_raw_config = t.cast("RawConfigDict", raw_config)
138-
repos = config.extract_repos(typed_raw_config, cwd=tmp_path)
137+
repos = config.extract_repos(raw_config, cwd=tmp_path)
139138

140139
assert len(repos) == len(expected_roots)
141140

0 commit comments

Comments
 (0)