Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raise if Singularity container retrieval fails #1622

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions nf_core/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,16 +742,24 @@ def singularity_pull_image(self, container, out_path, cache_path, progress):
task = progress.add_task(container, start=False, total=False, progress_type="singularity_pull", current_log="")

# Run the singularity pull command
proc = subprocess.Popen(
with subprocess.Popen(
singularity_command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
bufsize=1,
)
for line in proc.stdout:
log.debug(line.strip())
progress.update(task, current_log=line.strip())
) as proc:
lines = []
for line in proc.stdout:
lines.append(line)
progress.update(task, current_log=line.strip())

if lines:
# something went wrong with the container retrieval
if any("FATAL: " in line for line in lines):
log.info("Singularity container retrieval fialed with the following error:")
log.info("".join(lines))
fabianegli marked this conversation as resolved.
Show resolved Hide resolved
raise FileNotFoundError(f'The container "{container}" is unavailable.\n{"".join(lines)}')

# Copy cached download if we are using the cache
if cache_path:
Expand Down
26 changes: 21 additions & 5 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,30 @@ def test_mismatching_md5sums(self, tmpfile):
#
# Tests for 'singularity_pull_image'
#
# If Singularity is not installed, will log an error and exit
# If Singularity is installed, should raise an OSError due to non-existant image
# If Singularity is installed, but the container can't be accessed because it does not exist or there are aceess
# restrictions, a FileNotFoundError is raised due to the unavailability of the image.
@pytest.mark.skipif(
shutil.which("singularity") is None,
reason="Can't test what Singularity does if it's not installed.",
)
@with_temporary_folder
@pytest.mark.xfail(raises=OSError)
@mock.patch("rich.progress.Progress.add_task")
def test_singularity_pull_image(self, tmp_dir, mock_rich_progress):
def test_singularity_pull_image_singularity_installed(self, tmp_dir, mock_rich_progress):
download_obj = DownloadWorkflow(pipeline="dummy", outdir=tmp_dir)
download_obj.singularity_pull_image("a-container", tmp_dir, None, mock_rich_progress)
with pytest.raises(FileNotFoundError):
download_obj.singularity_pull_image("a-container", tmp_dir, None, mock_rich_progress)

# If Singularity is not installed, it raises a FileNotFoundError because the singularity command can't be found.
@pytest.mark.skipif(
shutil.which("singularity") is not None,
reason="Can't test how the code behaves if sungularity is not installed if it is.",
fabianegli marked this conversation as resolved.
Show resolved Hide resolved
)
@with_temporary_folder
@mock.patch("rich.progress.Progress.add_task")
def test_singularity_pull_image_singularity_not_installed(self, tmp_dir, mock_rich_progress):
download_obj = DownloadWorkflow(pipeline="dummy", outdir=tmp_dir)
with pytest.raises(FileNotFoundError):
download_obj.singularity_pull_image("a-container", tmp_dir, None, mock_rich_progress)

#
# Tests for the main entry method 'download_workflow'
Expand Down