Move dist preparation to its own method
@@ -143,18 +143,19 @@ class _InstallRequirementBackedCandidate(Candidate):
self._version = self.dist.parsed_version
return self._version
- def _get_abstract_distribution(self):
+ def _prepare_abstract_distribution(self):
# type: () -> AbstractDistribution
raise NotImplementedError("Override in subclass")
- @property
- def dist(self):
- # type: () -> Distribution
- if self._dist is None:
- abstract_dist = self._get_abstract_distribution()
+ def _prepare(self):
+ # type: () -> None
+ if self._dist is not None:
+ return
+
+ abstract_dist = self._prepare_abstract_distribution()
self._dist = abstract_dist.get_pkg_resources_distribution()
- # TODO: Only InstalledDistribution can return None here :-(
- assert self._dist is not None
+ assert self._dist is not None, "Distribution already installed"
+
# TODO: Abort cleanly here, as the resolution has been
# based on the wrong name/version until now, and
# so is wrong.
@@ -176,6 +177,10 @@ class _InstallRequirementBackedCandidate(Candidate):
self._version, self._dist.parsed_version,
)
+ @property
+ def dist(self):
+ # type: () -> Distribution
+ self._prepare()
return self._dist
def _get_requires_python_specifier(self):
@@ -207,7 +212,7 @@ class _InstallRequirementBackedCandidate(Candidate):
def get_install_requirement(self):
# type: () -> Optional[InstallRequirement]
- self.dist # HACK? Ensure the candidate is correctly prepared.
+ self._prepare()
return self._ireq
@@ -229,7 +234,7 @@ class LinkCandidate(_InstallRequirementBackedCandidate):
version=version,
)
- def _get_abstract_distribution(self):
+ def _prepare_abstract_distribution(self):
# type: () -> AbstractDistribution
return self._factory.preparer.prepare_linked_requirement(self._ireq)
@@ -252,7 +257,7 @@ class EditableCandidate(_InstallRequirementBackedCandidate):
version=version,
)
- def _get_abstract_distribution(self):
+ def _prepare_abstract_distribution(self):
# type: () -> AbstractDistribution
return self._factory.preparer.prepare_editable_requirement(self._ireq)
