def _capture_environment(environment, gist_slug, version): """Capture the python environment and attach it to the commit""" if environment is not None: # Check credentials if environment config exists creds = read_creds() if 'DEFAULT_CONFIG' in creds and 'environment' in creds['DEFAULT_CONFIG']: environment_config = creds['DEFAULT_CONFIG']['environment'] if not environment_config: # Disable environment capture return if environment == 'auto' and (environment_config == 'conda' or environment_config == 'pip'): environment = environment_config log('Capturing environment..') captured = False if environment == 'auto' or environment == 'conda': # Capture conda environment try: upload_conda_env(gist_slug, version) captured = True except CondaError as e: log(str(e), error=True) if not captured and (environment == 'pip' or environment == 'auto'): # Capture pip environment try: upload_pip_env(gist_slug, version) except Exception as e: log(str(e), error=True)
def test_upload_conda_env(mock_upload_file, mock_get_platform, mock_get_conda_env_name, mock_read_conda_env): with temp_directory(): mock_read_conda_env.return_value = ENV_STR with open('environment-linux.yml', 'w') as f: f.write(ENV_STR) upload_conda_env('fake_gist_slug', version=2) calls = [ mock.call(gist_slug='fake_gist_slug', file=('environment.yml', ENV_STR), version=2), mock.call(gist_slug='fake_gist_slug', file=('environment-linux.yml', ANY), version=2), mock.call(gist_slug='fake_gist_slug', file=('environment-macos.yml', ENV_STR), version=2) ] mock_upload_file.assert_has_calls(calls)