Exemplo n.º 1
0
def get_azdev_config_dir():
    """ Returns the user's .azdev directory. """
    from azdev.utilities import get_env_path
    env_name = None
    if not get_env_path():
        _, env_name = os.path.splitdrive(sys.executable)
    else:
        _, env_name = os.path.splitdrive(get_env_path())

    azdev_dir = os.getenv('AZDEV_CONFIG_DIR', None) or os.path.expanduser(
        os.path.join('~', '.azdev'))
    if not env_name:
        return azdev_dir
    return os.path.join(azdev_dir, 'env_config') + env_name
Exemplo n.º 2
0
def require_virtual_env():
    from azdev.utilities import get_env_path

    env = get_env_path()
    if not env:
        raise CLIError(
            'This command can only be run from an active virtual environment.')
Exemplo n.º 3
0
def _check_env(set_env):
    if not set_env:
        if not get_env_path():
            raise CLIError(
                'You are not running in a virtual enviroment and have not chosen to set one up.'
            )
        _check_pyenv()
    elif 'VIRTUAL_ENV' in os.environ:
        raise CLIError(
            "You are already running in a virtual enviroment, yet you want to set a new one up"
        )
Exemplo n.º 4
0
def require_virtual_env():
    from azdev.utilities import get_env_path

    env = get_env_path()
    if not env:
        raise CLIError('This command can only be run from an active virtual environment.')
    if not os.environ.get(const.AZ_CONFIG_DIR):
        raise CLIError(
            "AZURE_CONFIG_DIR env var is not set. Please run 'azdev setup'")
    if not os.path.exists(os.path.join(os.environ[const.AZ_CONFIG_DIR], "config")):
        raise CLIError(
            "The Azure config file does not exist. Please run 'azdev setup'")
Exemplo n.º 5
0
def py_cmd(command, message=False, show_stderr=True, is_module=True, **kwargs):
    """ Run a script or command with Python.

    :param command: The arguments to run python with.
    :param message: A custom message to display, or True (bool) to use a default.
    :param show_stderr: On error, display the contents of STDERR.
    :param is_module: Run a Python module as a script with -m.
    :param kwargs: Any kwargs supported by subprocess.Popen
    :returns: CommandResultItem object.
    """
    from azdev.utilities import get_env_path
    env_path = get_env_path()
    python_bin = sys.executable if not env_path else os.path.join(
        env_path, 'Scripts' if sys.platform == 'win32' else 'bin', 'python')
    if is_module:
        command = '{} -m {}'.format(python_bin, command)
    else:
        command = '{} {}'.format(python_bin, command)
    return cmd(command, message, show_stderr, **kwargs)