aboutsummaryrefslogtreecommitdiff
path: root/delivery_merge
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2019-05-16 09:58:35 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2019-05-16 09:58:35 -0400
commitdb949eb7a2e8e28d9808a638ae283de57043ab52 (patch)
treef41913c893b3a18f98195cb5159b0abf4b1e6cd4 /delivery_merge
parent39b5aaff1550ce5bdb1982a6f0c532d5a975e7d2 (diff)
downloaddelivery_merge-db949eb7a2e8e28d9808a638ae283de57043ab52.tar.gz
Implement force_yaml_channels()
* Switch from pyyaml to ruamel.yaml
Diffstat (limited to 'delivery_merge')
-rw-r--r--delivery_merge/cli/merge.py10
-rw-r--r--delivery_merge/merge.py37
2 files changed, 43 insertions, 4 deletions
diff --git a/delivery_merge/cli/merge.py b/delivery_merge/cli/merge.py
index 6cf421e..45adf64 100644
--- a/delivery_merge/cli/merge.py
+++ b/delivery_merge/cli/merge.py
@@ -1,6 +1,11 @@
import os
from ..conda import conda, conda_installer, conda_init_path
-from ..merge import env_combine, testable_packages, integration_test
+from ..merge import (
+ env_combine,
+ testable_packages,
+ integration_test,
+ force_yaml_channels
+)
from argparse import ArgumentParser
@@ -53,6 +58,9 @@ def main():
print("Exporting yaml configuration...")
conda('env', 'export', '-n', name, '--file', yamlfile)
+ print("Fix up yaml channel order...")
+ force_yaml_channels(yamlfile, channels)
+
print("Exporting explicit dump...")
with open(specfile, 'w+') as spec:
proc = conda('list', '--explicit', '-n', name)
diff --git a/delivery_merge/merge.py b/delivery_merge/merge.py
index 64aec8a..f99c542 100644
--- a/delivery_merge/merge.py
+++ b/delivery_merge/merge.py
@@ -1,10 +1,11 @@
import os
import re
-import yaml
+import sys
from .conda import conda, conda_env_load, conda_cmd_channels
from .utils import comment_find, git, pushd, sh
from configparser import ConfigParser
from glob import glob
+from ruamel.yaml import YAML
DMFILE_RE = re.compile(r'^(?P<name>[A-z\-_l]+)(?:[=<>\!]+)?(?P<version>[A-z0-9. ]+)?') # noqa
@@ -94,6 +95,7 @@ def testable_packages(filename, prefix):
"""
pkgdir = os.path.join(prefix, 'pkgs')
paths = []
+ yaml = YAML(typ='safe')
for record in dmfile(filename):
# Reconstruct ${package}-${version} format (when possible)
@@ -121,8 +123,7 @@ def testable_packages(filename, prefix):
continue
with open(os.path.join(recipe_d, 'meta.yaml')) as yaml_data:
- source = yaml.load(yaml_data.read(),
- Loader=yaml.SafeLoader)['source']
+ source = yaml.load(yaml_data)['source']
if not isinstance(source, dict):
continue
@@ -181,6 +182,7 @@ def integration_test(pkg_data, conda_env, results_root='.'):
proc_pip.check_returncode()
proc_pytest = sh("pytest", f"-v --basetemp=.tmp --junitxml={results}")
+ print(proc_pytest.stdout.decode())
if proc_pytest.returncode:
print(proc_pytest.stderr.decode())
@@ -188,6 +190,9 @@ def integration_test(pkg_data, conda_env, results_root='.'):
def force_xunit2(project='.'):
+ """ Set project configuration to emit xunit2 regardless of orignal settings
+ :param project: str: path project (i.e. source directory)
+ """
configs = [os.path.abspath(os.path.join(project, x))
for x in ['pytest.ini', 'setup.cfg']]
@@ -208,3 +213,29 @@ def force_xunit2(project='.'):
cfg.write(data)
return
+
+def force_yaml_channels(yamlfile, channels):
+ """ Replace the `channels:` block with `channels`
+ :param yamlfile: str: path to yaml file
+ :param channels: list: channel URLs
+ """
+ if not isinstance(channels, list):
+ raise TypeError("Expecting a list of URLs")
+
+ yaml = YAML()
+ yaml.default_flow_style = False
+ yaml.indent(offset=2)
+
+ with open(yamlfile) as yaml_data:
+ result = yaml.load(yaml_data)
+
+ if not result.get('channels'):
+ print(f"{yamlfile} has no channels", file=sys.stderr)
+ return
+
+ # Assuming there's a reason to change the file...
+ if result['channels'] != channels:
+ result['channels'] = channels
+
+ with open(yamlfile, 'w') as fp:
+ yaml.dump(result, fp)