Skip to content

Commit 41d0c3f

Browse files
authored
Use mamba env export differently: --no-build(s) and no --json (#2150)
1 parent 640938b commit 41d0c3f

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ repos:
4747
"requests",
4848
"urllib3",
4949
"types-beautifulsoup4",
50+
"types-PyYAML",
5051
"types-requests",
5152
"types-tabulate",
5253
"types-urllib3",

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ pytest-retry
66
# `pytest-xdist` is a plugin that provides the `--numprocesses` flag,
77
# allowing us to run `pytest` tests in parallel
88
pytest-xdist
9+
PyYAML
910
requests
1011
tabulate

tests/package_helper.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
# SOFTWARE.
2424

25-
import json
2625
import logging
2726
import re
2827
from collections import defaultdict
2928
from itertools import chain
3029
from typing import Any, Optional
3130

31+
import yaml
3232
from docker.models.containers import Container
3333
from tabulate import tabulate
3434

@@ -61,7 +61,7 @@ def start_container(container: TrackedContainer) -> Container:
6161
@staticmethod
6262
def _conda_export_command(from_history: bool) -> list[str]:
6363
"""Return the mamba export command with or without history"""
64-
cmd = ["mamba", "env", "export", "-n", "base", "--json", "--no-builds"]
64+
cmd = ["mamba", "env", "export", "--no-build"]
6565
if from_history:
6666
cmd.append("--from-history")
6767
return cmd
@@ -70,7 +70,7 @@ def installed_packages(self) -> dict[str, set[str]]:
7070
"""Return the installed packages"""
7171
if self.installed is None:
7272
LOGGER.info("Grabbing the list of installed packages ...")
73-
self.installed = CondaPackageHelper._packages_from_json(
73+
self.installed = CondaPackageHelper._parse_package_versions(
7474
self._execute_command(
7575
CondaPackageHelper._conda_export_command(from_history=False)
7676
)
@@ -81,7 +81,7 @@ def requested_packages(self) -> dict[str, set[str]]:
8181
"""Return the requested package (i.e. `mamba install <package>`)"""
8282
if self.requested is None:
8383
LOGGER.info("Grabbing the list of manually requested packages ...")
84-
self.requested = CondaPackageHelper._packages_from_json(
84+
self.requested = CondaPackageHelper._parse_package_versions(
8585
self._execute_command(
8686
CondaPackageHelper._conda_export_command(from_history=True)
8787
)
@@ -94,12 +94,12 @@ def _execute_command(self, command: list[str]) -> str:
9494
return rc.output.decode("utf-8") # type: ignore
9595

9696
@staticmethod
97-
def _packages_from_json(env_export: str) -> dict[str, set[str]]:
97+
def _parse_package_versions(env_export: str) -> dict[str, set[str]]:
9898
"""Extract packages and versions from the lines returned by the list of specifications"""
99-
# dependencies = filter(lambda x: isinstance(x, str), json.loads(env_export).get("dependencies"))
100-
dependencies = json.loads(env_export).get("dependencies")
101-
# Filtering packages installed through pip in this case it's a dict {'pip': ['toree==0.3.0']}
102-
# Since we only manage packages installed through mamba here
99+
dependencies = yaml.safe_load(env_export).get("dependencies")
100+
# Filtering packages installed through pip
101+
# since we only manage packages installed through mamba here
102+
# They are represented by a dict with a key 'pip'
103103
dependencies = filter(lambda x: isinstance(x, str), dependencies)
104104
packages_dict: dict[str, set[str]] = dict()
105105
for split in map(lambda x: re.split("=?=", x), dependencies):

0 commit comments

Comments
 (0)