Skip to content

Commit

Permalink
feat: added support for alias @ <vcs_url> syntax (#101) - thanks to @…
Browse files Browse the repository at this point in the history
…Glizzus

Signed-off-by: Cal Crosby <calcruiseby@gmail.com>
  • Loading branch information
Glizzus authored Jul 23, 2024
1 parent 93b2a85 commit 2927e00
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
7 changes: 6 additions & 1 deletion requirements/requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
r'(#(?P<fragment>\S+))?'
)

VCS_OPTIONAL_NAME_REGEX = r'(?:(?P<name>\w+)\s*@)?\s*'
VCS_SCHEMES_REGEX = r'|'.join([scheme.replace('+', r'\+') for scheme in VCS_SCHEMES])
VCS_REGEX = re.compile(
rf'^(?P<scheme>{VCS_SCHEMES_REGEX})://((?P<login>[^/@]+)@)?'
rf'^{VCS_OPTIONAL_NAME_REGEX}(?P<scheme>{VCS_SCHEMES_REGEX})://((?P<login>[^/@]+)@)?'
r'(?P<path>[^#@]+)(@(?P<revision>[^#]+))?(#(?P<fragment>\S+))?'
)

Expand Down Expand Up @@ -150,6 +151,8 @@ def parse_editable(cls, line: str) -> 'Requirement':
req.name, req.extras = parse_extras_require(egg) # type: ignore
req.hash_name, req.hash = get_hash_info(fragment) # type: ignore
req.subdirectory = fragment.get('subdirectory') # type: ignore
if groups['name']:
req.name = groups['name'] # type: ignore
for vcs in VCS:
if str(req.uri).startswith(vcs):
req.vcs = vcs # type: ignore
Expand Down Expand Up @@ -203,6 +206,8 @@ def parse_line(cls, line: str) -> 'Requirement':
for vcs in VCS:
if str(req.uri).startswith(vcs):
req.vcs = vcs # type: ignore
if groups['name']:
req.name = groups['name'] # type: ignore
elif uri_match is not None:
groups = uri_match.groupdict()
req.uri = f'{groups["scheme"]}://{groups["path"]}' # type: ignore
Expand Down
98 changes: 98 additions & 0 deletions tests/reqfiles/vcs_package_alias.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[
{
"line": "SomeProject@git+https://git.repo/some_pkg.git@1.3.1",
"editable": false,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "SomeProject",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
},
{
"line": "SomeProject@git+https://git.repo/some_pkg.git@1.3.1#egg=EggName",
"editable": false,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "SomeProject",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
},
{
"line": "SomeProject@ git+https://git.repo/some_pkg.git@1.3.1",
"editable": false,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "SomeProject",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
},
{
"line": "SomeProject @git+https://git.repo/some_pkg.git@1.3.1",
"editable": false,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "SomeProject",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
},
{
"line": "SomeProject @ git+https://git.repo/some_pkg.git@1.3.1",
"editable": false,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "SomeProject",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
},
{
"line": "-e SomeProject@git+https://git.repo/some_pkg.git@1.3.1",
"editable": true,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "SomeProject",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
}
]
7 changes: 7 additions & 0 deletions tests/reqfiles/vcs_package_alias.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SomeProject@git+https://git.repo/some_pkg.git@1.3.1
SomeProject@git+https://git.repo/some_pkg.git@1.3.1#egg=EggName
SomeProject@ git+https://git.repo/some_pkg.git@1.3.1
SomeProject @git+https://git.repo/some_pkg.git@1.3.1
SomeProject @ git+https://git.repo/some_pkg.git@1.3.1

-e SomeProject@git+https://git.repo/some_pkg.git@1.3.1

0 comments on commit 2927e00

Please sign in to comment.