8000 Decouple regexes, make varaibles consistent by tony · Pull Request #463 · vcs-python/libvcs · GitHub
[go: up one dir, main page]

Skip to content

Decouple regexes, make varaibles consistent #463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
constants(SCP_REGEX): SCP_REGEX to constants module
  • Loading branch information
tony committed Jun 17, 2024
commit 1366a7a5f357782d1149a2702526a50e882e6b99
14 changes: 14 additions & 0 deletions src/libvcs/url/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@
((?P<user>[^/:@]+)@)?
"""
"""Optional user, e.g. 'git@'"""

# Credit, pip (license: MIT):
# https://github.com/pypa/pip/blob/22.1.2/src/pip/_internal/vcs/git.py#L39-L52
# We modified it to have groupings
SCP_REGEX = r"""
# Server, e.g. 'github.com'.
(?P<hostname>([^/:]+))
(?P<separator>:)
# The server-side path. e.g. 'user/project.git'. Must start with an
# alphanumeric character so as not to be confusable with a Windows paths
# like 'C:/foo/bar' or 'C:\foo\bar'.
(?P<path>(\w[^:.]+))
"""
"""Regular expression for scp-style of git URLs."""
15 changes: 1 addition & 14 deletions src/libvcs/url/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,7 @@
from libvcs._internal.dataclasses import SkipDefaultFieldsReprMixin

from .base import Rule, RuleMap, URLProtocol
from .constants import RE_USER

# Credit, pip (license: MIT):
# https://github.com/pypa/pip/blob/22.1.2/src/pip/_internal/vcs/git.py#L39-L52
# We modified it to have groupings
SCP_REGEX = r"""
# Server, e.g. 'github.com'.
(?P<hostname>([^/:]+))
(?P<separator>:)
# The server-side path. e.g. 'user/project.git'. Must start with an
# alphanumeric character so as not to be confusable with a Windows paths
# like 'C:/foo/bar' or 'C:\foo\bar'.
(?P<path>(\w[^:.]+))
"""
from .constants import RE_USER, SCP_REGEX

RE_PATH = r"""
(?P<hostname>([^/:]+))
Expand Down
4 changes: 2 additions & 2 deletions src/libvcs/url/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
from typing import Optional

from libvcs._internal.dataclasses import SkipDefaultFieldsReprMixin
from libvcs.url.git import RE_PIP_REV, RE_SUFFIX, SCP_REGEX
from libvcs.url.git import RE_PIP_REV, RE_SUFFIX

from .base import Rule, RuleMap, URLProtocol
from .constants import RE_USER
from .constants import RE_USER, SCP_REGEX

RE_PATH = r"""
(?P<hostname>([^/:]+))
Expand Down
4 changes: 2 additions & 2 deletions src/libvcs/url/svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from typing import Optional

from libvcs._internal.dataclasses import SkipDefaultFieldsReprMixin
from libvcs.url.git import RE_PIP_REV, SCP_REGEX
from libvcs.url.git import RE_PIP_REV

from .base import Rule, RuleMap, URLProtocol
from .constants import RE_USER
from .constants import RE_USER, SCP_REGEX

RE_PATH = r"""
(?P<hostname>([^/:@]+))
Expand Down
0