Skip to content

Commit 0d831da

Browse files
authored
Merge pull request #4885 from smoors/download-bar
fix download progress bar
2 parents 491b7a3 + 33e0ded commit 0d831da

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

easybuild/framework/easyblock.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"""
4545
import concurrent
4646
import copy
47+
import functools
4748
import glob
4849
import inspect
4950
import json
@@ -128,9 +129,26 @@
128129
# Directory name in which to store reproducibility files
129130
REPROD = 'reprod'
130131

132+
CHECKSUMS_JSON = 'checksums.json'
133+
131134
_log = fancylogger.getLogger('easyblock')
132135

133136

137+
def _obtain_file_update_progress_bar_on_return(func):
138+
"""Decorator for obtain_file() to update the progress bar upon return"""
139+
@functools.wraps(func)
140+
def wrapper(*args, **kwargs):
141+
result = func(*args, **kwargs)
142+
filename = args[1]
143+
144+
# We don't account for the checksums file in the progress bar
145+
if filename != CHECKSUMS_JSON:
146+
update_progress_bar(PROGRESS_BAR_DOWNLOAD_ALL)
147+
148+
return result
149+
return wrapper
150+
151+
134152
class EasyBlock:
135153
"""Generic support for building and installing software, base class for actual easyblocks."""
136154

@@ -452,7 +470,7 @@ def get_checksums_from_json(self, always_read=False):
452470
:param always_read: always read the checksums.json file, even if it has been read before
453471
"""
454472
if always_read or self.json_checksums is None:
455-
path = self.obtain_file("checksums.json", no_download=True, warning_only=True)
473+
path = self.obtain_file(CHECKSUMS_JSON, no_download=True, warning_only=True)
456474
if path is not None:
457475
self.log.info("Loading checksums from file %s", path)
458476
json_txt = read_file(path)
@@ -789,6 +807,7 @@ def collect_exts_file_info(self, fetch_files=True, verify_checksums=True):
789807

790808
return exts_sources
791809

810+
@_obtain_file_update_progress_bar_on_return
792811
def obtain_file(self, filename, extension=False, urls=None, download_filename=None, force_download=False,
793812
git_config=None, no_download=False, download_instructions=None, alt_location=None,
794813
warning_only=False):
@@ -812,8 +831,8 @@ def obtain_file(self, filename, extension=False, urls=None, download_filename=No
812831
srcpaths = source_paths()
813832

814833
# We don't account for the checksums file in the progress bar
815-
if filename != 'checksum.json':
816-
update_progress_bar(PROGRESS_BAR_DOWNLOAD_ALL, label=filename)
834+
if filename != CHECKSUMS_JSON:
835+
update_progress_bar(PROGRESS_BAR_DOWNLOAD_ALL, progress_size=0, label=filename)
817836

818837
if alt_location is None:
819838
location = self.name
@@ -5051,7 +5070,7 @@ def inject_checksums_to_json(ecs, checksum_type):
50515070
raise EasyBuildError("Found existing checksum for %s, use --force to overwrite them" % filename)
50525071

50535072
# actually write the checksums
5054-
with open(os.path.join(ec_dir, 'checksums.json'), 'w') as outfile:
5073+
with open(os.path.join(ec_dir, CHECKSUMS_JSON), 'w') as outfile:
50555074
json.dump(existing_checksums, outfile, indent=2, sort_keys=True)
50565075

50575076

0 commit comments

Comments
 (0)