Skip to content

Commit 6e877d3

Browse files
committed
url: Decouple user regex to RE_USER
1 parent 4469c2a commit 6e877d3

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

src/libvcs/url/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Constants shared across ``libvcs.url``."""
2+
3+
RE_USER = r"""
4+
((?P<user>[^/:@]+)@)?
5+
"""
6+
"""Optional user, e.g. 'git@'"""

src/libvcs/url/git.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@
2323
from libvcs._internal.dataclasses import SkipDefaultFieldsReprMixin
2424

2525
from .base import Rule, RuleMap, URLProtocol
26+
from .constants import RE_USER
2627

2728
# Credit, pip (license: MIT):
2829
# https://github.com/pypa/pip/blob/22.1.2/src/pip/_internal/vcs/git.py#L39-L52
2930
# We modified it to have groupings
3031
SCP_REGEX = r"""
31-
# Optional user, e.g. 'git@'
32-
((?P<user>\w+)@)?
3332
# Server, e.g. 'github.com'.
3433
(?P<hostname>([^/:]+))
3534
(?P<separator>:)
@@ -40,7 +39,6 @@
4039
"""
4140

4241
RE_PATH = r"""
43-
((?P<user>\w+)@)?
4442
(?P<hostname>([^/:]+))
4543
(:(?P<port>\d{1,5}))?
4644
(?P<separator>[:,/])?
@@ -69,6 +67,7 @@
6967
rf"""
7068
^{RE_SCHEME}
7169
://
70+
{RE_USER}
7271
{RE_PATH}
7372
{RE_SUFFIX}?
7473
""",
@@ -83,6 +82,7 @@
8382
pattern=re.compile(
8483
rf"""
8584
^(?P<scheme>ssh)?
85+
{RE_USER}
8686
{SCP_REGEX}
8787
{RE_SUFFIX}?
8888
""",
@@ -125,7 +125,6 @@
125125
(@(?P<rev>.*))
126126
"""
127127

128-
129128
PIP_DEFAULT_RULES: list[Rule] = [
130129
Rule(
131130
label="pip-url",
@@ -134,6 +133,7 @@
134133
rf"""
135134
{RE_PIP_SCHEME}
136135
://
136+
{RE_USER}
137137
{RE_PATH}
138138
{RE_SUFFIX}?
139139
{RE_PIP_REV}?
@@ -148,6 +148,7 @@
148148
pattern=re.compile(
149149
rf"""
150150
{RE_PIP_SCP_SCHEME}
151+
{RE_USER}
151152
{SCP_REGEX}?
152153
{RE_SUFFIX}?
153154
{RE_PIP_REV}?

src/libvcs/url/hg.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
from libvcs.url.git import RE_PIP_REV, RE_SUFFIX, SCP_REGEX
2626

2727
from .base import Rule, RuleMap, URLProtocol
28+
from .constants import RE_USER
2829

2930
RE_PATH = r"""
30-
((?P<user>\w+)@)?
3131
(?P<hostname>([^/:]+))
3232
(:(?P<port>\d{1,5}))?
3333
(?P<separator>[:,/])?
@@ -53,6 +53,7 @@
5353
rf"""
5454
^{RE_SCHEME}
5555
://
56+
{RE_USER}
5657
{RE_PATH}
5758
{RE_SUFFIX}?
5859
{RE_PIP_REV}?
@@ -66,6 +67,7 @@
6667
pattern=re.compile(
6768
rf"""
6869
^(?P<scheme>ssh)?
70+
{RE_USER}
6971
{SCP_REGEX}
7072
{RE_SUFFIX}?
7173
""",
@@ -100,6 +102,7 @@
100102
rf"""
101103
^{RE_PIP_SCHEME}
102104
://
105+
{RE_USER}
103106
{RE_PATH}
104107
{RE_SUFFIX}?
105108
{RE_PIP_REV}?

src/libvcs/url/svn.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
from libvcs.url.git import RE_PIP_REV, SCP_REGEX
2727

2828
from .base import Rule, RuleMap, URLProtocol
29+
from .constants import RE_USER
2930

3031
RE_PATH = r"""
31-
((?P<user>[^/:@]+)@)?
3232
(?P<hostname>([^/:@]+))
3333
(:(?P<port>\d{1,5}))?
3434
(?P<separator>[:,/])?
@@ -56,6 +56,7 @@
5656
rf"""
5757
^{RE_SCHEME}
5858
://
59+
{RE_USER}
5960
{RE_PATH}
6061
{RE_PIP_REV}?
6162
""",
@@ -68,6 +69,7 @@
6869
pattern=re.compile(
6970
rf"""
7071
^(?P<scheme>ssh)?
72+
{RE_USER}
7173
{SCP_REGEX}
7274
{RE_PIP_REV}?
7375
""",
@@ -101,6 +103,7 @@
101103
rf"""
102104
^{RE_PIP_SCHEME}
103105
://
106+
{RE_USER}
104107
{RE_PATH}
105108
{RE_PIP_REV}?
106109
""",

0 commit comments

Comments
 (0)