未验证 提交 ef6d7368 编写于 作者: F Frost Ming

Fix sections resolve

上级 df4a35f8
from __future__ import annotations
from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Set, Tuple
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple
from resolvelib.resolvers import Criterion, Resolution
......@@ -62,12 +62,29 @@ def _build_metaset(
return metaset or Metaset()
def _get_sections(crit: Criterion) -> Iterable[str]:
for req, parent in crit.information:
if not parent:
yield req.from_section
else:
yield from parent.sections
def populate_sections(result: Result) -> None:
_sections_cache: Dict[str, List[str]] = {}
_visited: Set[str] = set() # a collection of visited names to avoid dead loop.
def get_candidate_sections(key: str) -> List[str]:
_visited.add(key)
if key in _sections_cache:
return _sections_cache[key]
res = set()
crit: Criterion = result.criteria[key]
for req, parent in crit.information:
if parent is None:
res.add(req.from_section)
else:
pkey = _identify_parent(parent)
if pkey in _visited:
continue
res.update(get_candidate_sections(pkey))
_sections_cache[key] = res = list(res)
return res
for k, can in result.mapping.items():
can.sections = sorted(get_candidate_sections(k))
def extract_metadata(result: Result) -> Dict[str, Metaset]:
......@@ -91,7 +108,6 @@ def extract_metadata(result: Result) -> Dict[str, Metaset]:
):
continue
new_metasets[k] = _build_metaset(crit, all_metasets, keep_unresolved)
result.mapping[k].sections = list(set(_get_sections(crit)))
if new_metasets:
all_metasets.update(new_metasets)
......@@ -116,7 +132,6 @@ def extract_metadata(result: Result) -> Dict[str, Metaset]:
for key in circular:
crit = result.criteria[key]
all_metasets[key] = _build_metaset(crit, all_metasets, set())
result.mapping[key].sections = list(set(_get_sections(crit)))
return all_metasets
......@@ -159,4 +174,6 @@ def resolve(
candidate = mapping[key]
candidate.marker = metaset.as_marker()
candidate.hashes = provider.get_hashes(candidate)
populate_sections(result)
return mapping, provider.fetched_dependencies, provider.summary_collection
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册