You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:58:19 UTC
[buildstream] 01/06: _yaml.dump: allow pass-through of file handle
This is an automated email from the ASF dual-hosted git repository.
not-in-ldap pushed a commit to branch aevri/win32_temptext
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 736e417a50f9f85f219f7b337af4f76bb19e3369
Author: Angelos Evripiotis <je...@bloomberg.net>
AuthorDate: Wed Jun 5 17:32:38 2019 +0100
_yaml.dump: allow pass-through of file handle
The underlying roundtrip_dump() allows for the 'file' parameter to be a
filename or a file handle. Offer this flexibility with dump() too.
Also copy the slighlty better documentation for the roundtrip_dump()
parameters to dump().
---
src/buildstream/_yaml.pyx | 12 ++++++++----
tests/artifactcache/config.py | 4 ++--
tests/artifactcache/junctions.py | 2 +-
tests/artifactcache/pull.py | 4 ++--
tests/artifactcache/push.py | 4 ++--
tests/cachekey/cachekey.py | 4 ++--
tests/frontend/remote-caches.py | 2 +-
tests/sourcecache/fetch.py | 6 +++---
tests/sourcecache/push.py | 6 +++---
9 files changed, 24 insertions(+), 20 deletions(-)
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index 2122dea..d47316d 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -460,11 +460,15 @@ cpdef Node load_data(str data, int file_index=_SYNTHETIC_FILE_INDEX, str file_na
# to output something close to what you read in, consider using the
# `roundtrip_load` and `roundtrip_dump` function pair instead.
#
+# If `file` is a string, it is the filename to write to, if `file` has a
+# `write` method, it's treated as a stream, otherwise output is to stdout.
+#
# Args:
-# contents (any): Content to write out
-# filename (str): The (optional) file name to write out to
-def dump(object contents, str filename=None):
- roundtrip_dump(node_sanitize(contents), file=filename)
+# contents (Mapping or list): The content to write out as YAML.
+# file (any): The file to write to.
+#
+def dump(contents, file=None):
+ roundtrip_dump(node_sanitize(contents), file=file)
# node_get_provenance()
diff --git a/tests/artifactcache/config.py b/tests/artifactcache/config.py
index 591cc0e..59cd4fb 100644
--- a/tests/artifactcache/config.py
+++ b/tests/artifactcache/config.py
@@ -101,11 +101,11 @@ def test_artifact_cache_precedence(tmpdir, override_caches, project_caches, user
project_config['name'] = 'test'
user_config_file = str(tmpdir.join('buildstream.conf'))
- _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ _yaml.dump(_yaml.node_sanitize(user_config), file=user_config_file)
project_dir = tmpdir.mkdir('project')
project_config_file = str(project_dir.join('project.conf'))
- _yaml.dump(_yaml.node_sanitize(project_config), filename=project_config_file)
+ _yaml.dump(_yaml.node_sanitize(project_config), file=project_config_file)
context = Context()
context.load(config=user_config_file)
diff --git a/tests/artifactcache/junctions.py b/tests/artifactcache/junctions.py
index 52d721b..98be62b 100644
--- a/tests/artifactcache/junctions.py
+++ b/tests/artifactcache/junctions.py
@@ -35,7 +35,7 @@ def project_set_artifacts(project, url):
'url': url,
'push': True
})
- _yaml.dump(_yaml.node_sanitize(project_config), filename=project_conf_file)
+ _yaml.dump(_yaml.node_sanitize(project_config), file=project_conf_file)
@pytest.mark.datafiles(DATA_DIR)
diff --git a/tests/artifactcache/pull.py b/tests/artifactcache/pull.py
index d5f2c1f..eb36820 100644
--- a/tests/artifactcache/pull.py
+++ b/tests/artifactcache/pull.py
@@ -73,7 +73,7 @@ def test_pull(cli, tmpdir, datafiles):
}
# Write down the user configuration file
- _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ _yaml.dump(_yaml.node_sanitize(user_config), file=user_config_file)
# Ensure CLI calls will use it
cli.configure(user_config)
@@ -182,7 +182,7 @@ def test_pull_tree(cli, tmpdir, datafiles):
}
# Write down the user configuration file
- _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ _yaml.dump(_yaml.node_sanitize(user_config), file=user_config_file)
# Ensure CLI calls will use it
cli.configure(user_config)
diff --git a/tests/artifactcache/push.py b/tests/artifactcache/push.py
index 1cf46a4..fb9ddbb 100644
--- a/tests/artifactcache/push.py
+++ b/tests/artifactcache/push.py
@@ -66,7 +66,7 @@ def test_push(cli, tmpdir, datafiles):
}
# Write down the user configuration file
- _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ _yaml.dump(_yaml.node_sanitize(user_config), file=user_config_file)
# Fake minimal context
context = Context()
@@ -164,7 +164,7 @@ def test_push_message(tmpdir, datafiles):
}
# Write down the user configuration file
- _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ _yaml.dump(_yaml.node_sanitize(user_config), file=user_config_file)
queue = multiprocessing.Queue()
# Use subprocess to avoid creation of gRPC threads in main BuildStream process
diff --git a/tests/cachekey/cachekey.py b/tests/cachekey/cachekey.py
index 7c5d90d..1591743 100644
--- a/tests/cachekey/cachekey.py
+++ b/tests/cachekey/cachekey.py
@@ -198,11 +198,11 @@ def test_cache_key_fatal_warnings(cli, tmpdir, first_warnings, second_warnings,
project_dir = tmpdir.mkdir(project_name)
project_config_file = str(project_dir.join('project.conf'))
- _yaml.dump(_yaml.node_sanitize(config), filename=project_config_file)
+ _yaml.dump(_yaml.node_sanitize(config), file=project_config_file)
elem_dir = project_dir.mkdir('elements')
element_file = str(elem_dir.join('stack.bst'))
- _yaml.dump({'kind': 'stack'}, filename=element_file)
+ _yaml.dump({'kind': 'stack'}, file=element_file)
result = cli.run(project=str(project_dir), args=[
'show',
diff --git a/tests/frontend/remote-caches.py b/tests/frontend/remote-caches.py
index 089cf96..2e8b270 100644
--- a/tests/frontend/remote-caches.py
+++ b/tests/frontend/remote-caches.py
@@ -57,7 +57,7 @@ def test_source_artifact_caches(cli, tmpdir, datafiles):
},
'cachedir': cachedir
}
- _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ _yaml.dump(_yaml.node_sanitize(user_config), file=user_config_file)
cli.configure(user_config)
create_element_size('repo.bst', project_dir, element_path, [], 10000)
diff --git a/tests/sourcecache/fetch.py b/tests/sourcecache/fetch.py
index 899e162..e6dcf07 100644
--- a/tests/sourcecache/fetch.py
+++ b/tests/sourcecache/fetch.py
@@ -56,7 +56,7 @@ def test_source_fetch(cli, tmpdir, datafiles):
},
'cachedir': cache_dir,
}
- _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ _yaml.dump(_yaml.node_sanitize(user_config), file=user_config_file)
cli.configure(user_config)
repo = create_repo('git', str(tmpdir))
@@ -131,7 +131,7 @@ def test_fetch_fallback(cli, tmpdir, datafiles):
},
'cachedir': cache_dir,
}
- _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ _yaml.dump(_yaml.node_sanitize(user_config), file=user_config_file)
cli.configure(user_config)
repo = create_repo('git', str(tmpdir))
@@ -188,7 +188,7 @@ def test_pull_fail(cli, tmpdir, datafiles):
},
'cachedir': cache_dir,
}
- _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ _yaml.dump(_yaml.node_sanitize(user_config), file=user_config_file)
cli.configure(user_config)
repo = create_repo('git', str(tmpdir))
diff --git a/tests/sourcecache/push.py b/tests/sourcecache/push.py
index 065047b..e2ff612 100644
--- a/tests/sourcecache/push.py
+++ b/tests/sourcecache/push.py
@@ -56,7 +56,7 @@ def test_source_push(cli, tmpdir, datafiles):
},
'cachedir': cache_dir,
}
- _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ _yaml.dump(_yaml.node_sanitize(user_config), file=user_config_file)
cli.configure(user_config)
repo = create_repo('git', str(tmpdir))
@@ -116,7 +116,7 @@ def test_push_pull(cli, datafiles, tmpdir):
},
'cachedir': cache_dir,
}
- _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ _yaml.dump(_yaml.node_sanitize(user_config), file=user_config_file)
cli.configure(user_config)
# create repo to pull from
@@ -162,7 +162,7 @@ def test_push_fail(cli, tmpdir, datafiles):
},
'cachedir': cache_dir,
}
- _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ _yaml.dump(_yaml.node_sanitize(user_config), file=user_config_file)
cli.configure(user_config)
# create repo to pull from