Bug 216396 - [webkitcorepy] Disable AutoInstaller with environment variable
Summary: [webkitcorepy] Disable AutoInstaller with environment variable
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-09-10 19:38 PDT by Jonathan Bedard
Modified: 2020-09-14 13:22 PDT (History)
4 users (show)

See Also:


Attachments
Patch (3.87 KB, patch)
2020-09-10 19:45 PDT, Jonathan Bedard
no flags Details | Formatted Diff | Diff
Patch (4.01 KB, patch)
2020-09-11 13:41 PDT, Jonathan Bedard
no flags Details | Formatted Diff | Diff
Patch (2.92 KB, patch)
2020-09-14 11:15 PDT, Jonathan Bedard
no flags 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-09-10 19:38:10 PDT
Feature request from Dean Johnson to be able to disable the AutoInstaller with an environment variable.
Comment 1 Radar WebKit Bug Importer 2020-09-10 19:38:32 PDT
<rdar://problem/68680933>
Comment 2 Jonathan Bedard 2020-09-10 19:45:22 PDT
Created attachment 408508 [details]
Patch
Comment 3 Dean Johnson 2020-09-11 10:14:44 PDT
Comment on attachment 408508 [details]
Patch

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

Unofficial r+ with some simplification of enable/disable.

> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py:300
> +    _ENVIRONMENT_VARIABLE = 'WEBKITCOREPY_AUTOINSTALL'

Nit: Can we make the name of the variable and env far more descriptive? e.g.
_ENVIRONMENT_VARIABLE -> ENABLED_ENV_VAR
WEBKITCOREPY_AUTOINSTALL -> DISABLE_WEBKITCOREPY_AUTOINSTALLER

It would also require inverting the checks below, but since the default for the auto installer is "enabled" I think including "disable" in the envvar is important.

> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py:303
>      enabled = False

Why does this value default to False if it's actually enabled when it's imported/used?

> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py:335
>      def enable(cls):

I think it'd be cleaner to just use one function / check for this and name it 'enabled'. I can't really think of a use-case where you'd want to enable, then disable, in the same runtime (other than testing, in which case you can mock).

> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py:336
> +        if cls._enabled_variable() is False:

An example of this is:
```
@classmethod
def enabled(cls):
    if os.environ.get(cls._ENVIRONMENT_VARIABLE) in ['0', 'FALSE', 'false', 'NO', 'no']:
        return False
    return True
```

> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py:387
> +        if cls._enabled_variable() is False:

Nit: I found in local testing that doing an early return in AutoInstaller.register allowed me to skip all of the auto installer, does this accomplish the same thing? I think it might be better to do the check in `register` since it's the function most likely to be first looked at by a client when looking into issues. This is just a preference though and doesn't need to change.
Comment 4 Jonathan Bedard 2020-09-11 13:04:44 PDT
Comment on attachment 408508 [details]
Patch

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

>> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py:303
>>      enabled = False
> 
> Why does this value default to False if it's actually enabled when it's imported/used?

Because the AutoInstaller needs to have a target directory set before it's enabled. webkitpy enables the Autoinstaller when it's imported, but that's a decision that's up to our client programs.

>> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py:335
>>      def enable(cls):
> 
> I think it'd be cleaner to just use one function / check for this and name it 'enabled'. I can't really think of a use-case where you'd want to enable, then disable, in the same runtime (other than testing, in which case you can mock).

Good point, I think removing "enable" and "disable" will go a long way to clarifying this patch.

>> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py:387
>> +        if cls._enabled_variable() is False:
> 
> Nit: I found in local testing that doing an early return in AutoInstaller.register allowed me to skip all of the auto installer, does this accomplish the same thing? I think it might be better to do the check in `register` since it's the function most likely to be first looked at by a client when looking into issues. This is just a preference though and doesn't need to change.

Registered packages won't be installed if we don't have a directory to install them to. I think we still want to be able to iterate through all packages the AutoInstaller has registered for a give script or configuration. Among other things, it would let us generate a version locked requirements.txt.
Comment 5 Jonathan Bedard 2020-09-11 13:41:53 PDT
Created attachment 408559 [details]
Patch
Comment 6 Dean Johnson 2020-09-11 16:42:10 PDT
Comment on attachment 408559 [details]
Patch

Unofficial r+; LGTM. Thanks for doing this!
Comment 7 dewei_zhu 2020-09-11 17:02:31 PDT
Comment on attachment 408559 [details]
Patch

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

> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py:326
> +        if os.environ.get(cls.DISABLE_ENV_VAR) not in ['0', 'FALSE', 'false', 'NO', 'no', None]:

Should we also consider to add 'No' and 'False' which seem quite common as well?
Comment 8 Jonathan Bedard 2020-09-14 09:33:35 PDT
(In reply to dewei_zhu from comment #7)
> Comment on attachment 408559 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=408559&action=review
> 
> > Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py:326
> > +        if os.environ.get(cls.DISABLE_ENV_VAR) not in ['0', 'FALSE', 'false', 'NO', 'no', None]:
> 
> Should we also consider to add 'No' and 'False' which seem quite common as
> well?

Will add! Also, waiting on https://bugs.webkit.org/show_bug.cgi?id=216480 so that we can log everything in the same way.
Comment 9 EWS 2020-09-14 10:10:44 PDT
Committed r267019: <https://trac.webkit.org/changeset/267019>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 408559 [details].
Comment 10 Jonathan Bedard 2020-09-14 10:12:03 PDT
(In reply to EWS from comment #9)
> Committed r267019: <https://trac.webkit.org/changeset/267019>
> 
> All reviewed patches have been landed. Closing bug and clearing flags on
> attachment 408559 [details].

Oops, meant to land https://bugs.webkit.org/show_bug.cgi?id=216480 first, going to need a follow-up fix here....
Comment 11 Jonathan Bedard 2020-09-14 11:15:11 PDT
Reopening to attach new patch.
Comment 12 Jonathan Bedard 2020-09-14 11:15:12 PDT
Created attachment 408728 [details]
Patch
Comment 13 EWS 2020-09-14 13:22:24 PDT
Committed r267035: <https://trac.webkit.org/changeset/267035>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 408728 [details].