ARM-software / devlib

Library for interaction with and instrumentation of remote devices.
Apache License 2.0
47 stars 78 forks source link

Importing devlib package requires ANDROID_HOME or adb in PATH #660

Closed douglas-raillard-arm closed 10 months ago

douglas-raillard-arm commented 10 months ago

An unintended consequence of the tool detection cleanup PR is that the tool detection is performed as soon as the "variable" containing the path is accessed. Unfortunately, imports are not lazy and therefore constitute such an access:

  File "/home/docs/checkouts/readthedocs.org/user_builds/lisa-linux-integrated-system-analysis/checkouts/main/external/devlib/devlib/__init__.py", line 16, in <module>
    from devlib.target import Target, LinuxTarget, AndroidTarget, LocalLinuxTarget, ChromeOsTarget
  File "/home/docs/checkouts/readthedocs.org/user_builds/lisa-linux-integrated-system-analysis/checkouts/main/external/devlib/devlib/target.py", line 60, in <module>
    from devlib.utils.android import AdbConnection, AndroidProperties, LogcatMonitor, adb_command, adb_disconnect, INTENT_FLAGS
  File "/home/docs/checkouts/readthedocs.org/user_builds/lisa-linux-integrated-system-analysis/checkouts/main/external/devlib/devlib/utils/android.py", line 93, in __getattr__
    env = _AndroidEnvironment()
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/lisa-linux-integrated-system-analysis/checkouts/main/external/devlib/devlib/utils/android.py", line 788, in __init__
    paths = self._from_adb()
            ^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/lisa-linux-integrated-system-analysis/checkouts/main/external/devlib/devlib/utils/android.py", line 822, in _from_adb
    raise HostError('ANDROID_HOME is not set and adb is not in PATH. '
devlib.exception.HostError: ANDROID_HOME is not set and adb is not in PATH. Have you installed Android SDK?

It also seems I overlooked that note in the Python doc:

Note

Defining module __getattr__ and setting module __class__ only affect lookups made using the attribute access syntax – directly accessing the module globals (whether by code within the module, or via a reference to the module’s globals dictionary) is unaffected. 

So I'll need to fix that up, probably with just some sort of namespace object with memoized properties attributes rather than a module-level __getattr__. I'll try to make a PR tomorrow