Skip to content

Commit acdf41d

Browse files
authored
Merge pull request #50 from gbouras13/dev
v1.6.2
2 parents d9f0316 + 75b2c79 commit acdf41d

6 files changed

Lines changed: 37 additions & 26 deletions

File tree

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# History
22

3+
1.6.2 (2024-03-08)
4+
------------------
5+
6+
* Bug fix with `--force` for `plassembler download`, which will only remove the output directory if `--force` is specified (#49).
7+
8+
39
1.6.1 (2024-03-02)
410
------------------
511

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "plassembler"
3-
version = "1.6.1" # change VERSION too
3+
version = "1.6.2" # change VERSION too
44
description = "Quickly and accurately assemble plasmids in hybrid sequenced bacterial isolates"
55
authors = ["George Bouras <george.bouras@adelaide.edu.au>"]
66
license = "MIT"

src/plassembler/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def run(
434434
# check the mash database is installed
435435

436436
logger.info("Checking database installation.")
437-
check_db_installation(Path(database), install_flag=False)
437+
check_db_installation(Path(database), force=False, install_flag=False)
438438
# will only continue if successful
439439
logger.info("Database successfully checked.")
440440

@@ -996,7 +996,7 @@ def assembled(
996996
# check the mash database is installed
997997

998998
logger.info("Checking database installation.")
999-
check_db_installation(Path(database), install_flag=False)
999+
check_db_installation(Path(database), force=False, install_flag=False)
10001000
# will only continue if successful
10011001
logger.info("Database successfully checked.")
10021002

@@ -1121,7 +1121,7 @@ def download(ctx, database, force, **kwargs):
11211121
logger.add(lambda _: sys.exit(1), level="ERROR")
11221122
database = Path(database)
11231123
logger.info(f"Checking database installation at {database}")
1124-
check_db_installation(database, install_flag=True) # t
1124+
check_db_installation(database, force, install_flag=True) # t
11251125

11261126

11271127
"""
@@ -1319,7 +1319,7 @@ def long(
13191319

13201320
# check the mash database is installed
13211321
logger.info("Checking database installation.")
1322-
check_db_installation(Path(database), install_flag=False)
1322+
check_db_installation(Path(database), force=False, install_flag=False)
13231323
# will only continue if successful
13241324
logger.info("Database successfully checked.")
13251325

src/plassembler/utils/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.1
1+
1.6.2

src/plassembler/utils/db.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
from plassembler.utils.cleanup import remove_directory
1717

1818

19-
def check_db_installation(db_dir: Path, install_flag: bool):
19+
def check_db_installation(db_dir: Path, force: bool, install_flag: bool):
2020
"""checks database is installed correctly
2121
:param db_dir: database directory
22+
:param force: boolean if force is true
2223
:param install_flag: whether to check or install database
2324
"""
2425
# Mash files
@@ -28,6 +29,25 @@ def check_db_installation(db_dir: Path, install_flag: bool):
2829
f1: Path = db_dir / f"{mash_db_names[0]}"
2930
f2: Path = db_dir / f"{mash_db_names[1]}"
3031

32+
if install_flag is True:
33+
if force is True:
34+
if os.path.isdir(db_dir) is True:
35+
logger.info(f"Removing the directory {db_dir} as --force was specified")
36+
shutil.rmtree(db_dir)
37+
else:
38+
logger.info(
39+
f"--force was specified even though the directory {db_dir} does not already exist. Continuing"
40+
)
41+
else:
42+
if os.path.isdir(db_dir) is True:
43+
logger.error(
44+
f"Directory {db_dir} already exists and force was not specified. Please specify -f or --force to overwrite {db_dir}"
45+
)
46+
47+
# instantiate outdir
48+
if os.path.isdir(db_dir) is False:
49+
os.mkdir(db_dir)
50+
3151
if f1.exists() and f2.exists():
3252
logger.info(f"PLSDB Database mash sketch at {f1} exists.")
3353
logger.info(f"PLSDB Database tsv metadata file at {f2} exists.")
@@ -49,20 +69,12 @@ def check_db_installation(db_dir: Path, install_flag: bool):
4969

5070

5171
def get_database_zenodo(db_dir: Path):
52-
logger.info("Downloading Plassembler Database.")
72+
logger.info(f"Downloading Plassembler Database to the directory {db_dir}")
5373
tarball = "201123_plassembler_v1.5.0_databases.tar.gz"
5474
tar_path = Path(f"{db_dir}/{tarball}")
5575
db_url = "https://zenodo.org/record/10158040/files/201123_plassembler_v1.5.0_databases.tar.gz"
5676
requiredmd5 = "3a24bacc05bb857dc044fc6662b58db7"
5777

58-
# remvoe the directory
59-
if os.path.exists(db_dir):
60-
shutil.rmtree(db_dir)
61-
62-
# make db dir
63-
if not os.path.exists(db_dir):
64-
os.mkdir(db_dir)
65-
6678
try:
6779
with tar_path.open("wb") as fh_out, requests.get(db_url, stream=True) as resp:
6880
total_length = resp.headers.get("content-length")

tests/test_db.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,12 @@ class test_install(unittest.TestCase):
4040

4141
# for plassembler run
4242
def test_check_db_installation_good(self):
43-
check_db_installation(db_path, False)
43+
check_db_installation(db_path, force=False, install_flag=False)
4444

4545
# for plassembler download
4646
def test_check_db_installation_good_d(self):
47-
check_db_installation(db_path, True)
47+
check_db_installation(db_path, force=True, install_flag=True)
4848

4949
def test_check_db_installation_bad(self):
5050
with self.assertRaises(SystemExit):
51-
check_db_installation(val_data, False)
52-
53-
def test_get_database_zenodo(self):
54-
expected_return = True
55-
get_database_zenodo(tmp_db_path)
56-
# remove it after downloading
57-
shutil.rmtree(tmp_db_path)
58-
self.assertEqual(expected_return, True)
51+
check_db_installation(val_data, force=False, install_flag=False)

0 commit comments

Comments
 (0)