Skip to content

Commit 7cdeb17

Browse files
authored
refactor!(projects): Make arguments kw-only (#364)
This will be instrumental in making `dict` options from vcspull directly able to pass-through into projects.
2 parents 2ecdc84 + 57e03f1 commit 7cdeb17

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

CHANGES

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ $ pip install --user --upgrade --pre libvcs
2222

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

25+
- {issue}`364`: Project classes no longer accept positional arguments. Per [PEP 570].
26+
27+
Deprecated in >=0.13:
28+
29+
```python
30+
GitProject('https://github.com/vcs-python/libvcs.git')
31+
```
32+
33+
New style in >=0.13:
34+
35+
```python
36+
GitProject(url='https://github.com/vcs-python/libvcs.git')
37+
```
38+
39+
[pep 570]: https://peps.python.org/pep-0570/
40+
2541
### What's new
2642

2743
- **Commands**: Experimental command wrappers added ({issue}`346`):

libvcs/projects/base.py

Lines changed: 4 additions & 4 deletions
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

Lines changed: 6 additions & 4 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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)