Spaces:
Runtime error
Runtime error
File size: 882 Bytes
0c87db7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
from typing import Callable, Iterable, Iterator, TypeVar, Union, overload
import setuptools.extern.jaraco.text as text
from setuptools.extern.packaging.requirements import Requirement
_T = TypeVar("_T")
_StrOrIter = Union[str, Iterable[str]]
def parse_strings(strs: _StrOrIter) -> Iterator[str]:
"""
Yield requirement strings for each specification in `strs`.
`strs` must be a string, or a (possibly-nested) iterable thereof.
"""
return text.join_continuation(map(text.drop_comment, text.yield_lines(strs)))
@overload
def parse(strs: _StrOrIter) -> Iterator[Requirement]:
...
@overload
def parse(strs: _StrOrIter, parser: Callable[[str], _T]) -> Iterator[_T]:
...
def parse(strs, parser=Requirement):
"""
Replacement for ``pkg_resources.parse_requirements`` that uses ``packaging``.
"""
return map(parser, parse_strings(strs))
|