Skip to content

Commit

Permalink
Merge pull request #193 from pietrodn/fix/package-clone-backport
Browse files Browse the repository at this point in the history
Backport fix for mismatching hash check
  • Loading branch information
sdispater authored Aug 26, 2021
2 parents 1978f38 + e612753 commit 52e543b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
29 changes: 2 additions & 27 deletions poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,33 +405,8 @@ def without_features(self): # type: () -> "Package"
return self.with_features([])

def clone(self): # type: () -> "Package"
if self.is_root():
clone = self.__class__(self.pretty_name, self.version)
else:
clone = self.__class__(
self.pretty_name,
self.version,
source_type=self._source_type,
source_url=self._source_url,
source_reference=self._source_reference,
features=list(self.features),
)

clone.description = self.description
clone.category = self.category
clone.optional = self.optional
clone.python_versions = self.python_versions
clone.marker = self.marker
clone.extras = self.extras
clone.root_dir = self.root_dir
clone.develop = self.develop

for dep in self.requires:
clone.requires.append(dep)

for dep in self.dev_requires:
clone.dev_requires.append(dep)

clone = self.__class__(self.pretty_name, self.version)
clone.__dict__ = copy.deepcopy(self.__dict__)
return clone

def __hash__(self): # type: () -> int
Expand Down
26 changes: 26 additions & 0 deletions tests/packages/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,29 @@ def test_to_dependency_for_url():
assert "https://example.com/path.tar.gz" == dep.url
assert "url" == dep.source_type
assert "https://example.com/path.tar.gz" == dep.source_url


def test_package_clone(f):
# TODO(nic): this test is not future-proof, in that any attributes added
# to the Package object and not filled out in this test setup might
# cause comparisons to match that otherwise should not. A factory method
# to create a Package object with all fields fully randomized would be the
# most rigorous test for this, but that's likely overkill.
p = Package(
"lol_wut",
"3.141.5926535",
pretty_version="③.⑭.⑮",
source_type="git",
source_url="http://some.url",
source_reference="fe4d2adabf3feb5d32b70ab5c105285fa713b10c",
source_resolved_reference="fe4d2adabf3feb5d32b70ab5c105285fa713b10c",
features=["abc", "def"],
)
p.files = (["file1", "file2", "file3"],)
p.homepage = "https://some.other.url"
p.repository_url = "http://bug.farm"
p.documentation_url = "http://lorem.ipsum/dolor/sit.amet"
p2 = p.clone()

assert p == p2
assert p.__dict__ == p2.__dict__

0 comments on commit 52e543b

Please sign in to comment.