From 2c3e6a5a743d8d21499756afbd7c000d4b731848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 11 Jun 2019 12:28:56 +0200 Subject: [PATCH] pkgset: Use highest pickle protocol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Higher protocols should be more efficient in terms of performance and storage size. Since we don't really care about interoperability with different python version, we can safely go to the highest version. Signed-off-by: Lubomír Sedlář --- pungi/phases/pkgset/pkgsets.py | 2 +- pungi/phases/pkgset/sources/source_koji.py | 2 +- pungi/phases/pkgset/sources/source_repos.py | 2 +- tests/test_pkgset_source_koji.py | 6 ++++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pungi/phases/pkgset/pkgsets.py b/pungi/phases/pkgset/pkgsets.py index b15b92d3..823812ec 100644 --- a/pungi/phases/pkgset/pkgsets.py +++ b/pungi/phases/pkgset/pkgsets.py @@ -253,7 +253,7 @@ class PackageSetBase(kobo.log.LoggingBase): Saves the current FileCache using the pickle module to `file_path`. """ with open(file_path, 'wb') as f: - pickle.dump(self.file_cache, f) + pickle.dump(self.file_cache, f, protocol=pickle.HIGHEST_PROTOCOL) class FilelistPackageSet(PackageSetBase): diff --git a/pungi/phases/pkgset/sources/source_koji.py b/pungi/phases/pkgset/sources/source_koji.py index b1069543..a05165e1 100644 --- a/pungi/phases/pkgset/sources/source_koji.py +++ b/pungi/phases/pkgset/sources/source_koji.py @@ -712,7 +712,7 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event): else: global_pkgset.fast_merge(pkgset) with open(global_pkgset_path, 'wb') as f: - data = pickle.dumps(global_pkgset) + data = pickle.dumps(global_pkgset, protocol=pickle.HIGHEST_PROTOCOL) f.write(data) # write global package list diff --git a/pungi/phases/pkgset/sources/source_repos.py b/pungi/phases/pkgset/sources/source_repos.py index c25165f0..9d73215e 100644 --- a/pungi/phases/pkgset/sources/source_repos.py +++ b/pungi/phases/pkgset/sources/source_repos.py @@ -152,7 +152,7 @@ def populate_global_pkgset(compose, file_list, path_prefix): pkgset = pungi.phases.pkgset.pkgsets.FilelistPackageSet(compose.conf["sigkeys"], logger=compose._logger, arches=ALL_ARCHES) pkgset.populate(file_list) with open(global_pkgset_path, "wb") as f: - pickle.dump(pkgset, f) + pickle.dump(pkgset, f, protocol=pickle.HIGHEST_PROTOCOL) # write global package list pkgset.save_file_list(compose.paths.work.package_list(arch="global"), remove_path_prefix=path_prefix) diff --git a/tests/test_pkgset_source_koji.py b/tests/test_pkgset_source_koji.py index 9946a8e7..74953cb0 100644 --- a/tests/test_pkgset_source_koji.py +++ b/tests/test_pkgset_source_koji.py @@ -10,6 +10,8 @@ try: except ImportError: import unittest +from six.moves import cPickle as pickle + sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) from pungi.phases.pkgset.sources import source_koji @@ -127,7 +129,7 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase): ] ) self.assertItemsEqual(pickle_dumps.call_args_list, - [mock.call(orig_pkgset)]) + [mock.call(orig_pkgset, protocol=pickle.HIGHEST_PROTOCOL)]) with open(self.pkgset_path) as f: self.assertEqual(f.read(), 'DATA') @@ -174,7 +176,7 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase): # for each tag, call pkgset.fast_merge once for each variant and once for global pkgset self.assertEqual(pkgset.fast_merge.call_count, 2 * (len(self.compose.all_variants.values()) + 1)) self.assertItemsEqual(pickle_dumps.call_args_list, - [mock.call(orig_pkgset)]) + [mock.call(orig_pkgset, protocol=pickle.HIGHEST_PROTOCOL)]) with open(self.pkgset_path) as f: self.assertEqual(f.read(), 'DATA')