Skip to content

Commit 3d67cb7

Browse files
committed
feat(parser,is_valid): Optionally check for is_explicit
1 parent 0e49f14 commit 3d67cb7

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

libvcs/parse/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dataclasses
2-
from typing import Iterator, Pattern, Protocol
2+
from typing import Iterator, Optional, Pattern, Protocol
33

44
from libvcs._internal.dataclasses import SkipDefaultFieldsReprMixin
55

@@ -13,7 +13,7 @@ def __init__(self, url: str):
1313
def to_url(self) -> str:
1414
...
1515

16-
def is_valid(self, url: str) -> bool:
16+
def is_valid(self, url: str, is_explicit: Optional[bool] = None) -> bool:
1717
...
1818

1919

libvcs/parse/git.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def __post_init__(self):
278278
setattr(self, k, v)
279279

280280
@classmethod
281-
def is_valid(cls, url: str) -> bool:
281+
def is_valid(cls, url: str, is_explicit: Optional[bool] = None) -> bool:
282282
"""Whether URL is compatible with VCS or not.
283283
284284
Examples
@@ -293,6 +293,12 @@ def is_valid(cls, url: str) -> bool:
293293
>>> GitURL.is_valid(url='notaurl')
294294
False
295295
"""
296+
if is_explicit is not None:
297+
return any(
298+
re.search(matcher.pattern, url)
299+
for matcher in cls.matchers.values()
300+
if matcher.is_explicit == is_explicit
301+
)
296302
return any(re.search(matcher.pattern, url) for matcher in cls.matchers.values())
297303

298304
def to_url(self) -> str:

libvcs/parse/hg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def __post_init__(self):
195195
setattr(self, k, v)
196196

197197
@classmethod
198-
def is_valid(cls, url: str) -> bool:
198+
def is_valid(cls, url: str, is_explicit: Optional[bool] = False) -> bool:
199199
"""Whether URL is compatible with VCS or not.
200200
201201
Examples

libvcs/parse/svn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __post_init__(self):
189189
setattr(self, k, v)
190190

191191
@classmethod
192-
def is_valid(cls, url: str) -> bool:
192+
def is_valid(cls, url: str, is_explicit: Optional[bool] = False) -> bool:
193193
"""Whether URL is compatible with VCS or not.
194194
195195
Examples

0 commit comments

Comments
 (0)