mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-02 10:23:25 +08:00
ardupilotwaf: drop subprocess monkeypatching for unsupported Python
Not needed now that minimum Python is 3.8.
This commit is contained in:
committed by
Thomas Watson
parent
6a0893479f
commit
98fe3547fa
@@ -20,49 +20,6 @@ import glob
|
||||
from waflib import Build, ConfigSet, Configure, Context, Utils
|
||||
from waflib.Configure import conf
|
||||
|
||||
# Ref: https://stackoverflow.com/questions/40590192/getting-an-error-attributeerror-module-object-has-no-attribute-run-while
|
||||
try:
|
||||
from subprocess import CompletedProcess
|
||||
except ImportError:
|
||||
# Python 2
|
||||
class CompletedProcess:
|
||||
|
||||
def __init__(self, args, returncode, stdout=None, stderr=None):
|
||||
self.args = args
|
||||
self.returncode = returncode
|
||||
self.stdout = stdout
|
||||
self.stderr = stderr
|
||||
|
||||
def check_returncode(self):
|
||||
if self.returncode != 0:
|
||||
err = subprocess.CalledProcessError(self.returncode, self.args, output=self.stdout)
|
||||
raise err
|
||||
return self.returncode
|
||||
|
||||
def sp_run(*popenargs, **kwargs):
|
||||
input = kwargs.pop("input", None)
|
||||
check = kwargs.pop("handle", False)
|
||||
kwargs.pop("capture_output", True)
|
||||
if input is not None:
|
||||
if 'stdin' in kwargs:
|
||||
raise ValueError('stdin and input arguments may not both be used.')
|
||||
kwargs['stdin'] = subprocess.PIPE
|
||||
process = subprocess.Popen(*popenargs, **kwargs)
|
||||
try:
|
||||
outs, errs = process.communicate(input)
|
||||
except:
|
||||
process.kill()
|
||||
process.wait()
|
||||
raise
|
||||
returncode = process.poll()
|
||||
if check and returncode:
|
||||
raise subprocess.CalledProcessError(returncode, popenargs, output=outs)
|
||||
return CompletedProcess(popenargs, returncode, stdout=outs, stderr=errs)
|
||||
|
||||
subprocess.run = sp_run
|
||||
# ^ This monkey patch allows it work on Python 2 or 3 the same way
|
||||
|
||||
|
||||
# TODO: implement a command 'waf help' that shows the basic tasks a
|
||||
# developer might want to do: e.g. how to configure a board, compile a
|
||||
# vehicle, compile all the examples, add a new example. Should fit in
|
||||
|
||||
Reference in New Issue
Block a user