Skip to content

Commit

Permalink
conda_init()
Browse files Browse the repository at this point in the history
  • Loading branch information
scopatz committed Sep 10, 2020
1 parent 3691ffd commit 8df0504
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
23 changes: 23 additions & 0 deletions news/rm-xonda.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* New, reentrant ``conda.conda_init()`` function enables ``conda activate``.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Fixed conda activation by removing dependence on xonda.

**Security:**

* <news item>
1 change: 0 additions & 1 deletion rever.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ with open('requirements/docs.txt') as f:
$DOCKER_CONDA_DEPS += f.read().split()
$DOCKER_CONDA_DEPS = [d.lower() for d in set($DOCKER_CONDA_DEPS)]
$DOCKER_APT_DEPS = ['file']
$DOCKER_PIP_DEPS = ['xonda']
$DOCKER_INSTALL_COMMAND = 'git clean -fdx && ./setup.py install'
$DOCKER_GIT_NAME = 'rever'
$DOCKER_GIT_EMAIL = 'rever@example.com'
17 changes: 17 additions & 0 deletions rever/conda.xsh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import sys
import json
from types import ModuleType
from contextlib import contextmanager


Expand All @@ -13,6 +15,20 @@ def env_exists(envname):
return False


def conda_init():
"""Initializes conda, if needed. This may safely be called many times."""
if "xontrib.conda" in sys.modules:
return
mod = ModuleType("xontrib.conda",
"Autogenerated from $(conda shell.xonsh hook)")
__xonsh__.execer.exec(
$(conda shell.xonsh hook),
glbs=mod.__dict__,
filename="$(conda shell.xonsh hook)"
)
sys.modules["xontrib.conda"] = mod


@contextmanager
def run_in_conda_env(packages, envname='rever-env'):
"""
Expand All @@ -29,6 +45,7 @@ def run_in_conda_env(packages, envname='rever-env'):
if env_exists(envname):
conda remove -y -n @(envname) --all
conda create -y -n @(envname) @(packages)
conda_init()
conda activate @(envname)
yield
finally:
Expand Down

0 comments on commit 8df0504

Please sign in to comment.