Bug 215702 - [webkitcorepy] Add subprocess_utils.run
Summary: [webkitcorepy] Add subprocess_utils.run
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jonathan Bedard
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-08-20 09:52 PDT by Jonathan Bedard
Modified: 2020-08-20 12:42 PDT (History)
5 users (show)

See Also:


Attachments
Patch (11.89 KB, patch)
2020-08-20 09:56 PDT, Jonathan Bedard
no flags Details | Formatted Diff | Diff
Patch for landing (11.48 KB, patch)
2020-08-20 12:01 PDT, Jonathan Bedard
dewei_zhu: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Bedard 2020-08-20 09:52:28 PDT
Python 3's subprocess.run API is great. We should have it in Python 2 as well so we can write modern Python code compatible with both versions.
Comment 1 Radar WebKit Bug Importer 2020-08-20 09:52:48 PDT
<rdar://problem/67487751>
Comment 2 Jonathan Bedard 2020-08-20 09:56:06 PDT
Created attachment 406938 [details]
Patch
Comment 3 dewei_zhu 2020-08-20 11:32:56 PDT
Comment on attachment 406938 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=406938&action=review

> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/subprocess_utils.py:39
> +        input = kwargs.pop('input', None)
> +        capture_output = kwargs.pop('capture_output', False)
> +        timeout = kwargs.pop('timeout', None)
> +        check = kwargs.pop('check', False)

Other than timeout, is there any reason we want to extract other variables out of **kwargs? It looks like the same defaults in the subprocess.run

> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/subprocess_utils.py:54
> +                return subprocess.run(*popenargs, input=input, capture_output=capture_output, timeout=timeout, check=check, **kwargs)
> +            return subprocess.run(
> +                *popenargs,
> +                input=input,
> +                capture_output=capture_output,
> +                timeout=min(timeout or sys.maxsize, int(math.ceil(difference))),
> +                check=check,
> +                **kwargs)

So the only difference is timeout, maybe we can simplify this by doing:
if difference:
    timeout = min(timeout or sys.maxsize, int(math.ceil(difference)))
return subprocess.run(*popenargs, input=input, capture_output=capture_output, timeout=timeout, check=check, **kwargs)
Comment 4 Jonathan Bedard 2020-08-20 11:58:22 PDT
Comment on attachment 406938 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=406938&action=review

>> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/subprocess_utils.py:39
>> +        check = kwargs.pop('check', False)
> 
> Other than timeout, is there any reason we want to extract other variables out of **kwargs? It looks like the same defaults in the subprocess.run

Was copying from the function subprocess.run declaration, turns out, no, we don't need to extract the other variables. I thought we needed it to get the correct defaults, for some reason, but we don't.

Will Remove.

>> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/subprocess_utils.py:54
>> +                **kwargs)
> 
> So the only difference is timeout, maybe we can simplify this by doing:
> if difference:
>     timeout = min(timeout or sys.maxsize, int(math.ceil(difference)))
> return subprocess.run(*popenargs, input=input, capture_output=capture_output, timeout=timeout, check=check, **kwargs)

Thanks for the suggestion! Much cleaner!
Comment 5 Jonathan Bedard 2020-08-20 12:01:36 PDT
Created attachment 406952 [details]
Patch for landing
Comment 6 EWS 2020-08-20 12:32:08 PDT
Committed r265957: <https://trac.webkit.org/changeset/265957>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 406952 [details].
Comment 7 dewei_zhu 2020-08-20 12:42:56 PDT
r=me