diff options
author | Angelos Evripiotis <jevripiotis@bloomberg.net> | 2019-08-29 11:00:03 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-10-08 08:57:25 +0000 |
commit | 4a2b573bfbeb1423a2456c5254561689c7280b9e (patch) | |
tree | f919ec210180058090855b8f2b965fad25daa614 | |
parent | d7b78ed454b63b664493167674a0e9c906ebd95c (diff) | |
download | buildstream-4a2b573bfbeb1423a2456c5254561689c7280b9e.tar.gz |
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.
-rw-r--r-- | src/buildstream/_frontend/cli.py | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py index 9abab6473..60527e698 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,22 @@ def override_completions(orig_args, cmd, cmd_param, args, incomplete): raise CompleteUnhandled() +def validate_output_streams(): + if sys.platform == 'win32': + # Windows does not support 'fcntl', the module is unavailable there as + # of Python 3.7, therefore early-out here. + return + + import fcntl + 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): @@ -210,14 +225,8 @@ 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) + # in the case that it is non-blocking. + 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 |