Skip to content

refactor!: Rename repo_dir to dir #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ $ pip install --user --upgrade --pre libvcs

- `GitRepo`, `SVNRepo`, `MercurialRepo`, `BaseRepo` have been moved to
`libvcs.states.{module}.{Module}Repo`
- `repo_dir` param is renamed to `dir`:

Before: `GitRepo(url='...', repo_dir='...')`

After: `GitRepo(url='...', dir='...')`

{issue}`#324`

- Logging functions moved to {attr}`libvcs.states.base.BaseRepo.log` ({issue}`#322`)
- Rename `RepoLoggingAdapter` to `CmdLoggingAdapter`
- `CmdLoggingAdapter`: Rename `repo_name` param to `keyword`
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ to inspect / checkout / update:
>>> from libvcs.shortcuts import create_repo_from_pip_url, create_repo

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

# or via pip-style URL
>>> r = create_repo_from_pip_url(
... pip_url='git+https://www.github.com/vcs-python/libtmux',
... repo_dir='/tmp/libtmux')
... pip_url='git+https://www.github.com/vcs-python/libtmux',
... dir='/tmp/libtmux'
... )
```

Update / clone repo:
Expand Down
2 changes: 1 addition & 1 deletion libvcs/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def git_repo(projects_path: pathlib.Path, git_remote_repo: pathlib.Path):
"""Pre-made git clone of remote repo checked out to user's projects dir."""
git_repo = GitRepo(
url=f"file://{git_remote_repo}",
repo_dir=str(projects_path / "git_repo"),
dir=str(projects_path / "git_repo"),
remotes={
"origin": GitRemoteDict(
**{
Expand Down
4 changes: 2 additions & 2 deletions libvcs/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create_repo(
>>> r = create_repo(
... url=f'file://{create_git_remote_repo()}',
... vcs='git',
... repo_dir=tmp_path
... dir=tmp_path
... )

>>> isinstance(r, GitRepo)
Expand All @@ -43,7 +43,7 @@ def create_repo_from_pip_url(
>>> from libvcs.shortcuts import create_repo_from_pip_url
>>> r = create_repo_from_pip_url(
... pip_url=f'git+{create_git_remote_repo()}',
... repo_dir=tmp_path
... dir=tmp_path
... )
>>> isinstance(r, GitRepo)
True
Expand Down
10 changes: 5 additions & 5 deletions libvcs/states/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BaseRepo:
#: vcs app name, e.g. 'git'
bin_name = ""

def __init__(self, url, repo_dir, progress_callback=None, *args, **kwargs):
def __init__(self, url, dir, progress_callback=None, *args, **kwargs):
r"""
Parameters
----------
Expand All @@ -63,7 +63,7 @@ def __init__(self, url, repo_dir, progress_callback=None, *args, **kwargs):
... )
>>> r = Repo(
... url=f'file://{create_git_remote_repo()}',
... repo_dir=str(tmp_path),
... dir=str(tmp_path),
... progress_callback=progress_cb
... )
>>> r.obtain() # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS +REPORT_CDIFF
Expand All @@ -81,13 +81,13 @@ def __init__(self, url, repo_dir, progress_callback=None, *args, **kwargs):
self.progress_callback = progress_callback

#: Parent directory
self.parent_dir = os.path.dirname(repo_dir)
self.parent_dir = os.path.dirname(dir)

#: Checkout path
self.path = repo_dir
self.path = dir

#: Base name of checkout
self.repo_name = os.path.basename(os.path.normpath(repo_dir))
self.repo_name = os.path.basename(os.path.normpath(dir))

if "rev" in kwargs:
self.rev = kwargs["rev"]
Expand Down
10 changes: 5 additions & 5 deletions libvcs/states/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class GitRepo(BaseRepo):
schemes = ("git", "git+http", "git+https", "git+ssh", "git+git", "git+file")

def __init__(
self, url: str, repo_dir: str, remotes: GitRemotesArgs = None, *args, **kwargs
self, url: str, dir: str, remotes: GitRemotesArgs = None, *args, **kwargs
):
"""A git repository.

Expand All @@ -164,7 +164,7 @@ def __init__(

repo = GitRepo(
url="https://github.com/vcs-python/libvcs",
repo_dir=checkout,
dir=checkout,
remotes={
'gitlab': 'https://gitlab.com/vcs-python/libvcs'
}
Expand All @@ -179,7 +179,7 @@ def __init__(

repo = GitRepo(
url="https://github.com/vcs-python/libvcs",
repo_dir=checkout,
dir=checkout,
remotes={
'gitlab': {
'fetch_url': 'https://gitlab.com/vcs-python/libvcs',
Expand Down Expand Up @@ -221,7 +221,7 @@ def __init__(
fetch_url=url,
push_url=url,
)
BaseRepo.__init__(self, url, repo_dir, *args, **kwargs)
BaseRepo.__init__(self, url, dir, *args, **kwargs)
self.url = self.chomp_protocol(
(
self._remotes.get("origin")
Expand Down Expand Up @@ -592,7 +592,7 @@ def status(self) -> dict:
--------
>>> git_repo = GitRepo(
... url=f'file://{create_git_remote_repo()}',
... repo_dir=tmp_path
... dir=tmp_path
... )
>>> git_repo.obtain()
>>> git_repo.status()
Expand Down
4 changes: 2 additions & 2 deletions libvcs/states/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class MercurialRepo(BaseRepo):
bin_name = "hg"
schemes = ("hg", "hg+http", "hg+https", "hg+file")

def __init__(self, url, repo_dir, *args, **kwargs):
BaseRepo.__init__(self, url, repo_dir, *args, **kwargs)
def __init__(self, url, dir, *args, **kwargs):
BaseRepo.__init__(self, url, dir, *args, **kwargs)

def obtain(self, *args, **kwargs):
self.ensure_dir()
Expand Down
4 changes: 2 additions & 2 deletions libvcs/states/svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SubversionRepo(BaseRepo):
bin_name = "svn"
schemes = ("svn", "svn+ssh", "svn+http", "svn+https", "svn+svn")

def __init__(self, url, repo_dir, *args, **kwargs):
def __init__(self, url, dir, *args, **kwargs):
"""A svn repository.

Parameters
Expand All @@ -55,7 +55,7 @@ def __init__(self, url, repo_dir, *args, **kwargs):
self.svn_trust_cert = False

self.rev = kwargs.get("rev")
BaseRepo.__init__(self, url, repo_dir, *args, **kwargs)
BaseRepo.__init__(self, url, dir, *args, **kwargs)

def _user_pw_args(self):
args = []
Expand Down
10 changes: 5 additions & 5 deletions tests/states/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


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

str_repo = str(repo)
assert "GitRepo" in str_repo
Expand All @@ -18,7 +18,7 @@ def test_repr():


def test_repr_base():
repo = BaseRepo(url="file://path/to/myrepo", repo_dir="/hello/")
repo = BaseRepo(url="file://path/to/myrepo", dir="/hello/")

str_repo = str(repo)
assert "Repo" in str_repo
Expand All @@ -28,8 +28,8 @@ def test_repr_base():

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

repo.ensure_dir()
assert projects_path.is_dir()
Expand Down Expand Up @@ -62,7 +62,7 @@ def obtain(self, *args, **kwargs):

r = Repo(
url=f"file://{str(git_remote_repo)}",
repo_dir=str(tmp_path),
dir=str(tmp_path),
progress_callback=progress_cb,
)
r.obtain()
Expand Down
Loading