Skip to content

Commit

Permalink
Merge 65328e2 into fb97583
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Dec 6, 2020
2 parents fb97583 + 65328e2 commit 1887d7c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ sense to move the project in the `mamba-org` organization.
### 4.1.0

- Features
- Dependencies graph (by clicking on the installed version for now)
- Dependencies graph (by clicking on the installed version for now) [#83](https://github.com/mamba-org/gator/issues/83)
- Bug fix
- Fix missing classical notebook extension
- Fix missing classical notebook extension [#115](https://github.com/mamba-org/gator/issues/115)
- Fix mamba not detected on Windows [#119](https://github.com/mamba-org/gator/issues/119)

### 4.0.0

Expand Down
71 changes: 47 additions & 24 deletions mamba_gator/envmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
import tempfile
from functools import partial
from pathlib import Path
from subprocess import PIPE, Popen
from typing import Any, Dict, List, Optional, Tuple, Union

Expand Down Expand Up @@ -70,10 +71,10 @@ def normalize_pkg_info(s: Dict[str, Any]) -> Dict[str, Union[str, List[str]]]:

def get_env_path(kernel_spec: Dict[str, Any]) -> Optional[str]:
"""Get the conda environment path.
Args:
kernel_spec (dict): Kernel spec
Returns:
str: Best guess for the environment path
"""
Expand Down Expand Up @@ -183,32 +184,50 @@ def manager(self) -> str:
"""Conda package manager name.
For now, use mamba if it is installed. Otherwise, fallback to conda.
Returns:
str: Package manager
"""
if EnvManager._manager_exe is None:
# Set conda by default
EnvManager._manager_exe = CONDA_EXE
try:
process = Popen(["mamba", "--version"], stdout=PIPE, stderr=PIPE)
which = "which"
if sys.platform == "win32":
which = "where"

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

if process.returncode != 0:
raise RuntimeError(error.decode("utf-8"))
raise RuntimeError(error)

mamba_exe = output.strip()
if mamba_exe:
process = Popen(
[mamba_exe, "--version"],
stdout=PIPE,
stderr=PIPE,
encoding="utf-8",
)
output, error = process.communicate()

versions = list(
map(lambda l: l.split(), output.decode("utf-8").splitlines())
)
if versions[0][0] == "mamba" and versions[1][0] == "conda":
EnvManager._conda_version = versions[1][1]
EnvManager._mamba_version = versions[0][1]
EnvManager._manager_exe = "mamba"
if process.returncode != 0:
raise RuntimeError(error)

versions = list(map(lambda l: l.split(), output.splitlines()))
if versions[0][0] == "mamba" and versions[1][0] == "conda":
EnvManager._conda_version = versions[1][1]
EnvManager._mamba_version = versions[0][1]
EnvManager._manager_exe = mamba_exe

except BaseException:
self.log.debug(
"Fail to get mamba version, falling back to conda",
exc_info=sys.exc_info(),
)
EnvManager._manager_exe = CONDA_EXE

self.log.debug("Package manager: {}".format(EnvManager._manager_exe))

Expand Down Expand Up @@ -533,23 +552,27 @@ async def pkg_depends(self, pkg: str) -> Dict[str, List[str]]:
Returns:
{"package": List[dependencies]}
"""
if self.manager != "mamba" :
self.log.warning("Package manager '{}' does not support dependency query.".format(self.manager))
return { pkg: None }
if Path(self.manager).stem != "mamba":
self.log.warning(
"Package manager '{}' does not support dependency query.".format(
self.manager
)
)
return {pkg: None}

resp = {}
ans = await self._execute(self.manager, "repoquery", "depends", "--json", pkg)
_, output = ans
query = self._clean_conda_json(output)

if "error" not in query:
for dep in query['result']['pkgs'] :
if type(dep) is dict :
deps = dep.get('depends', None)
if deps :
resp[dep['name']] = deps
else :
resp[dep['name']] = []
for dep in query["result"]["pkgs"]:
if type(dep) is dict:
deps = dep.get("depends", None)
if deps:
resp[dep["name"]] = deps
else:
resp[dep["name"]] = []

return resp

Expand Down

0 comments on commit 1887d7c

Please sign in to comment.