Skip to content

Commit fc268d1

Browse files
committed
updating to not use memory tar
1 parent abcbda4 commit fc268d1

8 files changed

Lines changed: 29 additions & 44 deletions

File tree

singularity/analysis/apps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def extract_apps(image_path, app_names, S=None, verbose=True):
6464
if not isinstance(app_names,list):
6565
app_names = [app_names]
6666

67-
file_obj, tar = get_image_tar(image_path, S=S, write_file=True)
67+
file_obj, tar = get_image_tar(image_path, S=S)
6868
members = tar.getmembers()
6969
apps = dict()
7070

singularity/analysis/compare.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def container_similarity_vector(container1=None,packages_set=None,by=None,custom
9393
return comparisons
9494

9595

96-
def compare_singularity_images(image_paths1,image_paths2=None,old_version=True):
96+
def compare_singularity_images(image_paths1,image_paths2=None):
9797
'''compare_singularity_images is a wrapper for compare_containers to compare
9898
singularity containers. If image_paths2 is not defined, pairwise comparison is done
9999
with image_paths1
@@ -113,8 +113,7 @@ def compare_singularity_images(image_paths1,image_paths2=None,old_version=True):
113113

114114
comparisons_done = []
115115
for image1 in image_paths1:
116-
fileobj1,tar1 = get_image_tar(image1,
117-
write_file=old_version)
116+
fileobj1,tar1 = get_image_tar(image1)
118117

119118
members1 = [x.name for x in tar1]
120119
for image2 in image_paths2:
@@ -125,8 +124,7 @@ def compare_singularity_images(image_paths1,image_paths2=None,old_version=True):
125124
if image1 == image2:
126125
sim = 1.0
127126
else:
128-
fileobj2,tar2 = get_image_tar(image2,
129-
write_file=old_version)
127+
fileobj2,tar2 = get_image_tar(image2)
130128
members2 = [x.name for x in tar2]
131129
c = compare_lists(members1,members2)
132130
sim = information_coefficient(c['total1'],c['total2'],c['intersect'])

singularity/analysis/reproduce/hash.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ def get_image_hash(image_path,
6464
level=None,level_filter=None,
6565
include_files=None,
6666
skip_files=None,
67-
version=None,
68-
memory_tar=False):
67+
version=None):
6968

7069
'''get_image_hash will generate a sha1 hash of an image, depending on a level
7170
of reproducibility specified by the user. (see function get_levels for descriptions)
@@ -100,8 +99,7 @@ def get_image_hash(image_path,
10099
include_files=include_files)
101100

102101
cli = Singularity()
103-
file_obj,tar = get_image_tar(image_path,
104-
write_file=not memory_tar)
102+
file_obj,tar = get_image_tar(image_path)
105103
hasher = hashlib.md5()
106104

107105
for member in tar:
@@ -136,8 +134,7 @@ def get_content_hashes(image_path,
136134
level_filter=None,
137135
skip_files=None,
138136
version=None,
139-
include_sizes=True,
140-
memory_tar=False):
137+
include_sizes=True):
141138

142139
'''get_content_hashes is like get_image_hash, but it returns a complete dictionary
143140
of file names (keys) and their respective hashes (values). This function is intended
@@ -158,8 +155,7 @@ def get_content_hashes(image_path,
158155
skip_files=skip_files,
159156
include_files=include_files)
160157

161-
file_obj,tar = get_image_tar(image_path,
162-
write_file=not memory_tar)
158+
file_obj,tar = get_image_tar(image_path)
163159

164160
results = extract_guts(image_path=image_path,
165161
tar=tar,

singularity/analysis/reproduce/metrics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def assess_differences(image_file1,
7171
guts2 = get_content_hashes(image_path=image_file2,
7272
level_filter=level_filter)
7373

74+
print(level_name)
7475
files = list(set(list(guts1['hashes'].keys()) + list(guts2['hashes'].keys())))
7576

7677
for file_name in files:

singularity/analysis/reproduce/utils.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,36 +88,29 @@ def extract_guts(image_path,tar,file_filter,tag_root=True,include_sizes=True):
8888

8989

9090
def get_memory_tar(image_path):
91-
'''get an in memory tar of an image (does not require sudo!)'''
91+
'''get an in memory tar of an image. Use carefully, not as reliable
92+
as get_image_tar
93+
'''
9294
cli = Singularity()
9395
byte_array = cli.export(image_path)
9496
file_object = io.BytesIO(byte_array)
9597
tar = tarfile.open(mode="r|*", fileobj=file_object)
9698
return (file_object,tar)
9799

98100

99-
def get_image_tar(image_path,write_file=True,S=None):
101+
def get_image_tar(image_path,S=None):
100102
'''get an image tar, either written in memory or to
101103
the file system. file_obj will either be the file object,
102104
or the file itself.
103105
'''
104-
105-
# Singularity 2.3 and up
106-
if not write_file:
107-
file_obj,tar = get_memory_tar(image_path)
108-
bot.debug('Generate in memory tar...')
109-
110-
# Singularity < version 2.3
111-
else:
112-
bot.debug('Generate file system tar...')
113-
if S is None:
114-
S = Singularity()
115-
file_obj = S.export(image_path=image_path)
116-
if file_obj is None:
117-
bot.error("Error generating tar, exiting.")
118-
sys.exit(1)
119-
tar = tarfile.open(file_obj)
120-
106+
bot.debug('Generate file system tar...')
107+
if S is None:
108+
S = Singularity()
109+
file_obj = S.export(image_path=image_path)
110+
if file_obj is None:
111+
bot.error("Error generating tar, exiting.")
112+
sys.exit(1)
113+
tar = tarfile.open(file_obj)
121114
return file_obj, tar
122115

123116

@@ -149,8 +142,7 @@ def extract_content(image_path,member_name,cli=None,return_hash=False):
149142
cli = Singularity()
150143
content = cli.execute(image_path,'cat %s' %(member_name))
151144
if not isinstance(content,bytes):
152-
if isinstance(content,str):
153-
content = content.encode('utf-8')
145+
content = content.encode('utf-8')
154146
content = bytes(content)
155147
# If permissions don't allow read, return None
156148
if len(content) == 0:

singularity/build/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ def run_build(build_dir,params,verbose=True, compress_image=False):
151151
spec_path=params['spec_file'],
152152
output_folder=build_dir,
153153
remove_image=True,
154-
verbose=True,
155-
old_version=True)
154+
verbose=True)
156155

157156
# Derive software tags by subtracting similar OS
158157
diff = get_diff(image_package=image_package)

singularity/package/build.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ def package(image_path,
115115
software=True,
116116
remove_image=False,
117117
verbose=False,
118-
S=None,
119-
old_version=True):
118+
S=None):
120119

121120
'''generate a zip (including the image) to a user specified output_folder.
122121
:param image_path: full path to singularity image file
@@ -130,7 +129,7 @@ def package(image_path,
130129
# Run create image and bootstrap with Singularity command line tool.
131130
S = Singularity(debug=verbose)
132131

133-
file_obj, tar = get_image_tar(image_path,S=S,write_file=old_version)
132+
file_obj, tar = get_image_tar(image_path,S=S)
134133

135134
members = tar.getmembers()
136135
image_name, ext = os.path.splitext(os.path.basename(image_path))

singularity/tests/test_reproduce.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,18 @@ def test_get_content_hashes(self):
129129
hashes = get_content_hashes(self.image1)
130130
for key in ['hashes','sizes','root_owned']:
131131
self.assertTrue(key in hashes)
132-
self.assertEqual(len(hashes['hashes']),372)
132+
self.assertEqual(len(hashes['hashes']),395)
133133

134134

135135
def test_extract_guts(self):
136136
from singularity.analysis.reproduce.utils import extract_guts
137137
from singularity.analysis.reproduce import (
138-
get_memory_tar,
138+
get_image_tar,
139139
get_levels )
140140

141141
print("Testing singularity.analysis.reproduce.extract_guts")
142142
levels = get_levels()
143-
file_obj,tar = get_memory_tar(self.image1)
143+
file_obj,tar = get_image_tar(self.image1)
144144
guts = extract_guts(image_path=self.image1,
145145
tar=tar,
146146
file_filter=levels['REPLICATE'])
@@ -151,7 +151,7 @@ def test_get_image_file_hash(self):
151151
from singularity.analysis.reproduce import get_image_file_hash
152152
print("Testing singularity.analysis.reproduce.get_image_file_hash")
153153
hashy = get_image_file_hash(self.image1)
154-
self.assertEqual('9d2edcd19328d09f51c86192990050c5',hashy)
154+
self.assertEqual('843929a1c92d53656fa744c6b831f59b',hashy)
155155

156156

157157
if __name__ == '__main__':

0 commit comments

Comments
 (0)