diff --git a/scripts/generate_gitlab.py b/scripts/generate_gitlab.py index 52346474..7afe4664 100755 --- a/scripts/generate_gitlab.py +++ b/scripts/generate_gitlab.py @@ -96,7 +96,7 @@ config[path][reponame] = { "name": reponame, - "dir": path / reponame, + "path": path / reponame, "url": f"git+ssh://{url_to_repo}", "remotes": { "origin": GitRemote( diff --git a/src/vcspull/cli/sync.py b/src/vcspull/cli/sync.py index f93e6a77..1609368c 100644 --- a/src/vcspull/cli/sync.py +++ b/src/vcspull/cli/sync.py @@ -79,19 +79,19 @@ def sync( found_repos = [] for repo_pattern in repo_patterns: - dir, vcs_url, name = None, None, None + path, vcs_url, name = None, None, None if any(repo_pattern.startswith(n) for n in ["./", "/", "~", "$HOME"]): - dir = repo_pattern + path = repo_pattern elif any(repo_pattern.startswith(n) for n in ["http", "git", "svn", "hg"]): vcs_url = repo_pattern else: name = repo_pattern # collect the repos from the config files - found = filter_repos(configs, dir=dir, vcs_url=vcs_url, name=name) + found = filter_repos(configs, path=path, vcs_url=vcs_url, name=name) if len(found) == 0: print(NO_REPOS_FOR_TERM_MSG.format(name=name)) - found_repos.extend(filter_repos(configs, dir=dir, vcs_url=vcs_url, name=name)) + found_repos.extend(filter_repos(configs, path=path, vcs_url=vcs_url, name=name)) for repo in found_repos: try: diff --git a/src/vcspull/config.py b/src/vcspull/config.py index bf30c383..928b1bdf 100644 --- a/src/vcspull/config.py +++ b/src/vcspull/config.py @@ -102,8 +102,8 @@ def extract_repos( if "name" not in conf: conf["name"] = repo - if "dir" not in conf: - conf["dir"] = expand_dir( + if "path" not in conf: + conf["path"] = expand_dir( pathlib.Path(expand_dir(pathlib.Path(directory), cwd=cwd)) / conf["name"], cwd, @@ -301,10 +301,10 @@ def detect_duplicate_repos( dupes: list[ConfigDictTuple] = [] repo_dirs = { - pathlib.Path(repo["dir"]).parent / repo["name"]: repo for repo in config1 + pathlib.Path(repo["path"]).parent / repo["name"]: repo for repo in config1 } repo_dirs_2 = { - pathlib.Path(repo["dir"]).parent / repo["name"]: repo for repo in config2 + pathlib.Path(repo["path"]).parent / repo["name"]: repo for repo in config2 } for repo_dir, repo in repo_dirs.items(): @@ -347,19 +347,19 @@ def in_dir( def filter_repos( config: list["ConfigDict"], - dir: t.Union[pathlib.Path, t.Literal["*"], str, None] = None, + path: t.Union[pathlib.Path, t.Literal["*"], str, None] = None, vcs_url: t.Union[str, None] = None, name: t.Union[str, None] = None, ) -> list["ConfigDict"]: """Return a :py:obj:`list` list of repos from (expanded) config file. - dir, vcs_url and name all support fnmatch. + path, vcs_url and name all support fnmatch. Parameters ---------- config : dict the expanded repo config in :py:class:`dict` format. - dir : str, Optional + path : str, Optional directory of checkout location, fnmatch pattern supported vcs_url : str, Optional url of vcs remote, fn match pattern supported @@ -373,12 +373,12 @@ def filter_repos( """ repo_list: list["ConfigDict"] = [] - if dir: + if path: repo_list.extend( [ r for r in config - if fnmatch.fnmatch(str(pathlib.Path(r["dir"]).parent), str(dir)) + if fnmatch.fnmatch(str(pathlib.Path(r["path"]).parent), str(path)) ] ) diff --git a/src/vcspull/types.py b/src/vcspull/types.py index 5d9f112a..b83f8ee9 100644 --- a/src/vcspull/types.py +++ b/src/vcspull/types.py @@ -12,7 +12,7 @@ class RawConfigDict(t.TypedDict): vcs: VCSLiteral name: str - dir: StrPath + path: StrPath url: str remotes: GitSyncRemoteDict @@ -26,7 +26,7 @@ class ConfigDict(TypedDict): vcs: t.Optional[VCSLiteral] name: str - dir: pathlib.Path + path: pathlib.Path url: str remotes: NotRequired[t.Optional[GitSyncRemoteDict]] shell_command_after: NotRequired[t.Optional[list[str]]] diff --git a/tests/fixtures/example.py b/tests/fixtures/example.py index 67b96592..0066e1b7 100644 --- a/tests/fixtures/example.py +++ b/tests/fixtures/example.py @@ -41,32 +41,32 @@ { "vcs": "git", "name": "linux", - "dir": pathlib.Path("/home/me/myproject/study/linux"), + "path": pathlib.Path("/home/me/myproject/study/linux"), "url": "git+git://git.kernel.org/linux/torvalds/linux.git", }, { "vcs": "git", "name": "freebsd", - "dir": pathlib.Path("/home/me/myproject/study/freebsd"), + "path": pathlib.Path("/home/me/myproject/study/freebsd"), "url": "git+https://github.com/freebsd/freebsd.git", }, { "vcs": "git", "name": "sphinx", - "dir": pathlib.Path("/home/me/myproject/study/sphinx"), + "path": pathlib.Path("/home/me/myproject/study/sphinx"), "url": "hg+https://bitbucket.org/birkenfeld/sphinx", }, { "vcs": "git", "name": "docutils", - "dir": pathlib.Path("/home/me/myproject/study/docutils"), + "path": pathlib.Path("/home/me/myproject/study/docutils"), "url": "svn+http://svn.code.sf.net/p/docutils/code/trunk", }, { "vcs": "git", "name": "kaptan", "url": "git+git@github.com:tony/kaptan.git", - "dir": pathlib.Path("/home/me/myproject/github_projects/kaptan"), + "path": pathlib.Path("/home/me/myproject/github_projects/kaptan"), "remotes": { "upstream": GitRemote( **{ @@ -87,14 +87,14 @@ { "vcs": "git", "name": ".vim", - "dir": pathlib.Path("/home/me/myproject/.vim"), + "path": pathlib.Path("/home/me/myproject/.vim"), "url": "git+git@github.com:tony/vim-config.git", "shell_command_after": ["ln -sf /home/me/.vim/.vimrc /home/me/.vimrc"], }, { "vcs": "git", "name": ".tmux", - "dir": pathlib.Path("/home/me/myproject/.tmux"), + "path": pathlib.Path("/home/me/myproject/.tmux"), "url": "git+git@github.com:tony/tmux-config.git", "shell_command_after": ["ln -sf /home/me/.tmux/.tmux.conf /home/me/.tmux.conf"], }, diff --git a/tests/test_cli.py b/tests/test_cli.py index 1683e7aa..a6991a4c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -84,8 +84,8 @@ def test_sync_cli_filter_non_existent( config = { "~/github_projects/": { "my_git_project": { - "url": f"git+file://{git_repo.dir}", - "remotes": {"test_remote": f"git+file://{git_repo.dir}"}, + "url": f"git+file://{git_repo.path}", + "remotes": {"test_remote": f"git+file://{git_repo.path}"}, }, } } @@ -219,11 +219,11 @@ def test_sync( config = { "~/github_projects/": { "my_git_repo": { - "url": f"git+file://{git_repo.dir}", - "remotes": {"test_remote": f"git+file://{git_repo.dir}"}, + "url": f"git+file://{git_repo.path}", + "remotes": {"test_remote": f"git+file://{git_repo.path}"}, }, "broken_repo": { - "url": f"git+file://{git_repo.dir}", + "url": f"git+file://{git_repo.path}", "remotes": {"test_remote": "git+file://non-existent-remote"}, }, } @@ -360,8 +360,8 @@ def test_sync_broken( config = { "~/github_projects/": { "my_git_repo": { - "url": f"git+file://{git_repo.dir}", - "remotes": {"test_remote": f"git+file://{git_repo.dir}"}, + "url": f"git+file://{git_repo.path}", + "remotes": {"test_remote": f"git+file://{git_repo.path}"}, }, "my_git_repo_not_found": { "url": "git+file:///dev/null", diff --git a/tests/test_config.py b/tests/test_config.py index 42eea214..d3daa6d0 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -16,7 +16,7 @@ class LoadYAMLFn(t.Protocol): def __call__( self, content: str, - dir: str = "randomdir", + path: str = "randomdir", filename: str = "randomfilename.yaml", ) -> tuple[pathlib.Path, list[t.Union[t.Any, pathlib.Path]], list["ConfigDict"]]: """Callable function type signature for load_yaml pytest fixture.""" @@ -28,10 +28,10 @@ def load_yaml(tmp_path: pathlib.Path) -> LoadYAMLFn: """Return a yaml loading function that uses temporary directory path.""" def fn( - content: str, dir: str = "randomdir", filename: str = "randomfilename.yaml" + content: str, path: str = "randomdir", filename: str = "randomfilename.yaml" ) -> tuple[pathlib.Path, list[pathlib.Path], list["ConfigDict"]]: """Return vcspull configurations and write out config to temp directory.""" - _dir = tmp_path / dir + _dir = tmp_path / path _dir.mkdir() _config = _dir / filename _config.write_text(content, encoding="utf-8") @@ -45,7 +45,7 @@ def fn( def test_simple_format(load_yaml: LoadYAMLFn) -> None: """Test simple configuration YAML file for vcspull.""" - dir, _, repos = load_yaml( + path, _, repos = load_yaml( """ vcspull: libvcs: git+https://github.com/vcs-python/libvcs @@ -55,24 +55,24 @@ def test_simple_format(load_yaml: LoadYAMLFn) -> None: assert len(repos) == 1 repo = repos[0] - assert dir / "vcspull" == repo["dir"].parent - assert dir / "vcspull" / "libvcs" == repo["dir"] + assert path / "vcspull" == repo["path"].parent + assert path / "vcspull" / "libvcs" == repo["path"] def test_relative_dir(load_yaml: LoadYAMLFn) -> None: """Test configuration files for vcspull support relative directories.""" - dir, _, repos = load_yaml( + path, _, repos = load_yaml( """ ./relativedir: docutils: svn+http://svn.code.sf.net/p/docutils/code/trunk """ ) - config_files = config.find_config_files(path=dir) - repos = config.load_configs(config_files, dir) + config_files = config.find_config_files(path=path) + repos = config.load_configs(config_files, path) assert len(repos) == 1 repo = repos[0] - assert dir / "relativedir" == repo["dir"].parent - assert dir / "relativedir" / "docutils" == repo["dir"] + assert path / "relativedir" == repo["path"].parent + assert path / "relativedir" / "docutils" == repo["path"] diff --git a/tests/test_config_file.py b/tests/test_config_file.py index 2dfd631b..84ba3507 100644 --- a/tests/test_config_file.py +++ b/tests/test_config_file.py @@ -171,12 +171,12 @@ def test_expandenv_and_homevars() -> None: config1_expanded = extract_repos(config1) config2_expanded = extract_repos(config2) - paths = [r["dir"].parent for r in config1_expanded] + paths = [r["path"].parent for r in config1_expanded] assert expand_dir(pathlib.Path("${HOME}/github_projects/")) in paths assert expand_dir(pathlib.Path("~/study/")) in paths assert expand_dir(pathlib.Path("~")) in paths - paths = [r["dir"].parent for r in config2_expanded] + paths = [r["path"].parent for r in config2_expanded] assert expand_dir(pathlib.Path("${HOME}/github_projects/")) in paths assert expand_dir(pathlib.Path("~/study/")) in paths diff --git a/tests/test_repo.py b/tests/test_repo.py index 9bccce71..36107a4c 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -11,7 +11,7 @@ def test_filter_dir() -> None: """`filter_repos` filter by dir.""" - repo_list = filter_repos(fixtures.config_dict_expanded, dir="*github_project*") + repo_list = filter_repos(fixtures.config_dict_expanded, path="*github_project*") assert len(repo_list) == 1 for r in repo_list: @@ -65,7 +65,7 @@ def test_vcs_url_scheme_to_object(tmp_path: pathlib.Path) -> None: git_repo = create_project( vcs="git", url="git+git://git.myproject.org/MyProject.git@da39a3ee5e6b4b", - dir=str(tmp_path / "myproject1"), + path=str(tmp_path / "myproject1"), ) # 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: hg_repo = create_project( vcs="hg", url="hg+https://hg.myproject.org/MyProject#egg=MyProject", - dir=str(tmp_path / "myproject2"), + path=str(tmp_path / "myproject2"), ) assert isinstance(hg_repo, HgSync) @@ -85,7 +85,7 @@ def test_vcs_url_scheme_to_object(tmp_path: pathlib.Path) -> None: svn_repo = create_project( vcs="svn", url="svn+svn://svn.myproject.org/svn/MyProject#egg=MyProject", - dir=str(tmp_path / "myproject3"), + path=str(tmp_path / "myproject3"), ) assert isinstance(svn_repo, SvnSync) @@ -101,11 +101,11 @@ def test_to_repo_objects(tmp_path: pathlib.Path) -> None: assert isinstance(r, BaseSync) assert r.repo_name assert r.repo_name == repo_dict["name"] - assert r.dir.parent + assert r.path.parent assert r.url assert r.url == repo_dict["url"] - assert r.dir == r.dir / r.repo_name + assert r.path == r.path / r.repo_name if hasattr(r, "remotes") and isinstance(r, GitSync): assert isinstance(r.remotes, dict) diff --git a/tests/test_sync.py b/tests/test_sync.py index 48b9f26b..bfb50725 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -37,7 +37,7 @@ def test_makes_recursive( repos = extract_repos(config=conf) assert len(repos) > 0 - filtered_repos = filter_repos(repos, dir="*") + filtered_repos = filter_repos(repos, path="*") assert len(filtered_repos) > 0 for r in filtered_repos: @@ -45,21 +45,21 @@ def test_makes_recursive( repo = create_project(**r) # type: ignore repo.obtain() - assert repo.dir.exists() + assert repo.path.exists() def write_config_remote( config_path: pathlib.Path, tmp_path: pathlib.Path, config_tpl: str, - dir: pathlib.Path, + path: pathlib.Path, clone_name: str, ) -> pathlib.Path: """Write vcspull configuration with git remote.""" return write_config( config_path=config_path, content=config_tpl.format( - tmp_path=str(tmp_path.parent), dir=dir, CLONE_NAME=clone_name + tmp_path=str(tmp_path.parent), path=path, CLONE_NAME=clone_name ), ) @@ -80,7 +80,7 @@ class ConfigVariationTest(t.NamedTuple): test_id="default", config_tpl=""" {tmp_path}/study/myrepo: - {CLONE_NAME}: git+file://{dir} + {CLONE_NAME}: git+file://{path} """, remote_list=["origin"], ), @@ -89,7 +89,7 @@ class ConfigVariationTest(t.NamedTuple): config_tpl=""" {tmp_path}/study/myrepo: {CLONE_NAME}: - repo: git+file://{dir} + repo: git+file://{path} """, remote_list=["repo"], ), @@ -98,9 +98,9 @@ class ConfigVariationTest(t.NamedTuple): config_tpl=""" {tmp_path}/study/myrepo: {CLONE_NAME}: - repo: git+file://{dir} + repo: git+file://{path} remotes: - secondremote: git+file://{dir} + secondremote: git+file://{path} """, remote_list=["secondremote"], ), @@ -109,7 +109,7 @@ class ConfigVariationTest(t.NamedTuple): config_tpl=""" {tmp_path}/study/myrepo: {CLONE_NAME}: - repo: git+file://{dir} + repo: git+file://{path} remotes: git_scheme_repo: git@codeberg.org:tmux-python/tmuxp.git """, @@ -120,7 +120,7 @@ class ConfigVariationTest(t.NamedTuple): config_tpl=""" {tmp_path}/study/myrepo: {CLONE_NAME}: - repo: git+file://{dir} + repo: git+file://{path} remotes: git_scheme_repo: git@github.com:tony/vcspull.git """, @@ -150,13 +150,13 @@ def test_config_variations( config_path=tmp_path / "myrepos.yaml", tmp_path=tmp_path, config_tpl=config_tpl, - dir=dummy_repo, + path=dummy_repo, clone_name="myclone", ) configs = load_configs([config_file]) # TODO: Merge repos - repos = filter_repos(configs, dir="*") + repos = filter_repos(configs, path="*") assert len(repos) == 1 for repo_dict in repos: @@ -208,7 +208,7 @@ class UpdatingRemoteFixture(t.NamedTuple): test_id="no_remotes", config_tpl=""" {tmp_path}/study/myrepo: - {CLONE_NAME}: git+file://{dir} + {CLONE_NAME}: git+file://{path} """, has_extra_remotes=False, ), @@ -217,7 +217,7 @@ class UpdatingRemoteFixture(t.NamedTuple): config_tpl=""" {tmp_path}/study/myrepo: {CLONE_NAME}: - repo: git+file://{dir} + repo: git+file://{path} """, has_extra_remotes=False, ), @@ -226,9 +226,9 @@ class UpdatingRemoteFixture(t.NamedTuple): config_tpl=""" {tmp_path}/study/myrepo: {CLONE_NAME}: - repo: git+file://{dir} + repo: git+file://{path} remotes: - mirror_repo: git+file://{dir} + mirror_repo: git+file://{path} """, has_extra_remotes=True, ), @@ -260,7 +260,7 @@ def test_updating_remote( initial_config: "ConfigDict" = { "vcs": "git", "name": "myclone", - "dir": tmp_path / "study/myrepo/myclone", + "path": tmp_path / "study/myrepo/myclone", "url": f"git+file://{dummy_repo}", "remotes": { mirror_name: GitRemote(