spack checksum: Use package's fetch_options (#15481)

This makes sure that a package's fetch_options are used when fetching
new versions to checksum. This allows working around problems with
slow servers or those requiring a cookie to be set.
This commit is contained in:
Michael Kuhn 2020-03-20 20:11:42 +01:00 committed by GitHub
parent 2f8ff722a9
commit 545fae8407
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -56,7 +56,8 @@ def checksum(parser, args):
tty.die("Could not find any versions for {0}".format(pkg.name)) tty.die("Could not find any versions for {0}".format(pkg.name))
version_lines = spack.stage.get_checksums_for_versions( version_lines = spack.stage.get_checksums_for_versions(
url_dict, pkg.name, keep_stage=args.keep_stage) url_dict, pkg.name, keep_stage=args.keep_stage,
fetch_options=pkg.fetch_options)
print() print()
print(version_lines) print(version_lines)

View File

@ -752,7 +752,8 @@ def purge():
def get_checksums_for_versions( def get_checksums_for_versions(
url_dict, name, first_stage_function=None, keep_stage=False): url_dict, name, first_stage_function=None, keep_stage=False,
fetch_options=None):
"""Fetches and checksums archives from URLs. """Fetches and checksums archives from URLs.
This function is called by both ``spack checksum`` and ``spack This function is called by both ``spack checksum`` and ``spack
@ -766,6 +767,8 @@ def get_checksums_for_versions(
first_stage_function (callable): function that takes a Stage and a URL; first_stage_function (callable): function that takes a Stage and a URL;
this is run on the stage of the first URL downloaded this is run on the stage of the first URL downloaded
keep_stage (bool): whether to keep staging area when command completes keep_stage (bool): whether to keep staging area when command completes
fetch_options (dict): Options used for the fetcher (such as timeout
or cookies)
Returns: Returns:
(str): A multi-line string containing versions and corresponding hashes (str): A multi-line string containing versions and corresponding hashes
@ -799,7 +802,12 @@ def get_checksums_for_versions(
i = 0 i = 0
for url, version in zip(urls, versions): for url, version in zip(urls, versions):
try: try:
with Stage(url, keep=keep_stage) as stage: if fetch_options:
url_or_fs = fs.URLFetchStrategy(
url, fetch_options=fetch_options)
else:
url_or_fs = url
with Stage(url_or_fs, keep=keep_stage) as stage:
# Fetch the archive # Fetch the archive
stage.fetch() stage.fetch()
if i == 0 and first_stage_function: if i == 0 and first_stage_function: