Skip to content

Commit 60c883e

Browse files
committed
refactor!: dir -> path (libvcs 0.27.0 and avoid overshadowing builtin)
1 parent cb3fb02 commit 60c883e

File tree

10 files changed

+66
-66
lines changed

10 files changed

+66
-66
lines changed

scripts/generate_gitlab.py

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

9797
config[path][reponame] = {
9898
"name": reponame,
99-
"dir": path / reponame,
99+
"path": path / reponame,
100100
"url": f"git+ssh://{url_to_repo}",
101101
"remotes": {
102102
"origin": GitRemote(

src/vcspull/cli/sync.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ def sync(
7979
found_repos = []
8080

8181
for repo_pattern in repo_patterns:
82-
dir, vcs_url, name = None, None, None
82+
path, vcs_url, name = None, None, None
8383
if any(repo_pattern.startswith(n) for n in ["./", "/", "~", "$HOME"]):
84-
dir = repo_pattern
84+
path = repo_pattern
8585
elif any(repo_pattern.startswith(n) for n in ["http", "git", "svn", "hg"]):
8686
vcs_url = repo_pattern
8787
else:
8888
name = repo_pattern
8989

9090
# collect the repos from the config files
91-
found = filter_repos(configs, dir=dir, vcs_url=vcs_url, name=name)
91+
found = filter_repos(configs, path=path, vcs_url=vcs_url, name=name)
9292
if len(found) == 0:
9393
print(NO_REPOS_FOR_TERM_MSG.format(name=name))
94-
found_repos.extend(filter_repos(configs, dir=dir, vcs_url=vcs_url, name=name))
94+
found_repos.extend(filter_repos(configs, path=path, vcs_url=vcs_url, name=name))
9595

9696
for repo in found_repos:
9797
try:

src/vcspull/config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def extract_repos(
102102
if "name" not in conf:
103103
conf["name"] = repo
104104

105-
if "dir" not in conf:
106-
conf["dir"] = expand_dir(
105+
if "path" not in conf:
106+
conf["path"] = expand_dir(
107107
pathlib.Path(expand_dir(pathlib.Path(directory), cwd=cwd))
108108
/ conf["name"],
109109
cwd,
@@ -301,10 +301,10 @@ def detect_duplicate_repos(
301301
dupes: list[ConfigDictTuple] = []
302302

303303
repo_dirs = {
304-
pathlib.Path(repo["dir"]).parent / repo["name"]: repo for repo in config1
304+
pathlib.Path(repo["path"]).parent / repo["name"]: repo for repo in config1
305305
}
306306
repo_dirs_2 = {
307-
pathlib.Path(repo["dir"]).parent / repo["name"]: repo for repo in config2
307+
pathlib.Path(repo["path"]).parent / repo["name"]: repo for repo in config2
308308
}
309309

310310
for repo_dir, repo in repo_dirs.items():
@@ -347,19 +347,19 @@ def in_dir(
347347

348348
def filter_repos(
349349
config: list["ConfigDict"],
350-
dir: t.Union[pathlib.Path, t.Literal["*"], str, None] = None,
350+
path: t.Union[pathlib.Path, t.Literal["*"], str, None] = None,
351351
vcs_url: t.Union[str, None] = None,
352352
name: t.Union[str, None] = None,
353353
) -> list["ConfigDict"]:
354354
"""Return a :py:obj:`list` list of repos from (expanded) config file.
355355
356-
dir, vcs_url and name all support fnmatch.
356+
path, vcs_url and name all support fnmatch.
357357
358358
Parameters
359359
----------
360360
config : dict
361361
the expanded repo config in :py:class:`dict` format.
362-
dir : str, Optional
362+
path : str, Optional
363363
directory of checkout location, fnmatch pattern supported
364364
vcs_url : str, Optional
365365
url of vcs remote, fn match pattern supported
@@ -373,12 +373,12 @@ def filter_repos(
373373
"""
374374
repo_list: list["ConfigDict"] = []
375375

376-
if dir:
376+
if path:
377377
repo_list.extend(
378378
[
379379
r
380380
for r in config
381-
if fnmatch.fnmatch(str(pathlib.Path(r["dir"]).parent), str(dir))
381+
if fnmatch.fnmatch(str(pathlib.Path(r["path"]).parent), str(path))
382382
]
383383
)
384384

src/vcspull/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class RawConfigDict(t.TypedDict):
1212

1313
vcs: VCSLiteral
1414
name: str
15-
dir: StrPath
15+
path: StrPath
1616
url: str
1717
remotes: GitSyncRemoteDict
1818

@@ -26,7 +26,7 @@ class ConfigDict(TypedDict):
2626

2727
vcs: t.Optional[VCSLiteral]
2828
name: str
29-
dir: pathlib.Path
29+
path: pathlib.Path
3030
url: str
3131
remotes: NotRequired[t.Optional[GitSyncRemoteDict]]
3232
shell_command_after: NotRequired[t.Optional[list[str]]]

tests/fixtures/example.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,32 @@
4141
{
4242
"vcs": "git",
4343
"name": "linux",
44-
"dir": pathlib.Path("/home/me/myproject/study/linux"),
44+
"path": pathlib.Path("/home/me/myproject/study/linux"),
4545
"url": "git+git://git.kernel.org/linux/torvalds/linux.git",
4646
},
4747
{
4848
"vcs": "git",
4949
"name": "freebsd",
50-
"dir": pathlib.Path("/home/me/myproject/study/freebsd"),
50+
"path": pathlib.Path("/home/me/myproject/study/freebsd"),
5151
"url": "git+https://github.com/freebsd/freebsd.git",
5252
},
5353
{
5454
"vcs": "git",
5555
"name": "sphinx",
56-
"dir": pathlib.Path("/home/me/myproject/study/sphinx"),
56+
"path": pathlib.Path("/home/me/myproject/study/sphinx"),
5757
"url": "hg+https://bitbucket.org/birkenfeld/sphinx",
5858
},
5959
{
6060
"vcs": "git",
6161
"name": "docutils",
62-
"dir": pathlib.Path("/home/me/myproject/study/docutils"),
62+
"path": pathlib.Path("/home/me/myproject/study/docutils"),
6363
"url": "svn+http://svn.code.sf.net/p/docutils/code/trunk",
6464
},
6565
{
6666
"vcs": "git",
6767
"name": "kaptan",
6868
"url": "git+git@github.com:tony/kaptan.git",
69-
"dir": pathlib.Path("/home/me/myproject/github_projects/kaptan"),
69+
"path": pathlib.Path("/home/me/myproject/github_projects/kaptan"),
7070
"remotes": {
7171
"upstream": GitRemote(
7272
**{
@@ -87,14 +87,14 @@
8787
{
8888
"vcs": "git",
8989
"name": ".vim",
90-
"dir": pathlib.Path("/home/me/myproject/.vim"),
90+
"path": pathlib.Path("/home/me/myproject/.vim"),
9191
"url": "git+git@github.com:tony/vim-config.git",
9292
"shell_command_after": ["ln -sf /home/me/.vim/.vimrc /home/me/.vimrc"],
9393
},
9494
{
9595
"vcs": "git",
9696
"name": ".tmux",
97-
"dir": pathlib.Path("/home/me/myproject/.tmux"),
97+
"path": pathlib.Path("/home/me/myproject/.tmux"),
9898
"url": "git+git@github.com:tony/tmux-config.git",
9999
"shell_command_after": ["ln -sf /home/me/.tmux/.tmux.conf /home/me/.tmux.conf"],
100100
},

tests/test_cli.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def test_sync_cli_filter_non_existent(
8484
config = {
8585
"~/github_projects/": {
8686
"my_git_project": {
87-
"url": f"git+file://{git_repo.dir}",
88-
"remotes": {"test_remote": f"git+file://{git_repo.dir}"},
87+
"url": f"git+file://{git_repo.path}",
88+
"remotes": {"test_remote": f"git+file://{git_repo.path}"},
8989
},
9090
}
9191
}
@@ -219,11 +219,11 @@ def test_sync(
219219
config = {
220220
"~/github_projects/": {
221221
"my_git_repo": {
222-
"url": f"git+file://{git_repo.dir}",
223-
"remotes": {"test_remote": f"git+file://{git_repo.dir}"},
222+
"url": f"git+file://{git_repo.path}",
223+
"remotes": {"test_remote": f"git+file://{git_repo.path}"},
224224
},
225225
"broken_repo": {
226-
"url": f"git+file://{git_repo.dir}",
226+
"url": f"git+file://{git_repo.path}",
227227
"remotes": {"test_remote": "git+file://non-existent-remote"},
228228
},
229229
}
@@ -360,8 +360,8 @@ def test_sync_broken(
360360
config = {
361361
"~/github_projects/": {
362362
"my_git_repo": {
363-
"url": f"git+file://{git_repo.dir}",
364-
"remotes": {"test_remote": f"git+file://{git_repo.dir}"},
363+
"url": f"git+file://{git_repo.path}",
364+
"remotes": {"test_remote": f"git+file://{git_repo.path}"},
365365
},
366366
"my_git_repo_not_found": {
367367
"url": "git+file:///dev/null",

tests/test_config.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class LoadYAMLFn(t.Protocol):
1616
def __call__(
1717
self,
1818
content: str,
19-
dir: str = "randomdir",
19+
path: str = "randomdir",
2020
filename: str = "randomfilename.yaml",
2121
) -> tuple[pathlib.Path, list[t.Union[t.Any, pathlib.Path]], list["ConfigDict"]]:
2222
"""Callable function type signature for load_yaml pytest fixture."""
@@ -28,10 +28,10 @@ def load_yaml(tmp_path: pathlib.Path) -> LoadYAMLFn:
2828
"""Return a yaml loading function that uses temporary directory path."""
2929

3030
def fn(
31-
content: str, dir: str = "randomdir", filename: str = "randomfilename.yaml"
31+
content: str, path: str = "randomdir", filename: str = "randomfilename.yaml"
3232
) -> tuple[pathlib.Path, list[pathlib.Path], list["ConfigDict"]]:
3333
"""Return vcspull configurations and write out config to temp directory."""
34-
_dir = tmp_path / dir
34+
_dir = tmp_path / path
3535
_dir.mkdir()
3636
_config = _dir / filename
3737
_config.write_text(content, encoding="utf-8")
@@ -45,7 +45,7 @@ def fn(
4545

4646
def test_simple_format(load_yaml: LoadYAMLFn) -> None:
4747
"""Test simple configuration YAML file for vcspull."""
48-
dir, _, repos = load_yaml(
48+
path, _, repos = load_yaml(
4949
"""
5050
vcspull:
5151
libvcs: git+https://github.com/vcs-python/libvcs
@@ -55,24 +55,24 @@ def test_simple_format(load_yaml: LoadYAMLFn) -> None:
5555
assert len(repos) == 1
5656
repo = repos[0]
5757

58-
assert dir / "vcspull" == repo["dir"].parent
59-
assert dir / "vcspull" / "libvcs" == repo["dir"]
58+
assert path / "vcspull" == repo["path"].parent
59+
assert path / "vcspull" / "libvcs" == repo["path"]
6060

6161

6262
def test_relative_dir(load_yaml: LoadYAMLFn) -> None:
6363
"""Test configuration files for vcspull support relative directories."""
64-
dir, _, repos = load_yaml(
64+
path, _, repos = load_yaml(
6565
"""
6666
./relativedir:
6767
docutils: svn+http://svn.code.sf.net/p/docutils/code/trunk
6868
"""
6969
)
7070

71-
config_files = config.find_config_files(path=dir)
72-
repos = config.load_configs(config_files, dir)
71+
config_files = config.find_config_files(path=path)
72+
repos = config.load_configs(config_files, path)
7373

7474
assert len(repos) == 1
7575
repo = repos[0]
7676

77-
assert dir / "relativedir" == repo["dir"].parent
78-
assert dir / "relativedir" / "docutils" == repo["dir"]
77+
assert path / "relativedir" == repo["path"].parent
78+
assert path / "relativedir" / "docutils" == repo["path"]

tests/test_config_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ def test_expandenv_and_homevars() -> None:
171171
config1_expanded = extract_repos(config1)
172172
config2_expanded = extract_repos(config2)
173173

174-
paths = [r["dir"].parent for r in config1_expanded]
174+
paths = [r["path"].parent for r in config1_expanded]
175175
assert expand_dir(pathlib.Path("${HOME}/github_projects/")) in paths
176176
assert expand_dir(pathlib.Path("~/study/")) in paths
177177
assert expand_dir(pathlib.Path("~")) in paths
178178

179-
paths = [r["dir"].parent for r in config2_expanded]
179+
paths = [r["path"].parent for r in config2_expanded]
180180
assert expand_dir(pathlib.Path("${HOME}/github_projects/")) in paths
181181
assert expand_dir(pathlib.Path("~/study/")) in paths
182182

tests/test_repo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def test_filter_dir() -> None:
1313
"""`filter_repos` filter by dir."""
14-
repo_list = filter_repos(fixtures.config_dict_expanded, dir="*github_project*")
14+
repo_list = filter_repos(fixtures.config_dict_expanded, path="*github_project*")
1515

1616
assert len(repo_list) == 1
1717
for r in repo_list:
@@ -65,7 +65,7 @@ def test_vcs_url_scheme_to_object(tmp_path: pathlib.Path) -> None:
6565
git_repo = create_project(
6666
vcs="git",
6767
url="git+git://git.myproject.org/MyProject.git@da39a3ee5e6b4b",
68-
dir=str(tmp_path / "myproject1"),
68+
path=str(tmp_path / "myproject1"),
6969
)
7070

7171
# TODO cwd and name if duplicated should give an error
@@ -76,7 +76,7 @@ def test_vcs_url_scheme_to_object(tmp_path: pathlib.Path) -> None:
7676
hg_repo = create_project(
7777
vcs="hg",
7878
url="hg+https://hg.myproject.org/MyProject#egg=MyProject",
79-
dir=str(tmp_path / "myproject2"),
79+
path=str(tmp_path / "myproject2"),
8080
)
8181

8282
assert isinstance(hg_repo, HgSync)
@@ -85,7 +85,7 @@ def test_vcs_url_scheme_to_object(tmp_path: pathlib.Path) -> None:
8585
svn_repo = create_project(
8686
vcs="svn",
8787
url="svn+svn://svn.myproject.org/svn/MyProject#egg=MyProject",
88-
dir=str(tmp_path / "myproject3"),
88+
path=str(tmp_path / "myproject3"),
8989
)
9090

9191
assert isinstance(svn_repo, SvnSync)
@@ -101,11 +101,11 @@ def test_to_repo_objects(tmp_path: pathlib.Path) -> None:
101101
assert isinstance(r, BaseSync)
102102
assert r.repo_name
103103
assert r.repo_name == repo_dict["name"]
104-
assert r.dir.parent
104+
assert r.path.parent
105105
assert r.url
106106
assert r.url == repo_dict["url"]
107107

108-
assert r.dir == r.dir / r.repo_name
108+
assert r.path == r.path / r.repo_name
109109

110110
if hasattr(r, "remotes") and isinstance(r, GitSync):
111111
assert isinstance(r.remotes, dict)

0 commit comments

Comments
 (0)