10000 URLs: Renaming by tony · Pull Request #417 · vcs-python/libvcs · GitHub
[go: up one dir, main page]

Skip to content

URLs: Renaming #417

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
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

8000
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
refactor!(url): MATCHERS -> RULES
  • Loading branch information
tony committed Sep 22, 2022
commit 7315799708a1a13617f2af3116d7fd36126f94a6
6 changes: 3 additions & 3 deletions src/libvcs/url/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,18 @@ def register(self, cls: Rule) -> None:

**Example: git URLs + pip-style git URLs:**

This is already in :class:`GitURL` via :data:`PIP_DEFAULT_MATCHERS`. For the
This is already in :class:`GitURL` via :data:`PIP_DEFAULT_RULES`. For the
sake of showing how extensibility works, here is a recreation based on
:class:`GitBaseURL`:

>>> from libvcs.url.git import GitBaseURL

>>> from libvcs.url.git import DEFAULT_MATCHERS, PIP_DEFAULT_MATCHERS
>>> from libvcs.url.git import DEFAULT_RULES, PIP_DEFAULT_RULES

>>> @dataclasses.dataclass(repr=False)
... class GitURLWithPip(GitBaseURL):
... rule_map: RuleMap = RuleMap(
... _rule_map={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
... _rule_map={m.label: m for m in [*DEFAULT_RULES, *PIP_DEFAULT_RULES]}
... )

>>> GitURLWithPip.is_valid(url="git+ssh://git@github.com/tony/AlgoXY.git")
Expand Down
12 changes: 6 additions & 6 deletions src/libvcs/url/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# Some https repos have .git at the end, e.g. https://github.com/org/repo.git


DEFAULT_MATCHERS: list[Rule] = [
DEFAULT_RULES: list[Rule] = [
Rule(
label="core-git-https",
description="Vanilla git pattern, URL ending with optional .git suffix",
Expand Down Expand Up @@ -125,7 +125,7 @@
"""


PIP_DEFAULT_MATCHERS: list[Rule] = [
PIP_DEFAULT_RULES: list[Rule] = [
Rule(
label="pip-url",
description="pip-style git URL",
Expand Down Expand Up @@ -191,7 +191,7 @@
- https://pip.pypa.io/en/stable/topics/vcs-support/
""" # NOQA: E501

NPM_DEFAULT_MATCHERS: list[Rule] = []
NPM_DEFAULT_RULES: list[Rule] = []
"""NPM-style git URLs.

Git URL pattern (from docs.npmjs.com)::
Expand Down Expand Up @@ -262,7 +262,7 @@ class GitBaseURL(URLProtocol, SkipDefaultFieldsReprMixin):
suffix: Optional[str] = None

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

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

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

def to_url(self) -> str:
"""Exports a pip-compliant URL.
Expand Down Expand Up @@ -479,7 +479,7 @@ class GitURL(GitPipURL, GitBaseURL, URLProtocol, SkipDefaultFieldsReprMixin):
"""

rule_map: RuleMap = RuleMap(
_rule_map={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
_rule_map={m.label: m for m in [*DEFAULT_RULES, *PIP_DEFAULT_RULES]}
)

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions src/libvcs/url/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
"""

DEFAULT_MATCHERS: list[Rule] = [
DEFAULT_RULES: list[Rule] = [
Rule(
label="core-hg",
description="Vanilla hg pattern",
Expand Down Expand Up @@ -74,7 +74,7 @@
)
"""

PIP_DEFAULT_MATCHERS: list[Rule] = [
PIP_DEFAULT_RULES: list[Rule] = [
Rule(
label="pip-url",
description="pip-style hg URL",
Expand Down Expand Up @@ -176,7 +176,7 @@ class HgURL(URLProtocol, SkipDefaultFieldsReprMixin):

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

def __post_init__(self) -> None:
url = self.url
Expand Down
6 changes: 3 additions & 3 deletions src/libvcs/url/svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
)
"""

DEFAULT_MATCHERS: list[Rule] = [
DEFAULT_RULES: list[Rule] = [
Rule(
label="core-svn",
description="Vanilla svn pattern",
Expand Down Expand Up @@ -78,7 +78,7 @@
)
"""

PIP_DEFAULT_MATCHERS: list[Rule] = [
PIP_DEFAULT_RULES: list[Rule] = [
Rule(
label="pip-url",
description="pip-style svn URL",
Expand Down Expand Up @@ -170,7 +170,7 @@ class SvnURL(URLProtocol, SkipDefaultFieldsReprMixin):
ref: Optional[str] = None

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

def __post_init__(self) -> None:
url = self.url
Expand Down
6 changes: 3 additions & 3 deletions tests/url/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from libvcs.sync.git import GitSync
from libvcs.url.base import RuleMap
from libvcs.url.git import DEFAULT_MATCHERS, PIP_DEFAULT_MATCHERS, GitBaseURL, GitURL
from libvcs.url.git import DEFAULT_RULES, PIP_DEFAULT_RULES, GitBaseURL, GitURL


class GitURLFixture(typing.NamedTuple):
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_git_url_extension_pip(
) -> None:
class GitURLWithPip(GitBaseURL):
rule_map: RuleMap = RuleMap(
_rule_map={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
_rule_map={m.label: m for m in [*DEFAULT_RULES, *PIP_DEFAULT_RULES]}
)

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

git_url = GitURLWithPip(**git_url_kwargs)
Expand Down
4 changes: 2 additions & 2 deletions tests/url/test_hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from libvcs.sync.hg import HgSync
from libvcs.url.base import RuleMap
from libvcs.url.hg import DEFAULT_MATCHERS, PIP_DEFAULT_MATCHERS, HgURL
from libvcs.url.hg import DEFAULT_RULES, PIP_DEFAULT_RULES, HgURL


class HgURLFixture(typing.NamedTuple):
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_hg_url_extension_pip(
) -> None:
class HgURLWithPip(HgURL):
rule_map: RuleMap = RuleMap(
_rule_map={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
_rule_map={m.label: m for m in [*DEFAULT_RULES, *PIP_DEFAULT_RULES]}
)

hg_url_kwargs["url"] = hg_url_kwargs["url"].format(local_repo=hg_repo.dir)
Expand Down
4 changes: 2 additions & 2 deletions tests/url/test_svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from libvcs.sync.svn import SvnSync
from libvcs.url.base import RuleMap
from libvcs.url.svn import DEFAULT_MATCHERS, PIP_DEFAULT_MATCHERS, SvnURL
from libvcs.url.svn import DEFAULT_RULES, PIP_DEFAULT_RULES, SvnURL


class SvnURLFixture(typing.NamedTuple):
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_svn_url_extension_pip(
) -> None:
class SvnURLWithPip(SvnURL):
rule_map: RuleMap = RuleMap(
_rule_map={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
_rule_map={m.label: m for m in [*DEFAULT_RULES, *PIP_DEFAULT_RULES]}
)

svn_url_kwargs["url"] = svn_url_kwargs["url"].format(local_repo=svn_repo.dir)
Expand Down
0