diff options
author | Angelos Evripiotis <jevripiotis@bloomberg.net> | 2019-08-29 11:00:03 +0100 |
---|---|---|
committer | Angelos Evripiotis <jevripiotis@bloomberg.net> | 2019-10-04 18:41:49 +0100 |
commit | 9407ef83b2fb282d7b5b09c582a75bcc1c3ac357 (patch) | |
tree | 7ab385ae0ebcf2127a3d76e38cab63c2eca8b12f | |
parent | 2516668ba2ad23b7149c73f2aac485603cb71536 (diff) | |
download | buildstream-aevri/no_win32_fcntl.tar.gz |
cli.py: no fcntl on Windowsaevri/no_win32_fcntl
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 | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py index 9abab6473..fa31d756f 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 |