Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ce1b04e

Browse filesBrowse files
committed
refactor(url): Matcher -> Rule, MatcherRegistry -> Rules
1 parent 5834604 commit ce1b04e
Copy full SHA for ce1b04e

File tree

Expand file treeCollapse file tree

8 files changed

+127
-135
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+127
-135
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ GitURL(url=git@github.com:vcs-python/libvcs.git,
4646
hostname=github.com,
4747
path=vcs-python/libvcs,
4848
suffix=.git,
49-
matcher=core-git-scp)
49+
rule=core-git-scp)
5050
```
5151

5252
Switch repo libvcs -> vcspull:

‎src/libvcs/url/base.py

Copy file name to clipboardExpand all lines: src/libvcs/url/base.py
+28-28Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def is_valid(self, url: str, is_explicit: Optional[bool] = None) -> bool:
2323

2424

2525
@dataclasses.dataclass(repr=False)
26-
class Matcher(SkipDefaultFieldsReprMixin):
27-
"""Structure for a matcher"""
26+
class Rule(SkipDefaultFieldsReprMixin):
27+
"""Structure for a rule"""
2828

2929
label: str
3030
"""Computer readable name / ID"""
@@ -38,12 +38,12 @@ class Matcher(SkipDefaultFieldsReprMixin):
3838

3939

4040
@dataclasses.dataclass(repr=False)
41-
class MatcherRegistry(SkipDefaultFieldsReprMixin):
41+
class Rules(SkipDefaultFieldsReprMixin):
4242
"""Pattern matching and parsing capabilities for URL parsers, e.g. GitURL"""
4343

44-
_matchers: dict[str, Matcher] = dataclasses.field(default_factory=dict)
44+
_rules: dict[str, Rule] = dataclasses.field(default_factory=dict)
4545

46-
def register(self, cls: Matcher) -> None:
46+
def register(self, cls: Rule) -> None:
4747
r"""
4848
4949
.. currentmodule:: libvcs.url.git
@@ -72,7 +72,7 @@ def register(self, cls: Matcher) -> None:
7272
GitURL(url=github:org/repo,
7373
hostname=github,
7474
path=org/repo,
75-
matcher=core-git-scp)
75+
rule=core-git-scp)
7676
7777
>>> GitURL(url="github:org/repo").to_url()
7878
'git@github:org/repo'
@@ -84,7 +84,7 @@ def register(self, cls: Matcher) -> None:
8484
8585
**Extending matching capability:**
8686
87-
>>> class GitHubPrefix(Matcher):
87+
>>> class GitHubPrefix(Rule):
8888
... label = 'gh-prefix'
8989
... description ='Matches prefixes like github:org/repo'
9090
... pattern = r'^github:(?P<path>.*)$'
@@ -97,8 +97,8 @@ def register(self, cls: Matcher) -> None:
9797
9898
>>> @dataclasses.dataclass(repr=False)
9999
... class GitHubURL(GitURL):
100-
... matchers: MatcherRegistry = MatcherRegistry(
101-
... _matchers={'github_prefix': GitHubPrefix}
100+
... rules: Rules = Rules(
101+
... _rules={'github_prefix': GitHubPrefix}
102102
... )
103103
104104
>>> GitHubURL.is_valid(url='github:vcs-python/libvcs')
@@ -114,26 +114,26 @@ def register(self, cls: Matcher) -> None:
114114
scheme=https,
115115
hostname=github.com,
116116
path=vcs-python/libvcs,
117-
matcher=gh-prefix)
117+
rule=gh-prefix)
118118
119119
>>> GitHubURL(url='github:vcs-python/libvcs').to_url()
120120
'https://github.com/vcs-python/libvcs'
121121
122122
>>> GitHubURL.is_valid(url='gitlab:vcs-python/libvcs')
123123
False
124124
125-
``GitHubURL`` sees this as invalid since it only has one matcher,
125+
``GitHubURL`` sees this as invalid since it only has one rule,
126126
``GitHubPrefix``.
127127
128128
>>> GitURL.is_valid(url='gitlab:vcs-python/libvcs')
129129
True
130130
131131
Same story, getting caught in ``git(1)``'s own liberal scp-style URL:
132132
133-
>>> GitURL(url='gitlab:vcs-python/libvcs').matcher
133+
>>> GitURL(url='gitlab:vcs-python/libvcs').rule
134134
'core-git-scp'
135135
136-
>>> class GitLabPrefix(Matcher):
136+
>>> class GitLabPrefix(Rule):
137137
... label = 'gl-prefix'
138138
... description ='Matches prefixes like gitlab:org/repo'
139139
... pattern = r'^gitlab:(?P<path>)'
@@ -143,12 +143,12 @@ def register(self, cls: Matcher) -> None:
143143
... 'suffix': '.git'
144144
... }
145145
146-
Option 1: Create a brand new matcher
146+
Option 1: Create a brand new rule
147147
148148
>>> @dataclasses.dataclass(repr=False)
149149
... class GitLabURL(GitURL):
150-
... matchers: MatcherRegistry = MatcherRegistry(
151-
... _matchers={'gitlab_prefix': GitLabPrefix}
150+
... rules: Rules = Rules(
151+
... _rules={'gitlab_prefix': GitLabPrefix}
152152
... )
153153
154154
>>> GitLabURL.is_valid(url='gitlab:vcs-python/libvcs')
@@ -161,12 +161,12 @@ def register(self, cls: Matcher) -> None:
161161
162162
Are we home free, though? Remember our issue with vague matches.
163163
164-
>>> GitURL(url='gitlab:vcs-python/libvcs').matcher
164+
>>> GitURL(url='gitlab:vcs-python/libvcs').rule
165165
'core-git-scp'
166166
167167
Register:
168168
169-
>>> GitURL.matchers.register(GitLabPrefix)
169+
>>> GitURL.rules.register(GitLabPrefix)
170170
171171
>>> GitURL.is_valid(url='gitlab:vcs-python/libvcs')
172172
True
@@ -183,8 +183,8 @@ def register(self, cls: Matcher) -> None:
183183
184184
>>> @dataclasses.dataclass(repr=False)
185185
... class GitURLWithPip(GitBaseURL):
186-
... matchers: MatcherRegistry = MatcherRegistry(
187-
... _matchers={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
186+
... rules: Rules = Rules(
187+
... _rules={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
188188
... )
189189
190190
>>> GitURLWithPip.is_valid(url="git+ssh://git@github.com/tony/AlgoXY.git")
@@ -197,19 +197,19 @@ def register(self, cls: Matcher) -> None:
197197
hostname=github.com,
198198
path=tony/AlgoXY,
199199
suffix=.git,
200-
matcher=pip-url)
200+
rule=pip-url)
201201
""" # NOQA: E501
202-
if cls.label not in self._matchers:
203-
self._matchers[cls.label] = cls
202+
if cls.label not in self._rules:
203+
self._rules[cls.label] = cls
204204

205205
def unregister(self, label: str) -> None:
206-
if label in self._matchers:
207-
del self._matchers[label]
206+
if label in self._rules:
207+
del self._rules[label]
208208

209209
def __iter__(self) -> Iterator[str]:
210-
return self._matchers.__iter__()
210+
return self._rules.__iter__()
211211

212212
def values(
213213
self, # https://github.com/python/typing/discussions/1033
214-
) -> "dict_values[str, Matcher]":
215-
return self._matchers.values()
214+
) -> "dict_values[str, Rule]":
215+
return self._rules.values()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.