Skip to content

Commit

Permalink
fix sbt fsstorage to not always create directory (#1539)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed May 22, 2021
1 parent ee4a8a8 commit e47bdb5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/sourmash/sbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def save(self, path, storage=None, sparseness=0.0, structure_only=False):
backend = "FSStorage"
name = os.path.basename(path[:-8])
subdir = '.sbt.{}'.format(name)
storage_args = FSStorage("", subdir).init_args()
storage_args = FSStorage("", subdir, make_dirs=False).init_args()
storage.save(subdir + "/", b"")
storage.subdir = subdir
index_filename = os.path.abspath(path)
Expand Down
9 changes: 5 additions & 4 deletions src/sourmash/sbt_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ def can_open(self, location):

class FSStorage(Storage):

def __init__(self, location, subdir):
def __init__(self, location, subdir, make_dirs=True):
self.location = location
self.subdir = subdir

fullpath = os.path.join(location, subdir)
if not os.path.exists(fullpath):
os.makedirs(fullpath)
if make_dirs:
fullpath = os.path.join(location, subdir)
if not os.path.exists(fullpath):
os.makedirs(fullpath)

def init_args(self):
return {'path': self.subdir}
Expand Down
8 changes: 6 additions & 2 deletions tests/test_sbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,9 @@ def test_gather_single_return(c):
assert results[0][0] == 1.0


@utils.in_tempdir
def test_sbt_protein_command_index(c):
def test_sbt_protein_command_index(runtmp):
c = runtmp

# test command-line creation of SBT database with protein sigs
sigfile1 = utils.get_test_data('prot/protein/GCA_001593925.1_ASM159392v1_protein.faa.gz.sig')
sigfile2 = utils.get_test_data('prot/protein/GCA_001593935.1_ASM159393v1_protein.faa.gz.sig')
Expand All @@ -794,6 +795,9 @@ def test_sbt_protein_command_index(c):
c.run_sourmash('index', db_out, sigfile1, sigfile2,
'--scaled', '100', '-k', '19', '--protein')

# check to make sure .sbt.protein directory doesn't get created
assert not os.path.exists(c.output('.sbt.protein'))

db2 = load_sbt_index(db_out)

sig1 = sourmash.load_one_signature(sigfile1)
Expand Down

0 comments on commit e47bdb5

Please sign in to comment.