Skip to content
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

Fix bug to parse VCS URIs with references #331

Merged
merged 4 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions news/330.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Resolved an issue introduced in 1.6.5 that failed to parse refs in VCS uris
5 changes: 4 additions & 1 deletion src/requirementslib/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,10 @@ def split_ref_from_uri(uri):
path = parsed.path if parsed.path else ""
scheme = parsed.scheme if parsed.scheme else ""
ref = None
if scheme != "file" and (re.match("^.*@[^/@]*$", path) or path.count("@") >= 2):
schema_is_filelike = scheme in ("", "file")
if (not schema_is_filelike and "@" in path) or (
schema_is_filelike and (re.match("^.*@[^/@]*$", path) or path.count("@") >= 2)
):
path, _, ref = path.rpartition("@")
parsed = parsed._replace(path=path)
return (parsed.url, ref)
Expand Down
82 changes: 55 additions & 27 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,33 +100,61 @@ def test_split_vcs_method_from_uri():
)


def test_split_ref_from_uri():
assert utils.split_ref_from_uri("https://github.com/sarugaku/plette.git") == (
"https://github.com/sarugaku/plette.git",
None,
)
assert utils.split_ref_from_uri("/Users/some.user@acme.com/dev/myproject") == (
"/Users/some.user@acme.com/dev/myproject",
None,
)
assert utils.split_ref_from_uri(
"https://user:password@github.com/sarugaku/plette.git"
) == (
"https://user:password@github.com/sarugaku/plette.git",
None,
)
assert utils.split_ref_from_uri(
"git+https://github.com/pypa/pipenv.git@master#egg=pipenv"
) == (
"git+https://github.com/pypa/pipenv.git#egg=pipenv",
"master",
)
assert utils.split_ref_from_uri(
"/Users/some.user@acme.com/dev/myproject@bugfix/309"
) == (
"/Users/some.user@acme.com/dev/myproject",
"bugfix/309",
)
@pytest.mark.parametrize(
"uri,expected_output",
[
pytest.param(
"https://github.com/sarugaku/plette.git",
(
"https://github.com/sarugaku/plette.git",
None,
),
id="https VCS, no ref",
),
pytest.param(
"/Users/some.user@acme.com/dev/myproject",
(
"/Users/some.user@acme.com/dev/myproject",
None,
),
id="Local path with @",
),
pytest.param(
"https://user:password@github.com/sarugaku/plette.git",
(
"https://user:password@github.com/sarugaku/plette.git",
None,
),
id="https VCS, with user@, no ref",
),
pytest.param(
"git+https://github.com/pypa/pipenv.git@master#egg=pipenv",
(
"git+https://github.com/pypa/pipenv.git#egg=pipenv",
"master",
),
id="https VCS, no user, master ref",
),
pytest.param(
"/Users/some.user@acme.com/dev/myproject@bugfix/309",
(
"/Users/some.user@acme.com/dev/myproject",
"bugfix/309",
),
id="Local path with @ ref",
),
pytest.param(
"git+ssh://git@github.com/mycomp/our_repo.git@release/v318#egg=our_package",
(
"git+ssh://git@github.com/mycomp/our_repo.git#egg=our_package",
"release/v318",
),
id="git/ssh VCS with user name, @ ref, egg",
),
],
)
def test_split_ref_from_uri(uri: str, expected_output):
assert utils.split_ref_from_uri(uri) == expected_output


# tests from pip-tools
Expand Down