Skip to content

Commit

Permalink
Move requirements processing to _reqs module. Add parse function.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Feb 5, 2022
1 parent 31c62fe commit 73e08a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
19 changes: 19 additions & 0 deletions setuptools/_reqs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import setuptools.extern.jaraco.text as text

from pkg_resources import Requirement


def parse_strings(strs):
"""
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)))


def parse(strs):
"""
Deprecated drop-in replacement for pkg_resources.parse_requirements.
"""
return map(Requirement, parse_strings(strs))
14 changes: 2 additions & 12 deletions setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@

import setuptools
import distutils

import setuptools.extern.jaraco.text as text
from ._reqs import parse_strings

__all__ = ['get_requires_for_build_sdist',
'get_requires_for_build_wheel',
Expand All @@ -49,23 +48,14 @@
'SetupRequirementsError']


def parse_requirements(strs):
"""
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)))


class SetupRequirementsError(BaseException):
def __init__(self, specifiers):
self.specifiers = specifiers


class Distribution(setuptools.dist.Distribution):
def fetch_build_eggs(self, specifiers):
specifier_list = list(parse_requirements(specifiers))
specifier_list = list(parse_strings(specifiers))

raise SetupRequirementsError(specifier_list)

Expand Down

0 comments on commit 73e08a8

Please sign in to comment.