Skip to content

Commit

Permalink
Remove snap archive creation in scan-run
Browse files Browse the repository at this point in the history
  • Loading branch information
horta committed Feb 13, 2024
1 parent 4153c9a commit 4bbfe9e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
2 changes: 0 additions & 2 deletions python-core/deciphon_core/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def run(self, snap: NewSnapFile):
if rc := lib.scan_run(self._cscan, str(snap.basename).encode()):
raise DeciphonError(rc)

snap.make_archive()

def interrupted(self) -> bool:
return lib.scan_interrupted(self._cscan)

Expand Down
18 changes: 18 additions & 0 deletions python-core/deciphon_core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ def must_have_extension(cls, x: FilePath):
class NewSnapFile(BaseModel):
path: Path

@classmethod
def create_from_prefix(cls, prefix: str):
try:
x = cls(path=Path(f"{prefix}.dcs").absolute())
except ValueError:
for i in range(1, 1001):
try:
x = cls(path=Path(f"{prefix}.{i}.dcs").absolute())
except ValueError:
continue
else:
break
else:
raise ValueError(
f"failed to find a noncolliding filename for prefix {prefix}"
)
return x

@field_validator("path")
def must_have_extension(cls, x: Path):
if x.suffix != ".dcs":
Expand Down
2 changes: 1 addition & 1 deletion python-core/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "deciphon-core"
version = "0.20.17"
version = "0.21.0"
description = "Python wrapper around the Deciphon C library"
authors = ["Danilo Horta <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 2 additions & 0 deletions python-core/tests/test_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def test_scan(tmp_path, files_path: Path):
for seq in sequences:
scan.add(seq)
scan.run(snapfile)
assert not scan.interrupted()
snapfile.make_archive()
assert scan.progress() == 100

shutil.unpack_archive(snapfile.path, format="zip")
Expand Down
25 changes: 25 additions & 0 deletions python-core/tests/test_snap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from pathlib import Path

from deciphon_core.schema import NewSnapFile


def test_collision(tmp_path: Path):
os.chdir(tmp_path)

x0 = NewSnapFile.create_from_prefix("snap")
x0.basename.mkdir()

x1 = NewSnapFile.create_from_prefix("snap")
x1.basename.mkdir()

x2 = NewSnapFile.create_from_prefix("snap")
x2.basename.mkdir()

x0.make_archive()
x1.make_archive()
x2.make_archive()

assert x0.basename.name == "snap"
assert x1.basename.name == "snap.1"
assert x2.basename.name == "snap.2"

0 comments on commit 4bbfe9e

Please sign in to comment.