Ejemplo n.º 1
0
def activate(env_fname=None):
    """Read the conda environment file and activate the environment"""
    log(ISSUES_MSG)

    # Check for conda and get the binary path
    try:
        conda_bin = get_conda_bin()
    except:
        log(CONDA_NOT_FOUND, error=True)
        return False

    # Identify the right environment file, and exit if absent
    env_fname = identify_env_file(env_fname=env_fname)
    if env_fname is None:
        log('Failed to detect a conda environment YML file. Skipping..',
            error=True)
        return False
    else:
        log('Detected conda environment file: ' + env_fname + "\n")

    # Get the environment name from user input
    env_name = extract_env_name(env_fname=env_fname)
    if env_name is None:
        log('Environment name not provided/detected. Skipping..')
        return False

    # Activate the environment
    command = conda_bin + " activate " + env_name
    log('Copy and execte the following command (try "source activate" if "conda activate doesn\'t work" )'
        )
    print("    " + command + " \n")
Ejemplo n.º 2
0
def install(env_fname=None, env_name=None):
    """Install packages for a cloned gist"""
    # Check for conda and get the binary path
    conda_bin = get_conda_bin()

    # Identify the right environment file, and exit if absent
    env_fname = identify_env_file(env_fname=env_fname)
    if env_fname is None:
        log('Failed to detect a conda environment YML file. Skipping..',
            error=True)
        return
    else:
        log('Detected conda environment file: ' + env_fname + "\n")

    # Get the environment name from user input
    env_name = request_env_name(env_name=env_name, env_fname=env_fname)
    if env_name is None:
        log('Environment name not provided/detected. Skipping..')
        return

    # Construct the command
    command = conda_bin + ' env update --file "' + \
        env_fname + '" --name "' + env_name + '"'

    packages = extract_env_packages(env_fname=env_fname)
    if len(packages) > 0:
        success = run_command(command=command,
                              env_fname=env_fname,
                              packages=packages,
                              run=1)
        if not success:
            print('Some pip packages failed to install.')
            print_conda_message(env_name=env_name)
Ejemplo n.º 3
0
    def test_identify_env_file_exists(self):
        os.system('touch environment.yml')

        self.assertEqual(identify_env_file(env_fname=None), 'environment.yml')

        os.system('rm environment.yml')
Ejemplo n.º 4
0
 def test_identify_env_file_no_environment_file(self):
     self.assertIsNone(identify_env_file(env_fname=None))
Ejemplo n.º 5
0
def test_identify_env_file_exists():
    with fake_envfile():
        assert identify_env_file(env_fname=None) == 'environment.yml'
Ejemplo n.º 6
0
def test_identify_env_file_no_environment_file():
    with temp_directory():
        assert identify_env_file(env_fname=None) == None