Use mamba env export with --json (#2162)

This commit is contained in:
Ayaz Salikhov
2024-11-25 16:23:38 +00:00
committed by GitHub
parent 918997f709
commit ac8453913c
3 changed files with 3 additions and 5 deletions

View File

@@ -47,7 +47,6 @@ repos:
"requests", "requests",
"urllib3", "urllib3",
"types-beautifulsoup4", "types-beautifulsoup4",
"types-PyYAML",
"types-requests", "types-requests",
"types-tabulate", "types-tabulate",
"types-urllib3", "types-urllib3",

View File

@@ -6,6 +6,5 @@ pytest-retry
# `pytest-xdist` is a plugin that provides the `--numprocesses` flag, # `pytest-xdist` is a plugin that provides the `--numprocesses` flag,
# allowing us to run `pytest` tests in parallel # allowing us to run `pytest` tests in parallel
pytest-xdist pytest-xdist
PyYAML
requests requests
tabulate tabulate

View File

@@ -22,13 +22,13 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
import json
import logging import logging
import re import re
from collections import defaultdict from collections import defaultdict
from itertools import chain from itertools import chain
from typing import Any, Optional from typing import Any, Optional
import yaml
from docker.models.containers import Container from docker.models.containers import Container
from tabulate import tabulate from tabulate import tabulate
@@ -61,7 +61,7 @@ class CondaPackageHelper:
@staticmethod @staticmethod
def _conda_export_command(from_history: bool) -> list[str]: def _conda_export_command(from_history: bool) -> list[str]:
"""Return the mamba export command with or without history""" """Return the mamba export command with or without history"""
cmd = ["mamba", "env", "export", "--no-build"] cmd = ["mamba", "env", "export", "--no-build", "--json"]
if from_history: if from_history:
cmd.append("--from-history") cmd.append("--from-history")
return cmd return cmd
@@ -96,7 +96,7 @@ class CondaPackageHelper:
@staticmethod @staticmethod
def _parse_package_versions(env_export: str) -> dict[str, set[str]]: def _parse_package_versions(env_export: str) -> dict[str, set[str]]:
"""Extract packages and versions from the lines returned by the list of specifications""" """Extract packages and versions from the lines returned by the list of specifications"""
dependencies = yaml.safe_load(env_export).get("dependencies") dependencies = json.loads(env_export).get("dependencies")
# Filtering packages installed through pip # Filtering packages installed through pip
# since we only manage packages installed through mamba here # since we only manage packages installed through mamba here
# They are represented by a dict with a key 'pip' # They are represented by a dict with a key 'pip'