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 for git subdirectories #288

Merged
merged 8 commits into from
May 11, 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
2 changes: 2 additions & 0 deletions src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ def __repr__(self) -> str:
args.append(
f"source_resolved_reference={repr(self._source_resolved_reference)}"
)
if self._source_subdirectory:
args.append(f"source_subdirectory={repr(self._source_subdirectory)}")

args = ", ".join(args)
return f"Package({args})"
6 changes: 6 additions & 0 deletions src/poetry/core/packages/specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def is_same_package_as(self, other: PackageSpecification) -> bool:
) and self._source_url != other.source_url:
return False

if (
self._source_subdirectory or other.source_subdirectory
) and self._source_subdirectory != other.source_subdirectory:
return False

# We check the resolved reference first:
# if they match we assume equality regardless
# of their source reference.
Expand Down Expand Up @@ -131,6 +136,7 @@ def __hash__(self) -> int:
^ hash(self._source_url)
^ hash(self._source_reference)
^ hash(self._source_resolved_reference)
^ hash(self._source_subdirectory)
ashnair1 marked this conversation as resolved.
Show resolved Hide resolved
^ hash(self._features)
)

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def normalize_url(cls, url: str) -> GitUrl:

formatted = re.sub(r"^git\+", "", url)
if parsed.rev:
formatted = re.sub(rf"[#@]{parsed.rev}$", "", formatted)
formatted = re.sub(rf"[#@]{parsed.rev}(?=[#&]?)(?!\=)", "", formatted)

if parsed.subdirectory:
formatted = re.sub(
Expand Down
31 changes: 31 additions & 0 deletions tests/packages/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,37 @@ def test_package_resolved_reference_is_relevant_for_equality_only_if_present_for
assert a2 == a4


def test_package_equality_source_subdirectory() -> None:
a1 = Package(
"a",
"0.1.0",
source_type="git",
source_url="https://foo.bar",
source_subdirectory="baz",
)
a2 = Package(
a1.name,
a1.version,
source_type="git",
source_url="https://foo.bar",
source_subdirectory="qux",
)
a3 = Package(
a1.name,
a1.version,
source_type="git",
source_url="https://foo.bar",
source_subdirectory="baz",
)
a4 = Package(a1.name, a1.version, source_type="git")

assert a1 == a3
assert a1 != a2
assert a2 != a3
assert a1 != a4
assert a2 != a4


def test_complete_name() -> None:
assert Package("foo", "1.2.3").complete_name == "foo"
assert (
Expand Down
40 changes: 40 additions & 0 deletions tests/vcs/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,46 @@
"project",
),
),
(
"git+https://github.com/demo/pyproject-demo-subdirectory.git@commit#subdirectory=project",
GitUrl(
"https://github.com/demo/pyproject-demo-subdirectory.git",
"commit",
"project",
),
),
(
"git+https://github.com/demo/pyproject-demo-subdirectory.git#commit&subdirectory=project",
GitUrl(
"https://github.com/demo/pyproject-demo-subdirectory.git",
"commit",
"project",
),
),
(
"git+https://github.com/demo/pyproject-demo-subdirectory.git#commit#subdirectory=project",
GitUrl(
"https://github.com/demo/pyproject-demo-subdirectory.git",
"commit",
"project",
),
),
(
"git+https://github.com/demo/pyproject-demo-subdirectory.git@commit&subdirectory=project",
GitUrl(
"https://github.com/demo/pyproject-demo-subdirectory.git",
"commit",
"project",
),
),
(
"git+https://github.com/demo/pyproject-demo-subdirectory.git@subdirectory#subdirectory=subdirectory",
GitUrl(
"https://github.com/demo/pyproject-demo-subdirectory.git",
"subdirectory",
"subdirectory",
),
),
],
)
def test_normalize_url(url: str, normalized: GitUrl) -> None:
Expand Down