Skip to content

Commit 6daa714

Browse files
authored
refactor!: Rename repo_dir to dir (#324)
2 parents 6c649bc + 2369a2d commit 6daa714

File tree

13 files changed

+80
-73
lines changed

13 files changed

+80
-73
lines changed

CHANGES

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ $ pip install --user --upgrade --pre libvcs
1717

1818
- `GitRepo`, `SVNRepo`, `MercurialRepo`, `BaseRepo` have been moved to
1919
`libvcs.states.{module}.{Module}Repo`
20+
- `repo_dir` param is renamed to `dir`:
21+
22+
Before: `GitRepo(url='...', repo_dir='...')`
23+
24+
After: `GitRepo(url='...', dir='...')`
25+
26+
{issue}`#324`
27+
2028
- Logging functions moved to {attr}`libvcs.states.base.BaseRepo.log` ({issue}`#322`)
2129
- Rename `RepoLoggingAdapter` to `CmdLoggingAdapter`
2230
- `CmdLoggingAdapter`: Rename `repo_name` param to `keyword`

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ to inspect / checkout / update:
3434
>>> from libvcs.shortcuts import create_repo_from_pip_url, create_repo
3535

3636
# repo is an object representation of a vcs repository.
37-
>>> r = create_repo(url='https://www.github.com/vcs-python/libtmux',
38-
... vcs='git',
39-
... repo_dir='/tmp/libtmux')
37+
>>> r = create_repo(
38+
... url='https://www.github.com/vcs-python/libtmux',
39+
... vcs='git',
40+
... dir='/tmp/libtmux'
41+
... )
4042

4143
# or via pip-style URL
4244
>>> r = create_repo_from_pip_url(
43-
... pip_url='git+https://www.github.com/vcs-python/libtmux',
44-
... repo_dir='/tmp/libtmux')
45+
... pip_url='git+https://www.github.com/vcs-python/libtmux',
46+
... dir='/tmp/libtmux'
47+
... )
4548
```
4649

4750
Update / clone repo:

libvcs/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def git_repo(projects_path: pathlib.Path, git_remote_repo: pathlib.Path):
301301
"""Pre-made git clone of remote repo checked out to user's projects dir."""
302302
git_repo = GitRepo(
303303
url=f"file://{git_remote_repo}",
304-
repo_dir=str(projects_path / "git_repo"),
304+
dir=str(projects_path / "git_repo"),
305305
remotes={
306306
"origin": GitRemoteDict(
307307
**{

libvcs/shortcuts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def create_repo(
1616
>>> r = create_repo(
1717
... url=f'file://{create_git_remote_repo()}',
1818
... vcs='git',
19-
... repo_dir=tmp_path
19+
... dir=tmp_path
2020
... )
2121
2222
>>> isinstance(r, GitRepo)
@@ -43,7 +43,7 @@ def create_repo_from_pip_url(
4343
>>> from libvcs.shortcuts import create_repo_from_pip_url
4444
>>> r = create_repo_from_pip_url(
4545
... pip_url=f'git+{create_git_remote_repo()}',
46-
... repo_dir=tmp_path
46+
... dir=tmp_path
4747
... )
4848
>>> isinstance(r, GitRepo)
4949
True

libvcs/states/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BaseRepo:
4040
#: vcs app name, e.g. 'git'
4141
bin_name = ""
4242

43-
def __init__(self, url, repo_dir, progress_callback=None, *args, **kwargs):
43+
def __init__(self, url, dir, progress_callback=None, *args, **kwargs):
4444
r"""
4545
Parameters
4646
----------
@@ -63,7 +63,7 @@ def __init__(self, url, repo_dir, progress_callback=None, *args, **kwargs):
6363
... )
6464
>>> r = Repo(
6565
... url=f'file://{create_git_remote_repo()}',
66-
... repo_dir=str(tmp_path),
66+
... dir=str(tmp_path),
6767
... progress_callback=progress_cb
6868
... )
6969
>>> r.obtain() # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS +REPORT_CDIFF
@@ -81,13 +81,13 @@ def __init__(self, url, repo_dir, progress_callback=None, *args, **kwargs):
8181
self.progress_callback = progress_callback
8282

8383
#: Parent directory
84-
self.parent_dir = os.path.dirname(repo_dir)
84+
self.parent_dir = os.path.dirname(dir)
8585

8686
#: Checkout path
87-
self.path = repo_dir
87+
self.path = dir
8888

8989
#: Base name of checkout
90-
self.repo_name = os.path.basename(os.path.normpath(repo_dir))
90+
self.repo_name = os.path.basename(os.path.normpath(dir))
9191

9292
if "rev" in kwargs:
9393
self.rev = kwargs["rev"]

libvcs/states/git.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class GitRepo(BaseRepo):
140140
schemes = ("git", "git+http", "git+https", "git+ssh", "git+git", "git+file")
141141

142142
def __init__(
143-
self, url: str, repo_dir: str, remotes: GitRemotesArgs = None, *args, **kwargs
143+
self, url: str, dir: str, remotes: GitRemotesArgs = None, *args, **kwargs
144144
):
145145
"""A git repository.
146146
@@ -164,7 +164,7 @@ def __init__(
164164
165165
repo = GitRepo(
166166
url="https://github.com/vcs-python/libvcs",
167-
repo_dir=checkout,
167+
dir=checkout,
168168
remotes={
169169
'gitlab': 'https://gitlab.com/vcs-python/libvcs'
170170
}
@@ -179,7 +179,7 @@ def __init__(
179179
180180
repo = GitRepo(
181181
url="https://github.com/vcs-python/libvcs",
182-
repo_dir=checkout,
182+
dir=checkout,
183183
remotes={
184184
'gitlab': {
185185
'fetch_url': 'https://gitlab.com/vcs-python/libvcs',
@@ -221,7 +221,7 @@ def __init__(
221221
fetch_url=url,
222222
push_url=url,
223223
)
224-
BaseRepo.__init__(self, url, repo_dir, *args, **kwargs)
224+
BaseRepo.__init__(self, url, dir, *args, **kwargs)
225225
self.url = self.chomp_protocol(
226226
(
227227
self._remotes.get("origin")
@@ -592,7 +592,7 @@ def status(self) -> dict:
592592
--------
593593
>>> git_repo = GitRepo(
594594
... url=f'file://{create_git_remote_repo()}',
595-
... repo_dir=tmp_path
595+
... dir=tmp_path
596596
... )
597597
>>> git_repo.obtain()
598598
>>> git_repo.status()

libvcs/states/hg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class MercurialRepo(BaseRepo):
2020
bin_name = "hg"
2121
schemes = ("hg", "hg+http", "hg+https", "hg+file")
2222

23-
def __init__(self, url, repo_dir, *args, **kwargs):
24-
BaseRepo.__init__(self, url, repo_dir, *args, **kwargs)
23+
def __init__(self, url, dir, *args, **kwargs):
24+
BaseRepo.__init__(self, url, dir, *args, **kwargs)
2525

2626
def obtain(self, *args, **kwargs):
2727
self.ensure_dir()

libvcs/states/svn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class SubversionRepo(BaseRepo):
3434
bin_name = "svn"
3535
schemes = ("svn", "svn+ssh", "svn+http", "svn+https", "svn+svn")
3636

37-
def __init__(self, url, repo_dir, *args, **kwargs):
37+
def __init__(self, url, dir, *args, **kwargs):
3838
"""A svn repository.
3939
4040
Parameters
@@ -55,7 +55,7 @@ def __init__(self, url, repo_dir, *args, **kwargs):
5555
self.svn_trust_cert = False
5656

5757
self.rev = kwargs.get("rev")
58-
BaseRepo.__init__(self, url, repo_dir, *args, **kwargs)
58+
BaseRepo.__init__(self, url, dir, *args, **kwargs)
5959

6060
def _user_pw_args(self):
6161
args = []

tests/states/test_base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def test_repr():
12-
repo = create_repo(url="file://path/to/myrepo", repo_dir="/hello/", vcs="git")
12+
repo = create_repo(url="file://path/to/myrepo", dir="/hello/", vcs="git")
1313

1414
str_repo = str(repo)
1515
assert "GitRepo" in str_repo
@@ -18,7 +18,7 @@ def test_repr():
1818

1919

2020
def test_repr_base():
21-
repo = BaseRepo(url="file://path/to/myrepo", repo_dir="/hello/")
21+
repo = BaseRepo(url="file://path/to/myrepo", dir="/hello/")
2222

2323
str_repo = str(repo)
2424
assert "Repo" in str_repo
@@ -28,8 +28,8 @@ def test_repr_base():
2828

2929
def test_ensure_dir_creates_parent_if_not_exist(tmp_path: pathlib.Path):
3030
projects_path = tmp_path / "projects_path" # doesn't exist yet
31-
repo_dir = projects_path / "myrepo"
32-
repo = BaseRepo(url="file://path/to/myrepo", repo_dir=repo_dir)
31+
dir = projects_path / "myrepo"
32+
repo = BaseRepo(url="file://path/to/myrepo", dir=dir)
3333

3434
repo.ensure_dir()
3535
assert projects_path.is_dir()
@@ -62,7 +62,7 @@ def obtain(self, *args, **kwargs):
6262

6363
r = Repo(
6464
url=f"file://{str(git_remote_repo)}",
65-
repo_dir=str(tmp_path),
65+
dir=str(tmp_path),
6666
progress_callback=progress_cb,
6767
)
6868
r.obtain()

0 commit comments

Comments
 (0)