Skip to content

Commit

Permalink
Modify _reqs.py to prefer prefer packaging instead of pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Jan 24, 2023
1 parent 1cfd18b commit dd7b8fb
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions setuptools/_reqs.py
@@ -1,9 +1,13 @@
from typing import Callable, Iterable, Iterator, TypeVar, Union, overload

import setuptools.extern.jaraco.text as text
from setuptools.extern.packaging.requirements import Requirement

from pkg_resources import Requirement
_T = TypeVar("_T")
_StrOrIter = Union[str, Iterable[str]]


def parse_strings(strs):
def parse_strings(strs: _StrOrIter) -> Iterator[str]:
"""
Yield requirement strings for each specification in `strs`.
Expand All @@ -12,8 +16,18 @@ def parse_strings(strs):
return text.join_continuation(map(text.drop_comment, text.yield_lines(strs)))


def parse(strs):
@overload
def parse(strs: _StrOrIter) -> Iterator[Requirement]:
...


@overload
def parse(strs: _StrOrIter, parser: Callable[[str], _T]) -> Iterator[_T]:
...


def parse(strs, parser=Requirement):
"""
Deprecated drop-in replacement for pkg_resources.parse_requirements.
Replacement for ``pkg_resources.parse_requirements`` that uses ``packaging``.
"""
return map(Requirement, parse_strings(strs))
return map(parser, parse_strings(strs))

0 comments on commit dd7b8fb

Please sign in to comment.