Skip to content

Commit f5ff8b7

Browse files
authored
libvcs v0.27.0 (linting updates, #435)
Includes breaking rename (`dir` -> `path`)
2 parents a1813a1 + 355ce6f commit f5ff8b7

14 files changed

+88
-75
lines changed

CHANGES

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ $ pipx install --suffix=@next 'vcspull' --pip-args '\--pre' --force
2121

2222
<!-- Maintainers, insert changes / features for the next release here -->
2323

24+
### Breaking changes
25+
26+
- libvcs: v0.25.0 -> v0.26.0 (#435)
27+
28+
Renamings of `dir` to `path`.
29+
30+
- Fix shadowing of python builtins
31+
32+
- `dir` -> `path` (#435)
33+
2434
### Documentation
2535

2636
- Refactor API docs to split across multiple pages (#431)

conftest.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ def cwd_default(monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path) -> None
4444
monkeypatch.chdir(tmp_path)
4545

4646

47-
@pytest.fixture(autouse=True, scope="session")
48-
@pytest.mark.usefixtures("set_home")
49-
def xdg_config_path(user_path: pathlib.Path) -> pathlib.Path:
47+
@pytest.fixture(autouse=True)
48+
def xdg_config_path(
49+
user_path: pathlib.Path,
50+
set_home: pathlib.Path,
51+
) -> pathlib.Path:
5052
"""Create and return path to use for XDG Config Path."""
5153
p = user_path / ".config"
52-
p.mkdir()
54+
if not p.exists():
55+
p.mkdir()
5356
return p
5457

5558

poetry.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ vcspull = 'vcspull:cli.cli'
6161

6262
[tool.poetry.dependencies]
6363
python = "^3.9"
64-
libvcs = "~0.26.0"
64+
libvcs = "~0.27.0"
6565
colorama = ">=0.3.9"
6666
PyYAML = "^6.0"
6767

scripts/generate_gitlab.py

+1-1
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

+4-4
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

+9-9
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

+2-2
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

+7-7
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": "[email protected]: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": "[email protected]: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": "[email protected]:tony/tmux-config.git",
9999
"shell_command_after": ["ln -sf /home/me/.tmux/.tmux.conf /home/me/.tmux.conf"],
100100
},

tests/test_cli.py

+7-7
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

+11-11
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

+2-2
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

0 commit comments

Comments
 (0)