Skip to content

Commit 7315799

Browse files
committed
refactor!(url): MATCHERS -> RULES
1 parent 8287b4b commit 7315799

File tree

7 files changed

+22
-22
lines changed

7 files changed

+22
-22
lines changed

src/libvcs/url/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,18 @@ def register(self, cls: Rule) -> None:
173173
174174
**Example: git URLs + pip-style git URLs:**
175175
176-
This is already in :class:`GitURL` via :data:`PIP_DEFAULT_MATCHERS`. For the
176+
This is already in :class:`GitURL` via :data:`PIP_DEFAULT_RULES`. For the
177177
sake of showing how extensibility works, here is a recreation based on
178178
:class:`GitBaseURL`:
179179
180180
>>> from libvcs.url.git import GitBaseURL
181181
182-
>>> from libvcs.url.git import DEFAULT_MATCHERS, PIP_DEFAULT_MATCHERS
182+
>>> from libvcs.url.git import DEFAULT_RULES, PIP_DEFAULT_RULES
183183
184184
>>> @dataclasses.dataclass(repr=False)
185185
... class GitURLWithPip(GitBaseURL):
186186
... rule_map: RuleMap = RuleMap(
187-
... _rule_map={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
187+
... _rule_map={m.label: m for m in [*DEFAULT_RULES, *PIP_DEFAULT_RULES]}
188188
... )
189189
190190
>>> GitURLWithPip.is_valid(url="git+ssh://[email protected]/tony/AlgoXY.git")

src/libvcs/url/git.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
# Some https repos have .git at the end, e.g. https://github.com/org/repo.git
6161

6262

63-
DEFAULT_MATCHERS: list[Rule] = [
63+
DEFAULT_RULES: list[Rule] = [
6464
Rule(
6565
label="core-git-https",
6666
description="Vanilla git pattern, URL ending with optional .git suffix",
@@ -125,7 +125,7 @@
125125
"""
126126

127127

128-
PIP_DEFAULT_MATCHERS: list[Rule] = [
128+
PIP_DEFAULT_RULES: list[Rule] = [
129129
Rule(
130130
label="pip-url",
131131
description="pip-style git URL",
@@ -191,7 +191,7 @@
191191
- https://pip.pypa.io/en/stable/topics/vcs-support/
192192
""" # NOQA: E501
193193

194-
NPM_DEFAULT_MATCHERS: list[Rule] = []
194+
NPM_DEFAULT_RULES: list[Rule] = []
195195
"""NPM-style git URLs.
196196
197197
Git URL pattern (from docs.npmjs.com)::
@@ -262,7 +262,7 @@ class GitBaseURL(URLProtocol, SkipDefaultFieldsReprMixin):
262262
suffix: Optional[str] = None
263263

264264
rule: Optional[str] = None
265-
rule_map: RuleMap = RuleMap(_rule_map={m.label: m for m in DEFAULT_MATCHERS})
265+
rule_map: RuleMap = RuleMap(_rule_map={m.label: m for m in DEFAULT_RULES})
266266

267267
def __post_init__(self) -> None:
268268
url = self.url
@@ -370,7 +370,7 @@ class GitPipURL(GitBaseURL, URLProtocol, SkipDefaultFieldsReprMixin):
370370
# commit-ish (rev): tag, branch, ref
371371
rev: Optional[str] = None
372372

373-
rule_map: RuleMap = RuleMap(_rule_map={m.label: m for m in PIP_DEFAULT_MATCHERS})
373+
rule_map: RuleMap = RuleMap(_rule_map={m.label: m for m in PIP_DEFAULT_RULES})
374374

375375
def to_url(self) -> str:
376376
"""Exports a pip-compliant URL.
@@ -479,7 +479,7 @@ class GitURL(GitPipURL, GitBaseURL, URLProtocol, SkipDefaultFieldsReprMixin):
479479
"""
480480

481481
rule_map: RuleMap = RuleMap(
482-
_rule_map={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
482+
_rule_map={m.label: m for m in [*DEFAULT_RULES, *PIP_DEFAULT_RULES]}
483483
)
484484

485485
@classmethod

src/libvcs/url/hg.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
)
4444
"""
4545

46-
DEFAULT_MATCHERS: list[Rule] = [
46+
DEFAULT_RULES: list[Rule] = [
4747
Rule(
4848
label="core-hg",
4949
description="Vanilla hg pattern",
@@ -74,7 +74,7 @@
7474
)
7575
"""
7676

77-
PIP_DEFAULT_MATCHERS: list[Rule] = [
77+
PIP_DEFAULT_RULES: list[Rule] = [
7878
Rule(
7979
label="pip-url",
8080
description="pip-style hg URL",
@@ -176,7 +176,7 @@ class HgURL(URLProtocol, SkipDefaultFieldsReprMixin):
176176

177177
rule: Optional[str] = None
178178
# name of the :class:`Rule`
179-
rule_map: RuleMap = RuleMap(_rule_map={m.label: m for m in DEFAULT_MATCHERS})
179+
rule_map: RuleMap = RuleMap(_rule_map={m.label: m for m in DEFAULT_RULES})
180180

181181
def __post_init__(self) -> None:
182182
url = self.url

src/libvcs/url/svn.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
)
4848
"""
4949

50-
DEFAULT_MATCHERS: list[Rule] = [
50+
DEFAULT_RULES: list[Rule] = [
5151
Rule(
5252
label="core-svn",
5353
description="Vanilla svn pattern",
@@ -78,7 +78,7 @@
7878
)
7979
"""
8080

81-
PIP_DEFAULT_MATCHERS: list[Rule] = [
81+
PIP_DEFAULT_RULES: list[Rule] = [
8282
Rule(
8383
label="pip-url",
8484
description="pip-style svn URL",
@@ -170,7 +170,7 @@ class SvnURL(URLProtocol, SkipDefaultFieldsReprMixin):
170170
ref: Optional[str] = None
171171

172172
rule: Optional[str] = None
173-
rule_map: RuleMap = RuleMap(_rule_map={m.label: m for m in DEFAULT_MATCHERS})
173+
rule_map: RuleMap = RuleMap(_rule_map={m.label: m for m in DEFAULT_RULES})
174174

175175
def __post_init__(self) -> None:
176176
url = self.url

tests/url/test_git.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from libvcs.sync.git import GitSync
66
from libvcs.url.base import RuleMap
7-
from libvcs.url.git import DEFAULT_MATCHERS, PIP_DEFAULT_MATCHERS, GitBaseURL, GitURL
7+
from libvcs.url.git import DEFAULT_RULES, PIP_DEFAULT_RULES, GitBaseURL, GitURL
88

99

1010
class GitURLFixture(typing.NamedTuple):
@@ -143,7 +143,7 @@ def test_git_url_extension_pip(
143143
) -> None:
144144
class GitURLWithPip(GitBaseURL):
145145
rule_map: RuleMap = RuleMap(
146-
_rule_map={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
146+
_rule_map={m.label: m for m in [*DEFAULT_RULES, *PIP_DEFAULT_RULES]}
147147
)
148148

149149
git_url_kwargs["url"] = git_url_kwargs["url"].format(local_repo=git_repo.dir)
@@ -256,7 +256,7 @@ def test_git_revs(
256256
) -> None:
257257
class GitURLWithPip(GitURL):
258258
rule_map: RuleMap = RuleMap(
259-
_rule_map={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
259+
_rule_map={m.label: m for m in [*DEFAULT_RULES, *PIP_DEFAULT_RULES]}
260260
)
261261

262262
git_url = GitURLWithPip(**git_url_kwargs)

tests/url/test_hg.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from libvcs.sync.hg import HgSync
66
from libvcs.url.base import RuleMap
7-
from libvcs.url.hg import DEFAULT_MATCHERS, PIP_DEFAULT_MATCHERS, HgURL
7+
from libvcs.url.hg import DEFAULT_RULES, PIP_DEFAULT_RULES, HgURL
88

99

1010
class HgURLFixture(typing.NamedTuple):
@@ -108,7 +108,7 @@ def test_hg_url_extension_pip(
108108
) -> None:
109109
class HgURLWithPip(HgURL):
110110
rule_map: RuleMap = RuleMap(
111-
_rule_map={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
111+
_rule_map={m.label: m for m in [*DEFAULT_RULES, *PIP_DEFAULT_RULES]}
112112
)
113113

114114
hg_url_kwargs["url"] = hg_url_kwargs["url"].format(local_repo=hg_repo.dir)

tests/url/test_svn.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from libvcs.sync.svn import SvnSync
66
from libvcs.url.base import RuleMap
7-
from libvcs.url.svn import DEFAULT_MATCHERS, PIP_DEFAULT_MATCHERS, SvnURL
7+
from libvcs.url.svn import DEFAULT_RULES, PIP_DEFAULT_RULES, SvnURL
88

99

1010
class SvnURLFixture(typing.NamedTuple):
@@ -125,7 +125,7 @@ def test_svn_url_extension_pip(
125125
) -> None:
126126
class SvnURLWithPip(SvnURL):
127127
rule_map: RuleMap = RuleMap(
128-
_rule_map={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
128+
_rule_map={m.label: m for m in [*DEFAULT_RULES, *PIP_DEFAULT_RULES]}
129129
)
130130

131131
svn_url_kwargs["url"] = svn_url_kwargs["url"].format(local_repo=svn_repo.dir)

0 commit comments

Comments
 (0)