Skip to content

Commit

Permalink
refactor!(projects): Make arguments kw-only
Browse files Browse the repository at this point in the history
To make passing as a configuration file (#315 and
vcs-python/vcspull#362) easier, deprecate
positional arguments.

See also:
- PEP 570: https://peps.python.org/pep-0570/
- https://peps.python.org/pep-0570/#:~:text=def%20kwd_only_arg*%2C%20arg)(%3A)
  • Loading branch information
tony committed May 29, 2022
1 parent 2ecdc84 commit 0c32240
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
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

0 comments on commit 0c32240

Please sign in to comment.