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

Do not fdopen() fds 1, 2 but use sys.* instead #15

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 14 additions & 2 deletions gpep517/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import functools
import importlib
import importlib.util
import io
import json
import logging
import os
Expand Down Expand Up @@ -35,8 +36,19 @@ def get_toml(path: Path):
return {}


def open_output(fd: int) -> io.FileIO:
"""Safely return file open for outputting into fd"""
if fd == 0:
raise RuntimeError("--output-fd 0 invalid")
elif fd == 1:
return contextlib.nullcontext(sys.stdout)
elif fd == 2:
return contextlib.nullcontext(sys.stderr)
return open(fd, "w")


def get_backend(args):
with os.fdopen(args.output_fd, "w") as out:
with open_output(args.output_fd) as out:
print(get_toml(args.pyproject_toml)
.get("build-system", {})
.get("build-backend", ""),
Expand Down Expand Up @@ -211,7 +223,7 @@ def safe_samefile(path, cwd):


def build_wheel(args):
with os.fdopen(args.output_fd, "w") as out:
with open_output(args.output_fd) as out:
print(build_wheel_impl(args, args.wheel_dir), file=out)
return 0

Expand Down
Loading