From fa7d4133c911578f94234363464d6797feafdae6 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Thu, 13 Jun 2024 10:06:21 -0400 Subject: [PATCH 1/2] refactor: don't use deprecated timezone-ignorant datetime methods --- src/biocommons/seqrepo/fastadir/fastadir.py | 2 +- src/biocommons/seqrepo/seqaliasdb/seqaliasdb.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/biocommons/seqrepo/fastadir/fastadir.py b/src/biocommons/seqrepo/fastadir/fastadir.py index 83b3851..4f8a0e2 100644 --- a/src/biocommons/seqrepo/fastadir/fastadir.py +++ b/src/biocommons/seqrepo/fastadir/fastadir.py @@ -194,7 +194,7 @@ def store(self, seq_id: str, seq: str) -> str: # <------ dir_ -----> # <----------- path -----------> if self._writing is None: - reldir = datetime.datetime.utcnow().strftime("%Y/%m%d/%H%M") + reldir = datetime.datetime.now(datetime.UTC).strftime("%Y/%m%d/%H%M") basename = str(time.time()) + ".fa.bgz" relpath = os.path.join(reldir, basename) diff --git a/src/biocommons/seqrepo/seqaliasdb/seqaliasdb.py b/src/biocommons/seqrepo/seqaliasdb/seqaliasdb.py index 916106d..23567c0 100644 --- a/src/biocommons/seqrepo/seqaliasdb/seqaliasdb.py +++ b/src/biocommons/seqrepo/seqaliasdb/seqaliasdb.py @@ -1,3 +1,4 @@ +import datetime import logging import sqlite3 from importlib import resources @@ -22,6 +23,9 @@ raise ImportError(msg) +sqlite3.register_converter("timestamp", lambda val: datetime.datetime.fromisoformat(val.decode())) + + class SeqAliasDB(object): """Implements a sqlite database of sequence aliases""" From a13a4a37a9ef1bb60f987e270e09a262db6910c9 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Thu, 13 Jun 2024 10:22:00 -0400 Subject: [PATCH 2/2] use older utc class --- src/biocommons/seqrepo/fastadir/fastadir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/biocommons/seqrepo/fastadir/fastadir.py b/src/biocommons/seqrepo/fastadir/fastadir.py index 4f8a0e2..21090ac 100644 --- a/src/biocommons/seqrepo/fastadir/fastadir.py +++ b/src/biocommons/seqrepo/fastadir/fastadir.py @@ -194,7 +194,7 @@ def store(self, seq_id: str, seq: str) -> str: # <------ dir_ -----> # <----------- path -----------> if self._writing is None: - reldir = datetime.datetime.now(datetime.UTC).strftime("%Y/%m%d/%H%M") + reldir = datetime.datetime.now(datetime.timezone.utc).strftime("%Y/%m%d/%H%M") basename = str(time.time()) + ".fa.bgz" relpath = os.path.join(reldir, basename)