pkgset: Use highest pickle protocol

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ář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2019-06-11 12:28:56 +02:00
parent 6ec206f9ae
commit 2c3e6a5a74
4 changed files with 7 additions and 5 deletions

View File

@ -253,7 +253,7 @@ class PackageSetBase(kobo.log.LoggingBase):
Saves the current FileCache using the pickle module to `file_path`. Saves the current FileCache using the pickle module to `file_path`.
""" """
with open(file_path, 'wb') as f: 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): class FilelistPackageSet(PackageSetBase):

View File

@ -712,7 +712,7 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event):
else: else:
global_pkgset.fast_merge(pkgset) global_pkgset.fast_merge(pkgset)
with open(global_pkgset_path, 'wb') as f: 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) f.write(data)
# write global package list # write global package list

View File

@ -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 = pungi.phases.pkgset.pkgsets.FilelistPackageSet(compose.conf["sigkeys"], logger=compose._logger, arches=ALL_ARCHES)
pkgset.populate(file_list) pkgset.populate(file_list)
with open(global_pkgset_path, "wb") as f: with open(global_pkgset_path, "wb") as f:
pickle.dump(pkgset, f) pickle.dump(pkgset, f, protocol=pickle.HIGHEST_PROTOCOL)
# write global package list # write global package list
pkgset.save_file_list(compose.paths.work.package_list(arch="global"), remove_path_prefix=path_prefix) pkgset.save_file_list(compose.paths.work.package_list(arch="global"), remove_path_prefix=path_prefix)

View File

@ -10,6 +10,8 @@ try:
except ImportError: except ImportError:
import unittest import unittest
from six.moves import cPickle as pickle
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from pungi.phases.pkgset.sources import source_koji from pungi.phases.pkgset.sources import source_koji
@ -127,7 +129,7 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase):
] ]
) )
self.assertItemsEqual(pickle_dumps.call_args_list, 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: with open(self.pkgset_path) as f:
self.assertEqual(f.read(), 'DATA') 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 # 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.assertEqual(pkgset.fast_merge.call_count, 2 * (len(self.compose.all_variants.values()) + 1))
self.assertItemsEqual(pickle_dumps.call_args_list, 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: with open(self.pkgset_path) as f:
self.assertEqual(f.read(), 'DATA') self.assertEqual(f.read(), 'DATA')