You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 08:22:38 UTC
[buildstream] 02/25: cli.py: no fcntl on Windows
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch aevri/win32_minimal
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 887522d3dff2d3c5be30415696db6437ba2db6aa
Author: Angelos Evripiotis <je...@bloomberg.net>
AuthorDate: Thu Aug 29 11:00:03 2019 +0100
cli.py: no fcntl on Windows
Work around the fact that we can't import 'fcntl' on Windows, and
confine the workaround to as small a scope as we can.
This enables us to run at least these commands on Windows:
bst help
bst init
We can't run any commands that require a Platform object though, which
is most commands.
---
src/buildstream/_frontend/cli.py | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py
index 931f531..a0cf948 100644
--- a/src/buildstream/_frontend/cli.py
+++ b/src/buildstream/_frontend/cli.py
@@ -2,7 +2,6 @@ import multiprocessing
import os
import sys
from functools import partial
-import fcntl
import shutil
import click
@@ -187,6 +186,26 @@ def override_completions(orig_args, cmd, cmd_param, args, incomplete):
raise CompleteUnhandled()
+def validate_output_streams():
+ try:
+ import fcntl
+ except ImportError:
+ # When we move onto Python 3.6+, we'll probably want to check for
+ # ModuleNotFoundError instead, as that's more specifically the problem
+ # we're working around.
+ if sys.platform != 'win32':
+ raise
+ return
+
+ for stream in (sys.stdout, sys.stderr):
+ fileno = stream.fileno()
+ flags = fcntl.fcntl(fileno, fcntl.F_GETFL)
+ if flags & os.O_NONBLOCK:
+ click.echo("{} is currently set to O_NONBLOCK, try opening a new shell"
+ .format(stream.name), err=True)
+ sys.exit(-1)
+
+
def override_main(self, args=None, prog_name=None, complete_var=None,
standalone_mode=True, **extra):
@@ -211,13 +230,7 @@ def override_main(self, args=None, prog_name=None, complete_var=None,
# Check output file descriptor at earliest opportunity, to
# provide a reasonable error message instead of a stack trace
# in the case that it is blocking
- for stream in (sys.stdout, sys.stderr):
- fileno = stream.fileno()
- flags = fcntl.fcntl(fileno, fcntl.F_GETFL)
- if flags & os.O_NONBLOCK:
- click.echo("{} is currently set to O_NONBLOCK, try opening a new shell"
- .format(stream.name), err=True)
- sys.exit(-1)
+ validate_output_streams()
# We can only set the global multiprocessing start method once; for that
# reason we're advised to do it inside the entrypoint, where it is easy to