diff options
Diffstat (limited to 'third_party/python/setuptools/setuptools/_reqs.py')
-rw-r--r-- | third_party/python/setuptools/setuptools/_reqs.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/third_party/python/setuptools/setuptools/_reqs.py b/third_party/python/setuptools/setuptools/_reqs.py new file mode 100644 index 0000000000..5d5b927fd8 --- /dev/null +++ b/third_party/python/setuptools/setuptools/_reqs.py @@ -0,0 +1,33 @@ +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)) |