Stay organized with collections Save and categorize content based on your preferences.

PythonVirtualenvHelper

public class PythonVirtualenvHelper
extends Object

java.lang.Object
   ↳ com.android.tradefed.util.PythonVirtualenvHelper


A helper class for activating Python 3 virtual environment.

Summary

Fields

public static final String VIRTUAL_ENV

Public constructors

PythonVirtualenvHelper()

Public methods

static void activate(IRunUtil runUtil, File virtualenvDir)

Activate virtualenv for a RunUtil.

static String getPackageInstallLocation(IRunUtil runUtil, String virtualenvPath)

Gets python package install location.

static String getPythonBinDir(String virtualenvPath)

Gets python bin directory path.

Fields

VIRTUAL_ENV

public static final String VIRTUAL_ENV

Public constructors

PythonVirtualenvHelper

public PythonVirtualenvHelper ()

Public methods

activate

public static void activate (IRunUtil runUtil, 
                File virtualenvDir)

Activate virtualenv for a RunUtil.

Parameters
runUtil IRunUtil: an utility object for running virtualenv activation commands.

virtualenvDir File: a File object representing the created virtualenv directory.

getPackageInstallLocation

public static String getPackageInstallLocation (IRunUtil runUtil, 
                String virtualenvPath)

Gets python package install location.

This method will call /path/to/venv/bin/pip3 show pip and parse out package location from stdout output.

Parameters
runUtil IRunUtil: an utility object for running for running commands.

virtualenvPath String: the path to the created virtualenv directory.

Returns
String a string representing the absolute path to the location where Python packages are installed.

getPythonBinDir

public static String getPythonBinDir (String virtualenvPath)

Gets python bin directory path.

This method will check the directory existence.

Parameters
virtualenvPath String

Returns
String str, the path to the python bin directory in venv.

Throws
NullPointerException if arg virtualenvPath is null.
RuntimeException if /path/to/venv/bin does not exist.