parse-git-url 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- parse_git_url-2.0.0/LICENSE +21 -0
- parse_git_url-2.0.0/PKG-INFO +34 -0
- parse_git_url-2.0.0/README.md +25 -0
- parse_git_url-2.0.0/pyproject.toml +15 -0
- parse_git_url-2.0.0/setup.cfg +4 -0
- parse_git_url-2.0.0/src/__init__.py +35 -0
- parse_git_url-2.0.0/src/parse_git_url.egg-info/PKG-INFO +34 -0
- parse_git_url-2.0.0/src/parse_git_url.egg-info/SOURCES.txt +10 -0
- parse_git_url-2.0.0/src/parse_git_url.egg-info/dependency_links.txt +1 -0
- parse_git_url-2.0.0/src/parse_git_url.egg-info/top_level.txt +2 -0
- parse_git_url-2.0.0/src/parser.py +101 -0
- parse_git_url-2.0.0/test/test_parser.py +72 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 John Dewey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: parse-git-url
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Dynamic: license-file
|
|
9
|
+
|
|
10
|
+
# giturlparse
|
|
11
|
+
|
|
12
|
+
A simple git URL parser.
|
|
13
|
+
|
|
14
|
+
Special thanks to the original author @retr0h and the author who inspired them, @FriendCode.
|
|
15
|
+
|
|
16
|
+
## License
|
|
17
|
+
|
|
18
|
+
MIT
|
|
19
|
+
|
|
20
|
+
## Contributing
|
|
21
|
+
|
|
22
|
+
Thanks for your interest, feel free to submit issues or PRs and I'll take a peek when I can.
|
|
23
|
+
|
|
24
|
+
Formatting:
|
|
25
|
+
`uv run ruff format`
|
|
26
|
+
|
|
27
|
+
Testing:
|
|
28
|
+
`uv run pytest --cov=src/`
|
|
29
|
+
|
|
30
|
+
Doc:
|
|
31
|
+
`uv run pdoc --output-dir=docs src/`
|
|
32
|
+
|
|
33
|
+
PRs will be squashed before merging into (conventional commits)[https://www.conventionalcommits.org/en/v1.0.0/].
|
|
34
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# giturlparse
|
|
2
|
+
|
|
3
|
+
A simple git URL parser.
|
|
4
|
+
|
|
5
|
+
Special thanks to the original author @retr0h and the author who inspired them, @FriendCode.
|
|
6
|
+
|
|
7
|
+
## License
|
|
8
|
+
|
|
9
|
+
MIT
|
|
10
|
+
|
|
11
|
+
## Contributing
|
|
12
|
+
|
|
13
|
+
Thanks for your interest, feel free to submit issues or PRs and I'll take a peek when I can.
|
|
14
|
+
|
|
15
|
+
Formatting:
|
|
16
|
+
`uv run ruff format`
|
|
17
|
+
|
|
18
|
+
Testing:
|
|
19
|
+
`uv run pytest --cov=src/`
|
|
20
|
+
|
|
21
|
+
Doc:
|
|
22
|
+
`uv run pdoc --output-dir=docs src/`
|
|
23
|
+
|
|
24
|
+
PRs will be squashed before merging into (conventional commits)[https://www.conventionalcommits.org/en/v1.0.0/].
|
|
25
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "parse-git-url"
|
|
3
|
+
version = "2.0.0"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
dependencies = []
|
|
8
|
+
|
|
9
|
+
[dependency-groups]
|
|
10
|
+
dev = [
|
|
11
|
+
"pdoc>=16.0.0",
|
|
12
|
+
"pytest>=9.0.3",
|
|
13
|
+
"pytest-cov>=7.1.0",
|
|
14
|
+
"ruff>=0.15.15",
|
|
15
|
+
]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
2
|
+
|
|
3
|
+
# Copyright (c) 2017 John Dewey
|
|
4
|
+
#
|
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
# furnished to do so, subject to the following conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
|
13
|
+
# all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
# THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
24
|
+
from .parser import GitUrl
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
__version__ = version("git-url-parse")
|
|
28
|
+
except PackageNotFoundError:
|
|
29
|
+
# pkg not installed
|
|
30
|
+
__version__ = "0.0.0.0"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def parse(url: str) -> GitUrl: # pragma: no cover
|
|
34
|
+
"""Parses a remote URL for a Git repository"""
|
|
35
|
+
return GitUrl.from_str(url)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: parse-git-url
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Dynamic: license-file
|
|
9
|
+
|
|
10
|
+
# giturlparse
|
|
11
|
+
|
|
12
|
+
A simple git URL parser.
|
|
13
|
+
|
|
14
|
+
Special thanks to the original author @retr0h and the author who inspired them, @FriendCode.
|
|
15
|
+
|
|
16
|
+
## License
|
|
17
|
+
|
|
18
|
+
MIT
|
|
19
|
+
|
|
20
|
+
## Contributing
|
|
21
|
+
|
|
22
|
+
Thanks for your interest, feel free to submit issues or PRs and I'll take a peek when I can.
|
|
23
|
+
|
|
24
|
+
Formatting:
|
|
25
|
+
`uv run ruff format`
|
|
26
|
+
|
|
27
|
+
Testing:
|
|
28
|
+
`uv run pytest --cov=src/`
|
|
29
|
+
|
|
30
|
+
Doc:
|
|
31
|
+
`uv run pdoc --output-dir=docs src/`
|
|
32
|
+
|
|
33
|
+
PRs will be squashed before merging into (conventional commits)[https://www.conventionalcommits.org/en/v1.0.0/].
|
|
34
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/__init__.py
|
|
5
|
+
src/parser.py
|
|
6
|
+
src/parse_git_url.egg-info/PKG-INFO
|
|
7
|
+
src/parse_git_url.egg-info/SOURCES.txt
|
|
8
|
+
src/parse_git_url.egg-info/dependency_links.txt
|
|
9
|
+
src/parse_git_url.egg-info/top_level.txt
|
|
10
|
+
test/test_parser.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
2
|
+
|
|
3
|
+
# Copyright (c) 2017 John Dewey
|
|
4
|
+
#
|
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
# furnished to do so, subject to the following conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
|
13
|
+
# all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
# THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
import collections
|
|
25
|
+
from typing import NamedTuple
|
|
26
|
+
import re
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
POSSIBLE_REGEXES = (
|
|
30
|
+
re.compile(
|
|
31
|
+
r"^(?P<protocol>https?|git|ssh|rsync)\://"
|
|
32
|
+
r"(?:(?P<user>.+)@)*"
|
|
33
|
+
r"(?P<resource>[a-z0-9_.-]*)"
|
|
34
|
+
r"[:/]*"
|
|
35
|
+
r"(?P<port>[\d]+){0,1}"
|
|
36
|
+
r"(?P<pathname>\/((?P<owner>[\w\-]+)\/)?"
|
|
37
|
+
r"((?P<name>[\w\-\.]+?)(\.git|\/)?)?)$"
|
|
38
|
+
),
|
|
39
|
+
re.compile(
|
|
40
|
+
r"(git\+)?"
|
|
41
|
+
r"((?P<protocol>\w+)://)"
|
|
42
|
+
r"((?P<user>\w+)@)?"
|
|
43
|
+
r"((?P<resource>[\w\.\-]+))"
|
|
44
|
+
r"(:(?P<port>\d+))?"
|
|
45
|
+
r"(?P<pathname>(\/(?P<owner>\w+)/)?"
|
|
46
|
+
r"(\/?(?P<name>[\w\-]+)(\.git|\/)?)?)$"
|
|
47
|
+
),
|
|
48
|
+
re.compile(
|
|
49
|
+
r"^(?:(?P<user>.+)@)*"
|
|
50
|
+
r"(?P<resource>[a-z0-9_.-]*)[:]*"
|
|
51
|
+
r"(?P<port>[\d]+){0,1}"
|
|
52
|
+
r"(?P<pathname>\/?(?P<owner>.+)/(?P<name>.+).git)$"
|
|
53
|
+
),
|
|
54
|
+
re.compile(
|
|
55
|
+
r"((?P<user>\w+)@)?"
|
|
56
|
+
r"((?P<resource>[\w\.\-]+))"
|
|
57
|
+
r"[\:\/]{1,2}"
|
|
58
|
+
r"(?P<pathname>((?P<owner>\w+)/)?"
|
|
59
|
+
r"((?P<name>[\w\-]+)(\.git|\/)?)?)$"
|
|
60
|
+
),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
type MaybeStr = str | None
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class ParseError(Exception):
|
|
68
|
+
"""Error raised when a URL can't be parsed."""
|
|
69
|
+
|
|
70
|
+
pass
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class GitUrl(NamedTuple):
|
|
74
|
+
pathname: MaybeStr = None
|
|
75
|
+
protocols: str | list[str] = []
|
|
76
|
+
protocol: str = "ssh"
|
|
77
|
+
href: MaybeStr = None
|
|
78
|
+
resource: str | None = None
|
|
79
|
+
user: MaybeStr = None
|
|
80
|
+
port: MaybeStr = None
|
|
81
|
+
name: MaybeStr = None
|
|
82
|
+
owner: MaybeStr = None
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def from_str(url: str) -> GitUrl:
|
|
86
|
+
for regex in POSSIBLE_REGEXES:
|
|
87
|
+
if match := regex.search(url):
|
|
88
|
+
data = match.groupdict()
|
|
89
|
+
data["href"] = url
|
|
90
|
+
data["protocols"] = _get_protocols(url)
|
|
91
|
+
return GitUrl(**data)
|
|
92
|
+
raise ParseError(f"Invalid URL '{url}'")
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _get_protocols(url: str) -> list[str]:
|
|
96
|
+
try:
|
|
97
|
+
idx = url.index("://")
|
|
98
|
+
return url[:idx].split("+")
|
|
99
|
+
except (ValueError, IndexError):
|
|
100
|
+
return []
|
|
101
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
2
|
+
|
|
3
|
+
# Copyright (c) 2017 John Dewey
|
|
4
|
+
#
|
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
# furnished to do so, subject to the following conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
|
13
|
+
# all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
# THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
from src.parser import GitUrl
|
|
24
|
+
import pytest
|
|
25
|
+
|
|
26
|
+
from src import parser
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.mark.parametrize(
|
|
30
|
+
"test_input",
|
|
31
|
+
[
|
|
32
|
+
"first_match_urls",
|
|
33
|
+
"second_match_urls",
|
|
34
|
+
"third_match_urls",
|
|
35
|
+
"fourth_match_urls",
|
|
36
|
+
],
|
|
37
|
+
)
|
|
38
|
+
def test_parse(request, test_input):
|
|
39
|
+
url_data = request.getfixturevalue(test_input)
|
|
40
|
+
for url, d in url_data.items():
|
|
41
|
+
result = GitUrl.from_str(url)
|
|
42
|
+
|
|
43
|
+
assert d["pathname"] == result.pathname
|
|
44
|
+
assert d["protocols"] == result.protocols
|
|
45
|
+
assert d["protocol"] == result.protocol
|
|
46
|
+
assert d["href"] == result.href
|
|
47
|
+
assert d["resource"] == result.resource
|
|
48
|
+
assert d["user"] == result.user
|
|
49
|
+
assert d["port"] == result.port
|
|
50
|
+
assert d["name"] == result.name
|
|
51
|
+
assert d["owner"] == result.owner
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_parse_raises_on_invalid_string(invalid_strings):
|
|
55
|
+
for invalid_string in invalid_strings:
|
|
56
|
+
with pytest.raises(parser.ParseError):
|
|
57
|
+
GitUrl.from_str(invalid_string)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_get_protocol_multiple_protocols():
|
|
61
|
+
parsed = parser._get_protocols("git+ssh://git@example.com/Owner/Repository.git")
|
|
62
|
+
assert ["git", "ssh"] == parsed
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_get_protocol_no_protocols():
|
|
66
|
+
assert [] == parser._get_protocols("//example.com/foo")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_get_protocol_one_protocols():
|
|
70
|
+
parsed = parser._get_protocols("ssh://git@example.com/Owner/Repository.git")
|
|
71
|
+
|
|
72
|
+
assert ["ssh"] == parsed
|