Skip to content

Commit 0fa6448

Browse files
check sopa cache for #306
1 parent 9fbb48e commit 0fa6448

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

sopa/cli/app.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,26 @@ def convert(
6565
"""Read any technology data as a SpatialData object and save it as a `.zarr` directory.
6666
6767
Either `--technology` or `--config-path` has to be provided."""
68+
import shutil
6869
from pathlib import Path
6970

7071
from spatialdata import SpatialData
7172

7273
from sopa import io
73-
from sopa._constants import SopaKeys
74+
from sopa._constants import SopaFiles, SopaKeys
7475

7576
sdata_path: Path = Path(data_path).with_suffix(".zarr") if sdata_path is None else Path(sdata_path)
7677

77-
if not overwrite and sdata_path.exists():
78-
assert not any(sdata_path.iterdir()), (
79-
f"Zarr directory {sdata_path} already exists. Sopa will not continue to avoid overwritting files."
80-
)
81-
sdata_path.rmdir() # remove empty directory
78+
if sdata_path.exists():
79+
if overwrite:
80+
cache_dir = sdata_path.resolve() / SopaFiles.SOPA_CACHE_DIR
81+
if cache_dir.exists() and cache_dir.is_dir():
82+
shutil.rmtree(cache_dir)
83+
else:
84+
assert not any(sdata_path.iterdir()), (
85+
f"Zarr directory {sdata_path} already exists. Sopa will not continue to avoid overwritting files. Use the `--overwrite` flag to overwrite it."
86+
)
87+
sdata_path.rmdir() # remove empty directory
8288

8389
assert technology is not None or config_path is not None, "Provide the argument `--technology` or `--config-path`"
8490

0 commit comments

Comments
 (0)