Skip to content
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

refactor!(projects): Make arguments kw-only #364

Merged
merged 2 commits into from
May 29, 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
16 changes: 16 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ $ pip install --user --upgrade --pre libvcs

- `run(cmd, ...)` is now `run(args, ...)` to match `Popen`'s convention.

- {issue}`364`: Project classes no longer accept positional arguments. Per [PEP 570].

Deprecated in >=0.13:

```python
GitProject('https://github.com/vcs-python/libvcs.git')
```

New style in >=0.13:

```python
GitProject(url='https://github.com/vcs-python/libvcs.git')
```

[pep 570]: https://peps.python.org/pep-0570/

### What's new

- **Commands**: Experimental command wrappers added ({issue}`346`):
Expand Down
8 changes: 4 additions & 4 deletions libvcs/projects/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import NamedTuple
from urllib import parse as urlparse

from libvcs.types import StrPath
from libvcs._internal.run import CmdLoggingAdapter, mkdir_p, run
from libvcs.types import StrPath

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -41,7 +41,7 @@ class BaseProject:
#: vcs app name, e.g. 'git'
bin_name = ""

def __init__(self, url, dir: StrPath, progress_callback=None, *args, **kwargs):
def __init__(self, *, url: str, dir: StrPath, progress_callback=None, **kwargs):
r"""
Parameters
----------
Expand Down Expand Up @@ -111,9 +111,9 @@ def __init__(self, url, dir: StrPath, progress_callback=None, *args, **kwargs):
)

@classmethod
def from_pip_url(cls, pip_url, *args, **kwargs):
def from_pip_url(cls, pip_url, **kwargs):
url, rev = convert_pip_url(pip_url)
self = cls(url=url, rev=rev, *args, **kwargs)
self = cls(url=url, rev=rev, **kwargs)

return self

Expand Down
10 changes: 6 additions & 4 deletions libvcs/projects/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from typing import Dict, Optional, TypedDict, Union
from urllib import parse as urlparse

from libvcs.types import StrPath

from .. import exc
from .base import BaseProject, VCSLocation, convert_pip_url as base_convert_pip_url

Expand Down Expand Up @@ -154,7 +156,7 @@ class GitProject(BaseProject):
schemes = ("git", "git+http", "git+https", "git+ssh", "git+git", "git+file")

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

Expand Down Expand Up @@ -235,7 +237,7 @@ def __init__(
fetch_url=url,
push_url=url,
)
super().__init__(url, dir, *args, **kwargs)
super().__init__(url=url, dir=dir, **kwargs)
self.url = self.chomp_protocol(
(
self._remotes.get("origin")
Expand All @@ -245,9 +247,9 @@ def __init__(
)

@classmethod
def from_pip_url(cls, pip_url, *args, **kwargs):
def from_pip_url(cls, pip_url, **kwargs):
url, rev = convert_pip_url(pip_url)
self = cls(url=url, rev=rev, *args, **kwargs)
self = cls(url=url, rev=rev, **kwargs)

return self

Expand Down
6 changes: 4 additions & 2 deletions libvcs/projects/svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import re
from urllib import parse as urlparse

from libvcs.types import StrPath

from .base import BaseProject, VCSLocation, convert_pip_url as base_convert_pip_url

logger = logging.getLogger(__name__)
Expand All @@ -37,7 +39,7 @@ class SubversionProject(BaseProject):
bin_name = "svn"
schemes = ("svn", "svn+ssh", "svn+http", "svn+https", "svn+svn")

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

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

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

def _user_pw_args(self):
args = []
Expand Down
6 changes: 3 additions & 3 deletions libvcs/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def create_project(
True
"""
if vcs == "git":
return GitProject(url, progress_callback=progress_callback, *args, **kwargs)
return GitProject(url=url, progress_callback=progress_callback, *args, **kwargs)
elif vcs == "hg":
return MercurialProject(
url, progress_callback=progress_callback, *args, **kwargs
url=url, progress_callback=progress_callback, *args, **kwargs
)
elif vcs == "svn":
return SubversionProject(
url, progress_callback=progress_callback, *args, **kwargs
url=url, progress_callback=progress_callback, *args, **kwargs
)
else:
raise InvalidVCS("VCS %s is not a valid VCS" % vcs)
Expand Down