Make program downward compatible until python 3.7
Add multi-version tests with nox to keep regressions from happening.
This commit is contained in:
parent
b9c89155e3
commit
031145db01
11 changed files with 109 additions and 42 deletions
|
|
@ -1,9 +1,9 @@
|
|||
# init.py
|
||||
import sys
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
try:
|
||||
from importlib.metadata import version as metadata_version
|
||||
else:
|
||||
except ImportError:
|
||||
from importlib_metadata import version as metadata_version
|
||||
|
||||
__version__ = str(metadata_version(__name__))
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
|
||||
from habitmove.nomiedata import Tracker
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Union
|
||||
from dataclasses import dataclass, field
|
||||
import re
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
|
|
@ -92,7 +94,8 @@ def add_to_database(
|
|||
(sql_id, repetition.timestamp, repetition.value),
|
||||
)
|
||||
except sqlite3.IntegrityError:
|
||||
# TODO better error handling
|
||||
# FIXME better error handling
|
||||
# TODO think about adapting this to allow importing into existing databases
|
||||
print(
|
||||
f"{sql_id}, {habit.name}: timestamp {datetime.fromtimestamp(repetition.timestamp/1000)} not unique, moving timestamp slightly."
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import sqlite3
|
||||
import sys
|
||||
|
||||
|
||||
def create_database(name):
|
||||
def create_database(db_file: str = ":memory:") -> sqlite3.Connection:
|
||||
"""create a database connection to the SQLite database
|
||||
specified by db_file
|
||||
:param db_file: database file
|
||||
|
|
@ -9,16 +10,14 @@ def create_database(name):
|
|||
"""
|
||||
conn = None
|
||||
try:
|
||||
conn = sqlite3.connect(name)
|
||||
conn = sqlite3.connect(db_file)
|
||||
return conn
|
||||
except sqlite3.Error as e:
|
||||
print(e)
|
||||
|
||||
return conn
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def create_tables(db):
|
||||
c = db.cursor()
|
||||
def create_tables(c: sqlite3.Cursor):
|
||||
c.execute(
|
||||
""" CREATE TABLE IF NOT EXISTS Habits (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
|
|
@ -51,8 +50,7 @@ def create_tables(db):
|
|||
)
|
||||
|
||||
|
||||
def create_constraints(db):
|
||||
c = db.cursor()
|
||||
def create_constraints(c: sqlite3.Cursor):
|
||||
c.execute(
|
||||
""" CREATE UNIQUE INDEX IF NOT EXISTS idx_repetitions_habit_timestamp
|
||||
on Repetitions( habit, timestamp);
|
||||
|
|
@ -60,15 +58,15 @@ def create_constraints(db):
|
|||
)
|
||||
|
||||
|
||||
def create_pragma(db):
|
||||
c = db.cursor()
|
||||
def create_pragma(c: sqlite3.Cursor):
|
||||
c.execute(""" PRAGMA user_version = 24; """)
|
||||
c.execute(""" PRAGMA schema_version = 30; """)
|
||||
|
||||
|
||||
def migrate(name):
|
||||
db = create_database(name)
|
||||
create_tables(db)
|
||||
create_constraints(db)
|
||||
create_pragma(db)
|
||||
def migrate(fname):
|
||||
db = create_database(fname)
|
||||
c = db.cursor()
|
||||
create_tables(c)
|
||||
create_constraints(c)
|
||||
create_pragma(c)
|
||||
return db
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue