MCPcopy
hub / github.com/scrapy/scrapy / build_component_list

Function build_component_list

scrapy/utils/conf.py:20–63  ·  view source on GitHub ↗

Compose a component list from a :ref:`component priority dictionary <component-priority-dictionaries>`.

(
    compdict: MutableMapping[Any, Any],
    *,
    convert: Callable[[Any], Any] = update_classpath,
)

Source from the content-addressed store, hash-verified

18
19
20def build_component_list(
21 compdict: MutableMapping[Any, Any],
22 *,
23 convert: Callable[[Any], Any] = update_classpath,
24) -> list[Any]:
25 """Compose a component list from a :ref:`component priority dictionary
26 <component-priority-dictionaries>`."""
27
28 def _check_components(complist: Collection[Any]) -> None:
29 if len({convert(c) for c in complist}) != len(complist):
30 raise ValueError(
31 f"Some paths in {complist!r} convert to the same object, "
32 "please update your settings"
33 )
34
35 def _map_keys(compdict: Mapping[Any, Any]) -> BaseSettings | dict[Any, Any]:
36 if isinstance(compdict, BaseSettings):
37 compbs = BaseSettings()
38 for k, v in compdict.items():
39 prio = compdict.getpriority(k)
40 assert prio is not None
41 if compbs.getpriority(convert(k)) == prio:
42 raise ValueError(
43 f"Some paths in {list(compdict.keys())!r} "
44 "convert to the same "
45 "object, please update your settings"
46 )
47 compbs.set(convert(k), v, priority=prio)
48 return compbs
49 _check_components(compdict)
50 return {convert(k): v for k, v in compdict.items()}
51
52 def _validate_values(compdict: Mapping[Any, Any]) -> None:
53 """Fail if a value in the components dict is not a real number or None."""
54 for name, value in compdict.items():
55 if value is not None and not isinstance(value, numbers.Real):
56 raise ValueError(
57 f"Invalid value {value} for component {name}, "
58 "please provide a real number or None instead"
59 )
60
61 _validate_values(compdict)
62 compdict = without_none_values(_map_keys(compdict))
63 return [k for k, v in sorted(compdict.items(), key=itemgetter(1))]
64
65
66def arglist_to_dict(arglist: list[str]) -> dict[str, str]:

Callers 11

load_settingsMethod · 0.90
runMethod · 0.90
test_build_dictMethod · 0.90
test_valid_numbersMethod · 0.90
__init__Method · 0.90

Calls 4

without_none_valuesFunction · 0.90
_validate_valuesFunction · 0.85
_map_keysFunction · 0.85
itemsMethod · 0.80

Tested by 4

test_build_dictMethod · 0.72
test_valid_numbersMethod · 0.72
__init__Method · 0.72