Skip to content

Commit

Permalink
replace HTTPError with more robust Exception for `download_and_extrac…
Browse files Browse the repository at this point in the history
…t_antismash_data`

to make sure deletion of exttract_path can always happen.
  • Loading branch information
CunliangGeng committed Aug 25, 2023
1 parent d96c159 commit d08851d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/nplinker/genomics/antismash/antismash_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from os import PathLike
from pathlib import Path
import shutil
from urllib.error import HTTPError
from nplinker.logconfig import LogConfig
from nplinker.utils import download_and_extract_archive
from nplinker.utils import list_dirs
Expand Down Expand Up @@ -74,12 +73,10 @@ def download_and_extract_antismash_data(antismash_id: str,
logger.info('antiSMASH BGC data of %s is downloaded and extracted.',
antismash_id)

except HTTPError as e:
except Exception as e:
shutil.rmtree(extract_path)
logger.warning(e)
raise HTTPError(e.url, e.code,
f"Could not find a valid url for {antismash_id}",
e.headers, e.fp) from e
raise e


def _check_roots(download_root: PathLike, extract_root: PathLike):
Expand Down
2 changes: 1 addition & 1 deletion tests/genomics/antismash/test_antismash_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_nonexisting_id(self, tmp_path):
extract_root = tmp_path / "extracted"
extract_root.mkdir()
for test_id in nonexisting_ids:
with pytest.raises(HTTPError):
with pytest.raises(RuntimeError):
download_and_extract_antismash_data(test_id, download_root,
extract_root)
extracted_folder = extract_root / "antismash" / test_id
Expand Down

0 comments on commit d08851d

Please sign in to comment.