Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use existing requirements parser to build docs. #2602

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions build-backend/pex_build/setuptools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# We re-export all setuptools' PEP-517 build backend hooks here for the build frontend to call.
from setuptools.build_meta import * # NOQA

from pex import hashing
from pex import hashing, requirements
from pex.common import open_zip, temporary_dir
from pex.orderedset import OrderedSet
from pex.pep_376 import Hash, InstalledFile, Record
from pex.version import __version__

Expand All @@ -26,17 +27,14 @@
def get_requires_for_build_wheel(config_settings=None):
# type: (Optional[Dict[str, Any]]) -> List[str]

reqs = setuptools.build_meta.get_requires_for_build_wheel(
config_settings=config_settings
) # type: List[str]
reqs = OrderedSet(
setuptools.build_meta.get_requires_for_build_wheel(config_settings=config_settings)
) # type: OrderedSet[str]
if pex_build.INCLUDE_DOCS:
with open("docs-requirements.txt") as fp:
for raw_req in fp.readlines():
req = raw_req.strip()
if not req or req.startswith("#"):
continue
reqs.append(req)
return reqs
reqs.update(
str(req) for req in requirements.parse_requirement_file("docs-requirements.txt")
)
return list(reqs)


def build_wheel(
Expand Down
24 changes: 14 additions & 10 deletions pex/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,26 @@ def create_parse_error(msg):


@attr.s(frozen=True)
class PyPIRequirement(object):
class _ParsedRequirement(object):
line = attr.ib() # type: LogicalLine

def __str__(self):
# type: () -> str
return str(self.line.processed_text)


@attr.s(frozen=True)
class PyPIRequirement(_ParsedRequirement):
"""A requirement realized through a package index or find links repository."""

line = attr.ib() # type: LogicalLine
requirement = attr.ib() # type: Requirement
editable = attr.ib(default=False) # type: bool


@attr.s(frozen=True)
class URLRequirement(object):
class URLRequirement(_ParsedRequirement):
"""A requirement realized through a distribution archive at a fixed URL."""

line = attr.ib() # type: LogicalLine
url = attr.ib() # type: Text
requirement = attr.ib() # type: Requirement
editable = attr.ib(default=False) # type: bool
Expand All @@ -168,10 +175,9 @@ class Value(Enum.Value):


@attr.s(frozen=True)
class VCSRequirement(object):
class VCSRequirement(_ParsedRequirement):
"""A requirement realized by building a distribution from sources retrieved from a VCS."""

line = attr.ib() # type: LogicalLine
vcs = attr.ib() # type: VCS.Value
url = attr.ib() # type: Text
requirement = attr.ib() # type: Requirement
Expand Down Expand Up @@ -219,10 +225,9 @@ def parse_requirement_from_dist(


@attr.s(frozen=True)
class LocalProjectRequirement(object):
class LocalProjectRequirement(_ParsedRequirement):
"""A requirement realized by building a distribution from local sources."""

line = attr.ib() # type: LogicalLine
path = attr.ib() # type: str
extras = attr.ib(default=(), converter=attrs.str_tuple_from_iterable) # type: Tuple[str, ...]
marker = attr.ib(default=None) # type: Optional[Marker]
Expand All @@ -241,8 +246,7 @@ def as_requirement(self, dist):


@attr.s(frozen=True)
class Constraint(object):
line = attr.ib() # type: LogicalLine
class Constraint(_ParsedRequirement):
requirement = attr.ib() # type: Requirement


Expand Down