Repository: cogent3/cogent3
Pull request #1251 (2022-12-20 05:20:31)

Data store refactor - merge new test to develop


Patch:
diff --git a/README.md b/README.md
index e1a338a5a..0f3072751 100644
--- a/README.md
+++ b/README.md
@@ -3,8 +3,9 @@
 
 [![Build Status](https://github.com/cogent3/cogent3/workflows/CI/badge.svg?branch=develop)](https://github.com/cogent3/cogent3/actions?workflow=CI)
 [![coverall](https://coveralls.io/repos/github/cogent3/cogent3/badge.svg?branch=develop)](https://coveralls.io/github/cogent3/cogent3?branch=develop)
+[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/cogent3/cogent3.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/cogent3/cogent3/context:python)
 
-[![Python 3.8+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads/release/python-370/)
+[![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads/release/python-370/)
 ![Using Black Formatting](https://img.shields.io/badge/code%20style-black-000000.svg)
 
 ## `cogent3`
diff --git a/src/cogent3/app/data_store.py b/src/cogent3/app/data_store.py
index 69139510b..21def7208 100644
--- a/src/cogent3/app/data_store.py
+++ b/src/cogent3/app/data_store.py
@@ -60,6 +60,7 @@ class DataStoreMember(str):  # pragma: no cover
             "cogent3.data_store_new.DataMember",
             "2023.3",
             "use cogent3.data_store_new.DataMember",
+            stack_level=1,
         )
 
         result = str.__new__(klass, name)
@@ -121,6 +122,7 @@ class ReadOnlyDataStoreBase:  # pragma: no cover
             "cogent3.data_store_new.DataStoreDirectory",
             "2023.3",
             "use cogent3.data_store_new.DataStoreABC",
+            stack_level=1,
         )
 
         # todo this approach to caching persistent arguments for reconstruction
@@ -427,6 +429,7 @@ class WritableDataStoreBase:  # pragma: no cover
             "cogent3.data_store_new.DataStoreDirectory",
             "2023.3",
             "use cogent3.data_store_new.DataStoreABC",
+            stack_level=1,
         )
 
         d = locals()
diff --git a/src/cogent3/app/data_store_new.py b/src/cogent3/app/data_store_new.py
index 6ab700cf1..3fcb15ee2 100644
--- a/src/cogent3/app/data_store_new.py
+++ b/src/cogent3/app/data_store_new.py
@@ -494,6 +494,7 @@ class DataStoreDirectory(DataStoreABC):
         return member
 
     def write_not_completed(self, *, unique_id: str, data: str) -> DataMember:
+        (self.source / _NOT_COMPLETED_TABLE).mkdir(parents=True, exist_ok=True)
         member = self._write(
             subdir=_NOT_COMPLETED_TABLE, unique_id=unique_id, suffix="json", data=data
         )
@@ -502,6 +503,7 @@ class DataStoreDirectory(DataStoreABC):
         return member
 
     def write_log(self, *, unique_id: str, data: str) -> None:
+        (self.source / _LOG_TABLE).mkdir(parents=True, exist_ok=True)        
         _ = self._write(subdir=_LOG_TABLE, unique_id=unique_id, suffix="log", data=data)
 
     def md5(self, unique_id: str) -> Union[str, NoneType]:
diff --git a/src/cogent3/app/io.py b/src/cogent3/app/io.py
index 6d1447b6b..7990dadfe 100644
--- a/src/cogent3/app/io.py
+++ b/src/cogent3/app/io.py
@@ -96,6 +96,7 @@ def get_data_store(
         "cogent3.open_data_store",
         "2023.3",
         "renamed and now a top-level import",
+        stack_level=1,
     )
 
     return open_data_store(base_path=base_path, suffix=suffix, limit=limit)
@@ -136,6 +137,7 @@ class load_aligned:  # pragma: no cover
             "use cogent3.get_app('load_aligned')",
             "2023.3",
             "use cogent3.get_app()",
+            stack_level=1,
         )
 
         if moltype:
@@ -173,6 +175,7 @@ class load_unaligned:  # pragma: no cover
             "use cogent3.get_app('load_unaligned')",
             "2023.3",
             "use cogent3.get_app()",
+            stack_level=1,
         )
 
         if moltype:
@@ -223,6 +226,7 @@ class load_tabular:  # pragma: no coverv
             "use cogent3.get_app('load_tabular')",
             "2023.3",
             "use cogent3.get_app()",
+            stack_level=1,
         )
 
         self._sep = sep
@@ -340,6 +344,7 @@ class write_tabular(_checkpointable):  # pragma: no cover
             "use cogent3.get_app('write_tabular')",
             "2023.3",
             "use cogent3.get_app()",
+            stack_level=1,
         )
 
         super().__init__(
@@ -406,6 +411,7 @@ class write_seqs(_checkpointable):  # pragma: no cover
             "use cogent3.get_app('write_seqs')",
             "2023.3",
             "use cogent3.get_app()",
+            stack_level=1,
         )
 
         super().__init__(
@@ -462,6 +468,7 @@ class load_json:  # pragma: no cover
             "use cogent3.get_app('load_json')",
             "2023.3",
             "use cogent3.get_app()",
+            stack_level=1,
         )
 
     def main(self, path: IdentifierType) -> SerialisableType:
@@ -512,6 +519,7 @@ class write_json(_checkpointable):  # pragma: no cover
             "use cogent3.get_app('write_json')",
             "2023.3",
             "use cogent3.get_app()",
+            stack_level=1,
         )
 
         super().__init__(
@@ -566,6 +574,7 @@ class load_db:  # pragma: no cover
             "use cogent3.get_app('load_db')",
             "2023.3",
             "use cogent3.get_app()",
+            stack_level=1,
         )
 
     def main(self, identifier: IdentifierType) -> SerialisableType:
@@ -602,6 +611,7 @@ class write_db(_checkpointable):  # pragma: no cover
             "use cogent3.get_app('write_db')",
             "2023.3",
             "use cogent3.get_app()",
+            stack_level=1,
         )
 
         super().__init__(
diff --git a/src/cogent3/core/moltype.py b/src/cogent3/core/moltype.py
index 7e706ee0e..1b0a3e934 100644
--- a/src/cogent3/core/moltype.py
+++ b/src/cogent3/core/moltype.py
@@ -739,7 +739,7 @@ class MolType(object):
 
     def gettype(self):  # pragma: no cover
         """Return the moltype label."""
-        deprecated("method", "gettype", "get_type", "2023.6", "pep8")
+        deprecated("method", "gettype", "get_type", "2023.6", "pep8", stack_level=1)
         return self.label
 
     def get_type(self):  # pragma: no cover
diff --git a/src/cogent3/core/sequence.py b/src/cogent3/core/sequence.py
index 0bd486319..e2239ac1d 100644
--- a/src/cogent3/core/sequence.py
+++ b/src/cogent3/core/sequence.py
@@ -1041,7 +1041,7 @@ class Sequence(_Annotatable, SequenceI):
 
     def gettype(self):  # pragma: no cover
         """Return the sequence type."""
-        deprecated("method", "gettype", "get_type", "2023.6", "pep8")
+        deprecated("method", "gettype", "get_type", "2023.6", "pep8", stack_level=1)
         return self.get_type()
 
     def get_type(self):
@@ -1056,6 +1056,7 @@ class Sequence(_Annotatable, SequenceI):
             "resolved_ambiguities",
             "2023.6",
             "pep8",
+            stack_level=1,
         )
         return self.resolved_ambiguities()
 
diff --git a/src/cogent3/util/warning.py b/src/cogent3/util/warning.py
index 11cd1ae29..5ecf817ec 100644
--- a/src/cogent3/util/warning.py
+++ b/src/cogent3/util/warning.py
@@ -13,7 +13,7 @@ __email__ = "gavin.huttley@anu.edu.au"
 __status__ = "Production"
 
 
-def deprecated(_type, old, new, version, reason=None, stack_level=3):
+def deprecated(_type, old, new, version, reason=None, stack_level=2):
     """a convenience function for deprecating classes, functions, arguments.
 
     Parameters
@@ -39,10 +39,10 @@ def deprecated(_type, old, new, version, reason=None, stack_level=3):
 
     with catch_warnings():
         simplefilter("always")
-        _warn(msg, DeprecationWarning, stacklevel=stack_level)
+        _warn(msg, DeprecationWarning, stack_level)
 
 
-def discontinued(_type, name, version, reason=None, stack_level=3):
+def discontinued(_type, name, version, reason=None, stack_level=2):
     """convenience func to warn about discontinued attributes
 
     Parameters
@@ -58,6 +58,7 @@ def discontinued(_type, name, version, reason=None, stack_level=3):
         why, and what choices users have
     stack_level
         as per warnings.warn
+
     """
     msg = (
         f"{_type} {name} is discontinued, support will be stopped in version {version}"
@@ -67,4 +68,4 @@ def discontinued(_type, name, version, reason=None, stack_level=3):
 
     with catch_warnings():
         simplefilter("always")
-        _warn(msg, DeprecationWarning, stacklevel=stack_level)
+        _warn(msg, DeprecationWarning, stack_level)


Test patch:
diff --git a/tests/test_app/test_data_store_new.py b/tests/test_app/test_data_store_new.py
index ba4e35442..6036899fa 100644
--- a/tests/test_app/test_data_store_new.py
+++ b/tests/test_app/test_data_store_new.py
@@ -9,6 +9,8 @@ import pytest
 
 from scitrack import get_text_hexdigest
 
+import cogent3.app.io_new as io_app
+
 from cogent3.app.composable import NotCompleted
 from cogent3.app.data_store_new import (
     _MD5_TABLE,
@@ -574,3 +576,15 @@ def test_load_record_from_json():
         assert Id == "some.json"
         assert data_ == expected
         assert compl == True
+
+
+def test_write_read_not_completed(nc_dstore):
+    nc_dstore.drop_not_completed()
+    assert len(nc_dstore.not_completed) == 0
+    nc = NotCompleted("ERROR", "test", "for tracing", source="blah")
+    writer = io_app.write_seqs(data_store=nc_dstore)
+    writer.main(nc, identifier="blah")
+    assert len(nc_dstore.not_completed) == 1
+    got = nc_dstore.not_completed[0].read()
+    assert nc.to_json() == got
+
diff --git a/tests/test_app/test_io_new.py b/tests/test_app/test_io_new.py
index f7f8c85d9..ac1d7e746 100644
--- a/tests/test_app/test_io_new.py
+++ b/tests/test_app/test_io_new.py
@@ -452,7 +452,7 @@ def test_write_db_load_db(fasta_dir, tmp_dir):
     assert data_store.record_type == get_object_provenance(orig)
 
 
-def test_write_db_not_completed(tmp_dir):
+def test_write_read_db_not_completed(tmp_dir):
     from cogent3.app.sqlite_data_store import DataStoreSqlite
 
     nc = NotCompleted("ERROR", "test", "for tracing", source="blah")