Skip to content

Commit

Permalink
Ruamel dependency (#31)
Browse files Browse the repository at this point in the history
* Fix bug that prevented file writing, bump version

* Fix bug where pip wasn't properly being added. Simplify env_deps in
manifest class

* Add function for writing yaml, add test for same

* Bump version

* Change dependency from pyyaml to ruamel.yaml
  • Loading branch information
tylerpotts authored Nov 18, 2021
1 parent 9db0938 commit 0df4d53
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 37 deletions.
4 changes: 3 additions & 1 deletion conda_vendor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
)
from conda_vendor.version import __version__
from conda_vendor.manifest import combine_metamanifests, write_combined_manifest
import yaml

from ruamel.yaml import YAML

import logging

logger = logging.getLogger(__name__)
Expand Down
6 changes: 4 additions & 2 deletions conda_vendor/conda_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path

import requests
import yaml
from ruamel.yaml import YAML
from conda_lock.conda_lock import solve_specs_for_arch
from conda_lock.src_parser.environment_yaml import parse_environment_file
from requests.adapters import HTTPAdapter
Expand Down Expand Up @@ -37,7 +37,9 @@ def __init__(self, *, channel_root=Path(), meta_manifest_path=None):

def load_manifest(self, manifest_path):
with open(manifest_path) as f:
return yaml.load(f, Loader=yaml.SafeLoader)
return YAML(typ="safe").load(
f,
)

def fetch_and_filter_repodata(self, conda_subdir, manifest_subset_metadata):
# returns a channel specific repodata.json
Expand Down
11 changes: 8 additions & 3 deletions conda_vendor/custom_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from abc import ABC, abstractmethod
from pathlib import Path

import yaml
from ruamel.yaml import YAML

logger = logging.getLogger(__name__)

Expand All @@ -18,7 +18,9 @@ def __init__(self, manifest_path=Path()):

def read_meta_manifest(self, manifest_path):
with open(self.manifest_path) as f:
return yaml.load(f, Loader=yaml.SafeLoader)
return YAML(typ="safe").load(
f,
)

@abstractmethod
def write_custom_manifest(self, output_path=None):
Expand All @@ -38,7 +40,10 @@ def write_custom_manifest(self, output_file_path=None):

logger.info(f"Output Custom Manifest : {str(output_file_path.absolute())}")
with open(output_file_path, "w") as f:
yaml.dump(self.custom_manifest, f, sort_keys=False)
YAML().dump(
self.custom_manifest,
f,
)

@staticmethod
def strip_lead_underscore(in_str):
Expand Down
13 changes: 9 additions & 4 deletions conda_vendor/env_yaml_from_manifest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

import yaml
from ruamel.yaml import YAML
from ruamel.yaml import YAML


class YamlFromManifest:
Expand All @@ -10,7 +10,9 @@ def __init__(self, channel_root, meta_manifest_path=Path()):

def load_manifest(self, meta_manifest_path):
with open(meta_manifest_path) as f:
return yaml.load(f, Loader=yaml.SafeLoader)
return YAML(typ="safe").load(
f,
)

def get_packages_from_manifest(self):
i_bank_pkg_list = []
Expand Down Expand Up @@ -40,5 +42,8 @@ def create_yaml(self, channel_root, env_name):
}
fn = channel_root / f"local_{env_name}.yaml"
with open(fn, "w") as f:
yaml.dump(env_yaml, f, sort_keys=False)
YAML().dump(
env_yaml,
f,
)
return env_yaml
19 changes: 14 additions & 5 deletions conda_vendor/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import struct
import sys
from pathlib import Path

from ruamel.yaml import YAML
import requests
import yaml
from conda_lock.conda_lock import solve_specs_for_arch
from conda_lock.src_parser.environment_yaml import parse_environment_file
from requests.adapters import HTTPAdapter
Expand Down Expand Up @@ -118,7 +117,10 @@ def create_manifest(self, *, manifest_filename=None):
outpath_file_name = self.manifest_root / cleaned_name
logger.info(f"Creating Manifest {outpath_file_name.absolute()}")
with open(outpath_file_name, "w") as f:
yaml.dump(manifest, f, sort_keys=False)
YAML().dump(
manifest,
f,
)
return manifest

def get_manifest(self):
Expand Down Expand Up @@ -214,10 +216,17 @@ def read_manifests(manifest_paths):
manifest_list = []
for manifest_path in manifest_paths:
with open(manifest_path, "r") as f:
manifest_list.append(yaml.safe_load(f))

manifest_list.append(YAML(typ="safe").load(f))

return manifest_list


def write_combined_manifest(manifest_path, combined_manifest):
with open(manifest_path, "w") as f:
yaml.dump(combined_manifest, f, sort_keys=False)

YAML().dump(
combined_manifest,
f,
)

2 changes: 1 addition & 1 deletion conda_vendor/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.1.14"
__version__ = "0.1.15"


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions conda_vendor_container_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ channels:
dependencies:
- python=3.9.5
- conda-lock
- ruamel.yaml
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
packages=find_packages(exclude=("tests",), where="."),
url="https://github.com/MetroStar/conda-vendor",
entry_points={"console_scripts": ["conda-vendor = conda_vendor.__main__:cli"]},
install_requires=["pyyaml", "conda-lock"],
install_requires=["ruamel.yaml", "conda-lock"],
setup_requires=["wheel"],
python_requires=">=3.6",
long_description=long_description,
Expand Down
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from unittest.mock import Mock

import pytest
import yaml
from ruamel.yaml import YAML

from conda_vendor.conda_channel import CondaChannel
from conda_vendor.manifest import MetaManifest
Expand Down Expand Up @@ -60,7 +60,10 @@ def get_path_location_for_manifest_fixture(tmpdir_factory):

fn = tmpdir_factory.mktemp("minimal_env").join("env.yml")
with open(fn, "w") as f:
yaml.dump(fixture_manifest, f, sort_keys=False)
YAML().dump(
fixture_manifest,
f,
)

return fn

Expand Down
9 changes: 4 additions & 5 deletions tests/test_conda_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@
from unittest.mock import Mock, call, mock_open, patch

import pytest
import yaml
from ruamel.yaml import YAML
from requests import Response
from requests.adapters import urldefragauth
from yaml import safe_load
from yaml.loader import SafeLoader

from ruamel.yaml import YAML
from conda_vendor.conda_channel import CondaChannel, improved_download
from conda_vendor.manifest import LockWrapper, MetaManifest

from .conftest import mock_response


@patch("yaml.load")
@patch("ruamel.yaml.YAML")
def test_load_manifest(mock, conda_channel_fixture, tmp_path):
test_manifest_path = tmp_path / "test_manifest.yml"
with open(test_manifest_path, "w") as y:
y.write("test")
conda_channel_fixture.load_manifest(test_manifest_path)
mock.assert_called_once_with = [test_manifest_path, yaml.SafeLoader]
mock.assert_called_once_with = [test_manifest_path]


@patch("requests.Session.get")
Expand Down
6 changes: 4 additions & 2 deletions tests/test_custom_manifest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import TestCase
from unittest.mock import Mock, call, mock_open, patch

import yaml
from ruamel.yaml import YAML

from conda_vendor.custom_manifest import CustomManifest, IBManifest

Expand Down Expand Up @@ -40,7 +40,9 @@ def test_write_custom_manifest(mock_read_meta_manifest, tmp_path):

custom_channel.write_custom_manifest(test_output_path)
with open(expected_custom_manifest_destination, "r") as f:
actual_custom_manifest = yaml.load(f, Loader=yaml.SafeLoader)
actual_custom_manifest = YAML(typ="safe").load(
f,
)

assert actual_custom_manifest == expected_custom_manifest

Expand Down
4 changes: 2 additions & 2 deletions tests/test_env_yaml_from_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from unittest.mock import patch

import pytest
import yaml
from ruamel.yaml import YAML
from yaml import SafeLoader

from conda_vendor.env_yaml_from_manifest import YamlFromManifest
Expand All @@ -20,7 +20,7 @@ def yml_man_fixture(tmp_path, get_path_location_for_manifest_fixture):
def test_YamlFromManifest_init_(yml_man_fixture):
test_manifest_path = yml_man_fixture.meta_manifest_path
with open(test_manifest_path, "r") as f:
expected = yaml.load(f, Loader=SafeLoader)
expected = YAML(typ="safe").load(f)
result = yml_man_fixture.meta_manifest
TestCase().assertDictEqual(expected, result)

Expand Down
6 changes: 4 additions & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from unittest import TestCase
from unittest.mock import Mock, patch

import yaml
from ruamel.yaml import YAML

from conda_vendor.cli import (
ironbank_from_meta_manifest,
Expand Down Expand Up @@ -39,7 +39,9 @@ def test_get_packages_from_manifest(meta_manifest, expected_packages):
minimal_conda_forge_environment, tmp_path, test_manifest_filename
)
with open(expected_manifest_path) as f:
actual_manifest = yaml.load(f, Loader=yaml.SafeLoader)
actual_manifest = YAML(typ="safe").load(
f,
)

assert "main" in actual_manifest.keys()
assert "conda-forge" in actual_manifest.keys()
Expand Down
17 changes: 10 additions & 7 deletions tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from requests import Response
import hashlib
import json
import yaml
from ruamel.yaml import YAML
from requests import Response
from unittest import TestCase
from unittest.mock import Mock, patch, call, mock_open
Expand Down Expand Up @@ -227,7 +227,7 @@ def test_create_manifest(meta_manifest_fixture, tmp_path):
test_manifest_fixture.create_manifest()

with open(expected_path, "r") as f:
actual_manifest = yaml.load(f, Loader=SafeLoader)
actual_manifest = YAML(typ="safe").load(f)

TestCase().assertDictEqual(actual_manifest, expected_manifest)

Expand Down Expand Up @@ -342,10 +342,11 @@ def test_combine_metamanifests(tmp_path):
test_manifests_list = [manifest_path_1, manifest_path_2]

with open(manifest_path_1, "w") as f:
yaml.dump(test_manifest1, f)
YAML().dump(test_manifest1, f)

with open(manifest_path_2, "w") as f:
yaml.dump(test_manifest2, f)
YAML().dump(test_manifest2, f)


actual_return = combine_metamanifests(test_manifests_list)
assert actual_return == expected_return
Expand All @@ -359,10 +360,10 @@ def test_read_manifests(tmp_path):
yaml_path2 = tmp_path / "yaml2.yaml"

with open(yaml_path1, "w") as f:
yaml.dump(yaml1, f)
YAML().dump(yaml1, f)

with open(yaml_path2, "w") as f:
yaml.dump(yaml2, f)
YAML().dump(yaml2, f)

expected_manifest_list = [yaml1, yaml2]
actual_manifest_list = read_manifests([yaml_path1, yaml_path2])
Expand All @@ -377,6 +378,8 @@ def test_write_combined_manifest(tmp_path):
write_combined_manifest(yaml_path, test_yaml)

with open(yaml_path, "r") as f:
actual_yaml = yaml.safe_load(f)

actual_yaml = YAML(typ="safe").load(f)


TestCase().assertDictEqual(actual_yaml, test_yaml)

0 comments on commit 0df4d53

Please sign in to comment.