Esempio n. 1
0
def async_mount_local_lib_path(config_dir: str,
                               loop: asyncio.AbstractEventLoop) -> str:
    """Add local library to Python Path.

    This function is a coroutine.
    """
    deps_dir = os.path.join(config_dir, 'deps')
    lib_dir = yield from async_get_user_site(deps_dir, loop=loop)
    if lib_dir not in sys.path:
        sys.path.insert(0, lib_dir)
    return deps_dir
Esempio n. 2
0
def async_mount_local_lib_path(config_dir: str,
                               loop: asyncio.AbstractEventLoop) -> str:
    """Add local library to Python Path.

    This function is a coroutine.
    """
    deps_dir = os.path.join(config_dir, 'deps')
    lib_dir = yield from async_get_user_site(deps_dir, loop=loop)
    if lib_dir not in sys.path:
        sys.path.insert(0, lib_dir)
    return deps_dir
Esempio n. 3
0
def test_async_get_user_site(hass, mock_env_copy):
    """Test async get user site directory."""
    deps_dir = '/deps_dir'
    env = mock_env_copy()
    env['PYTHONUSERBASE'] = os.path.abspath(deps_dir)
    args = [sys.executable, '-m', 'site', '--user-site']
    with patch('homeassistant.util.package.asyncio.create_subprocess_exec',
               return_value=mock_async_subprocess()) as popen_mock:
        ret = yield from package.async_get_user_site(deps_dir, hass.loop)
    assert popen_mock.call_count == 1
    assert popen_mock.call_args == call(
        *args, loop=hass.loop, stdin=asyncio.subprocess.PIPE,
        stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.DEVNULL,
        env=env)
    assert ret == os.path.join(deps_dir, 'lib_dir')
Esempio n. 4
0
def test_async_get_user_site(mock_env_copy):
    """Test async get user site directory."""
    deps_dir = '/deps_dir'
    env = mock_env_copy()
    env['PYTHONUSERBASE'] = os.path.abspath(deps_dir)
    args = [sys.executable, '-m', 'site', '--user-site']
    with patch('homeassistant.util.package.asyncio.create_subprocess_exec',
               return_value=mock_async_subprocess()) as popen_mock:
        ret = yield from package.async_get_user_site(deps_dir)
    assert popen_mock.call_count == 1
    assert popen_mock.call_args == call(
        *args, stdin=asyncio.subprocess.PIPE,
        stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.DEVNULL,
        env=env)
    assert ret == os.path.join(deps_dir, 'lib_dir')