22
22
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
# SOFTWARE.
24
24
25
- import json
26
25
import logging
27
26
import re
28
27
from collections import defaultdict
29
28
from itertools import chain
30
29
from typing import Any , Optional
31
30
31
+ import yaml
32
32
from docker .models .containers import Container
33
33
from tabulate import tabulate
34
34
@@ -61,7 +61,7 @@ def start_container(container: TrackedContainer) -> Container:
61
61
@staticmethod
62
62
def _conda_export_command (from_history : bool ) -> list [str ]:
63
63
"""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 " ]
65
65
if from_history :
66
66
cmd .append ("--from-history" )
67
67
return cmd
@@ -70,7 +70,7 @@ def installed_packages(self) -> dict[str, set[str]]:
70
70
"""Return the installed packages"""
71
71
if self .installed is None :
72
72
LOGGER .info ("Grabbing the list of installed packages ..." )
73
- self .installed = CondaPackageHelper ._packages_from_json (
73
+ self .installed = CondaPackageHelper ._parse_package_versions (
74
74
self ._execute_command (
75
75
CondaPackageHelper ._conda_export_command (from_history = False )
76
76
)
@@ -81,7 +81,7 @@ def requested_packages(self) -> dict[str, set[str]]:
81
81
"""Return the requested package (i.e. `mamba install <package>`)"""
82
82
if self .requested is None :
83
83
LOGGER .info ("Grabbing the list of manually requested packages ..." )
84
- self .requested = CondaPackageHelper ._packages_from_json (
84
+ self .requested = CondaPackageHelper ._parse_package_versions (
85
85
self ._execute_command (
86
86
CondaPackageHelper ._conda_export_command (from_history = True )
87
87
)
@@ -94,12 +94,12 @@ def _execute_command(self, command: list[str]) -> str:
94
94
return rc .output .decode ("utf-8" ) # type: ignore
95
95
96
96
@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 ]]:
98
98
"""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'
103
103
dependencies = filter (lambda x : isinstance (x , str ), dependencies )
104
104
packages_dict : dict [str , set [str ]] = dict ()
105
105
for split in map (lambda x : re .split ("=?=" , x ), dependencies ):
0 commit comments