@@ -23,8 +23,8 @@ def is_valid(self, url: str, is_explicit: Optional[bool] = None) -> bool:
23
23
24
24
25
25
@dataclasses .dataclass (repr = False )
26
- class Matcher (SkipDefaultFieldsReprMixin ):
27
- """Structure for a matcher """
26
+ class Rule (SkipDefaultFieldsReprMixin ):
27
+ """Structure for a rule """
28
28
29
29
label : str
30
30
"""Computer readable name / ID"""
@@ -38,12 +38,12 @@ class Matcher(SkipDefaultFieldsReprMixin):
38
38
39
39
40
40
@dataclasses .dataclass (repr = False )
41
- class MatcherRegistry (SkipDefaultFieldsReprMixin ):
41
+ class Rules (SkipDefaultFieldsReprMixin ):
42
42
"""Pattern matching and parsing capabilities for URL parsers, e.g. GitURL"""
43
43
44
- _matchers : dict [str , Matcher ] = dataclasses .field (default_factory = dict )
44
+ _rules : dict [str , Rule ] = dataclasses .field (default_factory = dict )
45
45
46
- def register (self , cls : Matcher ) -> None :
46
+ def register (self , cls : Rule ) -> None :
47
47
r"""
48
48
49
49
.. currentmodule:: libvcs.url.git
@@ -72,7 +72,7 @@ def register(self, cls: Matcher) -> None:
72
72
GitURL(url=github:org/repo,
73
73
hostname=github,
74
74
path=org/repo,
75
- matcher =core-git-scp)
75
+ rule =core-git-scp)
76
76
77
77
>>> GitURL(url="github:org/repo").to_url()
78
78
'git@github:org/repo'
@@ -84,7 +84,7 @@ def register(self, cls: Matcher) -> None:
84
84
85
85
**Extending matching capability:**
86
86
87
- >>> class GitHubPrefix(Matcher ):
87
+ >>> class GitHubPrefix(Rule ):
88
88
... label = 'gh-prefix'
89
89
... description ='Matches prefixes like github:org/repo'
90
90
... pattern = r'^github:(?P<path>.*)$'
@@ -97,8 +97,8 @@ def register(self, cls: Matcher) -> None:
97
97
98
98
>>> @dataclasses.dataclass(repr=False)
99
99
... class GitHubURL(GitURL):
100
- ... matchers: MatcherRegistry = MatcherRegistry (
101
- ... _matchers ={'github_prefix': GitHubPrefix}
100
+ ... rules: Rules = Rules (
101
+ ... _rules ={'github_prefix': GitHubPrefix}
102
102
... )
103
103
104
104
>>> GitHubURL.is_valid(url='github:vcs-python/libvcs')
@@ -114,26 +114,26 @@ def register(self, cls: Matcher) -> None:
114
114
scheme=https,
115
115
hostname=github.com,
116
116
path=vcs-python/libvcs,
117
- matcher =gh-prefix)
117
+ rule =gh-prefix)
118
118
119
119
>>> GitHubURL(url='github:vcs-python/libvcs').to_url()
120
120
'https://github.com/vcs-python/libvcs'
121
121
122
122
>>> GitHubURL.is_valid(url='gitlab:vcs-python/libvcs')
123
123
False
124
124
125
- ``GitHubURL`` sees this as invalid since it only has one matcher ,
125
+ ``GitHubURL`` sees this as invalid since it only has one rule ,
126
126
``GitHubPrefix``.
127
127
128
128
>>> GitURL.is_valid(url='gitlab:vcs-python/libvcs')
129
129
True
130
130
131
131
Same story, getting caught in ``git(1)``'s own liberal scp-style URL:
132
132
133
- >>> GitURL(url='gitlab:vcs-python/libvcs').matcher
133
+ >>> GitURL(url='gitlab:vcs-python/libvcs').rule
134
134
'core-git-scp'
135
135
136
- >>> class GitLabPrefix(Matcher ):
136
+ >>> class GitLabPrefix(Rule ):
137
137
... label = 'gl-prefix'
138
138
... description ='Matches prefixes like gitlab:org/repo'
139
139
... pattern = r'^gitlab:(?P<path>)'
@@ -143,12 +143,12 @@ def register(self, cls: Matcher) -> None:
143
143
... 'suffix': '.git'
144
144
... }
145
145
146
- Option 1: Create a brand new matcher
146
+ Option 1: Create a brand new rule
147
147
148
148
>>> @dataclasses.dataclass(repr=False)
149
149
... class GitLabURL(GitURL):
150
- ... matchers: MatcherRegistry = MatcherRegistry (
151
- ... _matchers ={'gitlab_prefix': GitLabPrefix}
150
+ ... rules: Rules = Rules (
151
+ ... _rules ={'gitlab_prefix': GitLabPrefix}
152
152
... )
153
153
154
154
>>> GitLabURL.is_valid(url='gitlab:vcs-python/libvcs')
@@ -161,12 +161,12 @@ def register(self, cls: Matcher) -> None:
161
161
162
162
Are we home free, though? Remember our issue with vague matches.
163
163
164
- >>> GitURL(url='gitlab:vcs-python/libvcs').matcher
164
+ >>> GitURL(url='gitlab:vcs-python/libvcs').rule
165
165
'core-git-scp'
166
166
167
167
Register:
168
168
169
- >>> GitURL.matchers .register(GitLabPrefix)
169
+ >>> GitURL.rules .register(GitLabPrefix)
170
170
171
171
>>> GitURL.is_valid(url='gitlab:vcs-python/libvcs')
172
172
True
@@ -183,8 +183,8 @@ def register(self, cls: Matcher) -> None:
183
183
184
184
>>> @dataclasses.dataclass(repr=False)
185
185
... 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]}
188
188
... )
189
189
190
190
>>> GitURLWithPip.is_valid(url="git+ssh://git@github.com/tony/AlgoXY.git")
@@ -197,19 +197,19 @@ def register(self, cls: Matcher) -> None:
197
197
hostname=github.com,
198
198
path=tony/AlgoXY,
199
199
suffix=.git,
200
- matcher =pip-url)
200
+ rule =pip-url)
201
201
""" # 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
204
204
205
205
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 ]
208
208
209
209
def __iter__ (self ) -> Iterator [str ]:
210
- return self ._matchers .__iter__ ()
210
+ return self ._rules .__iter__ ()
211
211
212
212
def values (
213
213
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