Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix finding mamba on windows #135

Merged
merged 6 commits into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Test the server extension
run: |
conda activate test_gator
python -m pytest mamba_gator
python -m pytest -ra mamba_gator
shell: bash -l {0}

test-backend-mamba:
Expand Down Expand Up @@ -77,21 +77,22 @@ jobs:
activate-environment: test_gator
auto-update-conda: true
channels: conda-forge
mamba-version: "*"
python-version: ${{ matrix.python-version }}
show-channel-urls: true
use-only-tar-bz2: true
- name: Install dependencies
run: |
conda activate test_gator
conda install -n test_gator --file requirements_dev.txt
mamba install -n test_gator --file requirements_dev.txt
python setup.py develop --skip-npm
# Check pip dependencies
python -m pip check
shell: bash -l {0}
- name: Test the server extension
run: |
conda activate test_gator
python -m pytest mamba_gator
python -m pytest -ra mamba_gator
shell: bash -l {0}

test-all-os:
Expand Down Expand Up @@ -220,7 +221,7 @@ jobs:
run: |
conda activate test_gator
mamba install -n test_gator --file requirements_dev.txt
conda install -n test_gator coveralls jupyterlab=3
mamba install -n test_gator coveralls jupyterlab=3
yarn install
python -m pip install -e .
# Check pip dependencies
Expand All @@ -239,10 +240,13 @@ jobs:
coverage report
yarn run test

jupyter serverextension list 1>serverextensions 2>&1
cat serverextensions | grep "mamba_gator.*OK"
jupyter labextension list 1>labextensions 2>&1
cat labextensions | grep "@mamba-org/gator-lab.*OK"
jupyter serverextension list
jupyter serverextension list 2>&1 | grep "mamba_gator.*OK"

jupyter server extension list
jupyter server extension list 2>&1 | grep "mamba_gator.*OK"
jupyter labextension list
jupyter labextension list 2>&1 | grep "@mamba-org/gator-lab.*OK"
python -m jupyterlab.browser_check
shell: bash -l {0}

Expand Down
10 changes: 5 additions & 5 deletions mamba_gator/envmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,20 @@ def manager(self) -> str:
# Set conda by default
EnvManager._manager_exe = CONDA_EXE
try:
which = "which"
cmd = ["which", "mamba"]
if sys.platform == "win32":
which = "where"
cmd = ["where", "mamba.exe"]

process = Popen(
[which, "mamba"], stdout=PIPE, stderr=PIPE, encoding="utf-8"
cmd, stdout=PIPE, stderr=PIPE, encoding="utf-8"
)
output, error = process.communicate()

if process.returncode != 0:
raise RuntimeError(error)

mamba_exe = output.strip() or "mamba"
mamba_exe = output.splitlines()[0] or "mamba"

process = Popen(
[mamba_exe, "--version"],
stdout=PIPE,
Expand Down
12 changes: 11 additions & 1 deletion mamba_gator/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from mamba_gator.handlers import AVAILABLE_CACHE, PackagesHandler
from mamba_gator.tests.utils import ServerTest, assert_http_error

from .utils import has_mamba


def generate_name() -> str:
"""Generate a random name."""
Expand All @@ -36,7 +38,6 @@ def setUp(self):
def tearDown(self):
# Remove created environment
for n in self.env_names:
print(self.env_names, self.conda_api.envs())
self.wait_for_task(self.rm_env, n)
super(JupyterCondaAPITest, self).tearDown()

Expand Down Expand Up @@ -263,6 +264,9 @@ def test_env_clone(self):
self.wait_for_task(self.rm_env, n)

def test_environment_yaml_import(self):
if has_mamba:
self.skipTest("FIXME not working with mamba")

n = generate_name()
self.env_names.append(n)
build = {"linux": "h0371630_0", "win32": "h8c8aaf0_1", "darwin": "h359304d_0"}
Expand Down Expand Up @@ -351,6 +355,9 @@ def g():
self.assertIn(p, packages, "{} not found.".format(p))

def test_update_env_yaml(self):
if has_mamba:
self.skipTest("FIXME not working with mamba")

n = generate_name()
response = self.wait_for_task(self.mk_env, n, ["python=3.7",])
self.assertEqual(response.status_code, 200)
Expand Down Expand Up @@ -391,6 +398,9 @@ def g():
self.assertIn(p, packages, "{} not found.".format(p))

def test_update_env_no_filename(self):
if has_mamba:
self.skipTest("FIXME not working with mamba")

n = generate_name()
response = self.wait_for_task(self.mk_env, n, ["python=3.7",])
self.assertEqual(response.status_code, 200)
Expand Down
20 changes: 20 additions & 0 deletions mamba_gator/tests/test_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pathlib import Path

import pytest
from mamba_gator.envmanager import EnvManager

from .utils import has_mamba


@pytest.mark.skipif(has_mamba, reason="Mamba found")
def test_EnvManager_manager_conda():
manager = EnvManager("", None)

assert Path(manager.manager).stem == "conda"


@pytest.mark.skipif(not has_mamba, reason="Mamba NOT found")
def test_EnvManager_manager_mamba():
manager = EnvManager("", None)

assert Path(manager.manager).stem == "mamba"
22 changes: 13 additions & 9 deletions mamba_gator/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import time
from binascii import hexlify
from subprocess import CalledProcessError, check_call
from threading import Event, Thread
from typing import List
from unittest import TestCase
Expand All @@ -13,11 +14,10 @@
import jupyter_core.paths
import requests
from ipython_genutils.tempdir import TemporaryDirectory
from mamba_gator.handlers import NS
from tornado.ioloop import IOLoop
from traitlets.config import Config

from mamba_gator.handlers import NS

# Shim for notebook server or jupyter_server
#
# Provides:
Expand All @@ -27,23 +27,27 @@
# - url_path_join

try:
from notebook.tests.launchnotebook import (
assert_http_error,
NotebookTestBase as ServerTestBase,
)
from notebook.utils import url_escape, url_path_join
from notebook.notebookapp import NotebookApp as ServerApp
from notebook.tests.launchnotebook import NotebookTestBase as ServerTestBase
from notebook.tests.launchnotebook import assert_http_error
from notebook.utils import url_escape, url_path_join
except ImportError:
from jupyter_server.serverapp import ServerApp # noqa
from jupyter_server.tests.launchnotebook import assert_http_error # noqa
from jupyter_server.tests.launchserver import ServerTestBase # noqa
from jupyter_server.utils import url_escape, url_path_join # noqa
from jupyter_server.serverapp import ServerApp # noqa



TIMEOUT = 150
SLEEP = 1

try:
check_call(["mamba", "--version"])
except (CalledProcessError, FileNotFoundError):
has_mamba = False
else:
has_mamba = True


class APITester(object):
"""Wrapper for REST API requests"""
Expand Down