-
Notifications
You must be signed in to change notification settings - Fork 0
/
asv_oggm_plugin.py
56 lines (46 loc) · 1.83 KB
/
asv_oggm_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import subprocess
import requests
import tempfile
import os
import logging
from asv.plugins.conda import _find_conda, Conda
from asv.console import log
from asv import util
logging.getLogger("requests").setLevel(logging.WARNING)
OGGM_CONDA_ENV_URL = ("https://raw.githubusercontent.com/OGGM/"
"OGGM-dependency-list/master/linux-64/{0}")
OGGM_CONDA_ENVS = {
"36": "oggmdev-1.2.0.201910091415_20191009_py36.yml",
"37": "oggmdev-1.2.0.201910091415_20191009_py37.yml",
}
class OggmVirtualenv(Conda):
tool_name = "oggm_conda"
def _setup(self):
log.info("Creating oggm conda environment for {0}".format(self.name))
env_file = tempfile.NamedTemporaryFile(mode="w", delete=False,
suffix=".yml")
try:
pyver = str(self._python).replace(".", "")[:2]
oggm_env = OGGM_CONDA_ENVS[pyver]
req = requests.get(OGGM_CONDA_ENV_URL.format(oggm_env))
req.raise_for_status()
for line in req.text.splitlines():
if line.startswith("prefix:"):
continue
elif line.startswith("name:"):
env_file.write("name: {0}\n".format(self.name))
else:
env_file.write(line + "\n")
env_file.close()
self._conda_channels = ["conda-forge", "defaults"]
self._conda_environment_file = env_file.name
return super()._setup()
except Exception as exc:
if os.path.isfile(env_file.name):
with open(env_file.name, "r") as f:
text = f.read()
log.info("oggm conda env create failed: in {} with:\n{}"
.format(self._path, text))
raise
finally:
os.unlink(env_file.name)