Skip to content

Commit 0c32240

Browse files
committed
refactor!(projects): Make arguments kw-only
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)
1 parent 2ecdc84 commit 0c32240

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

libvcs/projects/base.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from typing import NamedTuple
55
from urllib import parse as urlparse
66

7-
from libvcs.types import StrPath
87
from libvcs._internal.run import CmdLoggingAdapter, mkdir_p, run
8+
from libvcs.types import StrPath
99

1010
logger = logging.getLogger(__name__)
1111

@@ -41,7 +41,7 @@ class BaseProject:
4141
#: vcs app name, e.g. 'git'
4242
bin_name = ""
4343

44-
def __init__(self, url, dir: StrPath, progress_callback=None, *args, **kwargs):
44+
def __init__(self, *, url: str, dir: StrPath, progress_callback=None, **kwargs):
4545
r"""
4646
Parameters
4747
----------
@@ -111,9 +111,9 @@ def __init__(self, url, dir: StrPath, progress_callback=None, *args, **kwargs):
111111
)
112112

113113
@classmethod
114-
def from_pip_url(cls, pip_url, *args, **kwargs):
114+
def from_pip_url(cls, pip_url, **kwargs):
115115
url, rev = convert_pip_url(pip_url)
116-
self = cls(url=url, rev=rev, *args, **kwargs)
116+
self = cls(url=url, rev=rev, **kwargs)
117117

118118
return self
119119

libvcs/projects/git.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from typing import Dict, Optional, TypedDict, Union
2222
from urllib import parse as urlparse
2323

24+
from libvcs.types import StrPath
25+
2426
from .. import exc
2527
from .base import BaseProject, VCSLocation, convert_pip_url as base_convert_pip_url
2628

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

156158
def __init__(
157-
self, url: str, dir: str, remotes: GitRemotesArgs = None, *args, **kwargs
159+
self, *, url: str, dir: StrPath, remotes: GitRemotesArgs = None, **kwargs
158160
):
159161
"""A git repository.
160162
@@ -235,7 +237,7 @@ def __init__(
235237
fetch_url=url,
236238
push_url=url,
237239
)
238-
super().__init__(url, dir, *args, **kwargs)
240+
super().__init__(url=url, dir=dir, **kwargs)
239241
self.url = self.chomp_protocol(
240242
(
241243
self._remotes.get("origin")
@@ -245,9 +247,9 @@ def __init__(
245247
)
246248

247249
@classmethod
248-
def from_pip_url(cls, pip_url, *args, **kwargs):
250+
def from_pip_url(cls, pip_url, **kwargs):
249251
url, rev = convert_pip_url(pip_url)
250-
self = cls(url=url, rev=rev, *args, **kwargs)
252+
self = cls(url=url, rev=rev, **kwargs)
251253

252254
return self
253255

libvcs/projects/svn.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import re
2121
from urllib import parse as urlparse
2222

23+
from libvcs.types import StrPath
24+
2325
from .base import BaseProject, VCSLocation, convert_pip_url as base_convert_pip_url
2426

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

40-
def __init__(self, url, dir, *args, **kwargs):
42+
def __init__(self, *, url: str, dir: StrPath, **kwargs):
4143
"""A svn repository.
4244
4345
Parameters
@@ -58,7 +60,7 @@ def __init__(self, url, dir, *args, **kwargs):
5860
self.svn_trust_cert = False
5961

6062
self.rev = kwargs.get("rev")
61-
super().__init__(url, dir, *args, **kwargs)
63+
super().__init__(url=url, dir=dir, **kwargs)
6264

6365
def _user_pw_args(self):
6466
args = []

libvcs/shortcuts.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ def create_project(
2323
True
2424
"""
2525
if vcs == "git":
26-
return GitProject(url, progress_callback=progress_callback, *args, **kwargs)
26+
return GitProject(url=url, progress_callback=progress_callback, *args, **kwargs)
2727
elif vcs == "hg":
2828
return MercurialProject(
29-
url, progress_callback=progress_callback, *args, **kwargs
29+
url=url, progress_callback=progress_callback, *args, **kwargs
3030
)
3131
elif vcs == "svn":
3232
return SubversionProject(
33-
url, progress_callback=progress_callback, *args, **kwargs
33+
url=url, progress_callback=progress_callback, *args, **kwargs
3434
)
3535
else:
3636
raise InvalidVCS("VCS %s is not a valid VCS" % vcs)

0 commit comments

Comments
 (0)