Skip to content

Commit

Permalink
fix: support extras and more chars in names for VCS lines (#103) - th…
Browse files Browse the repository at this point in the history
…anks @theCapypara

Signed-off-by: Marco "Capypara" Köpcke <hello@capypara.de>
  • Loading branch information
theCapypara authored Jul 26, 2024
1 parent f303a69 commit 90e7f9e
Show file tree
Hide file tree
Showing 3 changed files with 255 additions and 5 deletions.
6 changes: 3 additions & 3 deletions requirements/requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
r'(#(?P<fragment>\S+))?'
)

VCS_OPTIONAL_NAME_REGEX = r'(?:(?P<name>\w+)\s*@)?\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'^{VCS_OPTIONAL_NAME_REGEX}(?P<scheme>{VCS_SCHEMES_REGEX})://((?P<login>[^/@]+)@)?'
Expand Down Expand Up @@ -152,7 +152,7 @@ def parse_editable(cls, line: str) -> 'Requirement':
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
req.name, req.extras = parse_extras_require(groups['name']) # type: ignore
for vcs in VCS:
if str(req.uri).startswith(vcs):
req.vcs = vcs # type: ignore
Expand Down Expand Up @@ -207,7 +207,7 @@ def parse_line(cls, line: str) -> 'Requirement':
if str(req.uri).startswith(vcs):
req.vcs = vcs # type: ignore
if groups['name']:
req.name = groups['name'] # type: ignore
req.name, req.extras = parse_extras_require(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
234 changes: 233 additions & 1 deletion tests/reqfiles/vcs_package_alias.expected
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,237 @@
"hash": null,
"extras": [],
"specs": []
},




{
"line": "Some_Project@git+https://git.repo/some_pkg.git@1.3.1",
"editable": false,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "Some_Project",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
},
{
"line": "Some-Project@git+https://git.repo/some_pkg.git@1.3.1",
"editable": false,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "Some-Project",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
},
{
"line": "Some_Project@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": "Some_Project",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
},
{
"line": "Some_Project@ git+https://git.repo/some_pkg.git@1.3.1",
"editable": false,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "Some_Project",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
},
{
"line": "Some_Project @git+https://git.repo/some_pkg.git@1.3.1",
"editable": false,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "Some_Project",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
},
{
"line": "Some_Project @ git+https://git.repo/some_pkg.git@1.3.1",
"editable": false,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "Some_Project",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
},
{
"line": "-e Some_Project@git+https://git.repo/some_pkg.git@1.3.1",
"editable": true,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "Some_Project",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": [],
"specs": []
},




{
"line": "SomeProject[extra1,extra2]@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": ["extra1", "extra2"],
"specs": []
},
{
"line": "Some_Project[extra1]@git+https://git.repo/some_pkg.git@1.3.1",
"editable": false,
"local_file": false,
"specifier": false,
"vcs": "git",
"revision": "1.3.1",
"name": "Some_Project",
"uri": "git+https://git.repo/some_pkg.git",
"subdirectory": null,
"path": null,
"hash_name": null,
"hash": null,
"extras": ["extra1"],
"specs": []
},
{
"line": "SomeProject[extra1,extra2]@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": ["extra1", "extra2"],
"specs": []
},
{
"line": "SomeProject[extra1,extra2]@ 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": ["extra1", "extra2"],
"specs": []
},
{
"line": "SomeProject[extra1,extra2] @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": ["extra1", "extra2"],
"specs": []
},
{
"line": "SomeProject[extra1,extra2] @ 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": ["extra1", "extra2"],
"specs": []
},
{
"line": "-e SomeProject[extra1,extra2]@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": ["extra1", "extra2"],
"specs": []
}
]
]
20 changes: 19 additions & 1 deletion tests/reqfiles/vcs_package_alias.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,22 @@ 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
-e SomeProject@git+https://git.repo/some_pkg.git@1.3.1

Some_Project@git+https://git.repo/some_pkg.git@1.3.1
Some-Project@git+https://git.repo/some_pkg.git@1.3.1
Some_Project@git+https://git.repo/some_pkg.git@1.3.1#egg=EggName
Some_Project@ git+https://git.repo/some_pkg.git@1.3.1
Some_Project @git+https://git.repo/some_pkg.git@1.3.1
Some_Project @ git+https://git.repo/some_pkg.git@1.3.1

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

SomeProject[extra1,extra2]@git+https://git.repo/some_pkg.git@1.3.1
Some_Project[extra1]@git+https://git.repo/some_pkg.git@1.3.1
SomeProject[extra1,extra2]@git+https://git.repo/some_pkg.git@1.3.1#egg=EggName
SomeProject[extra1,extra2]@ git+https://git.repo/some_pkg.git@1.3.1
SomeProject[extra1,extra2] @git+https://git.repo/some_pkg.git@1.3.1
SomeProject[extra1,extra2] @ git+https://git.repo/some_pkg.git@1.3.1

-e SomeProject[extra1,extra2]@git+https://git.repo/some_pkg.git@1.3.1

0 comments on commit 90e7f9e

Please sign in to comment.