include requirements.txt
include requirements-*.txt
-include ntclient/LICENSE
-include ntclient/CHANGELOG.rst
-
-include ntclient/ntsqlite/LICENSE
-include ntclient/ntsqlite/README.rst
-include ntclient/ntsqlite/CHANGELOG.rst
include ntclient/ntsqlite/sql/*.sql
include ntclient/ntsqlite/sql/data/*.csv
include ntclient/ntsqlite/sql/upgrade_scripts/*.sql
global-exclude nt.sqlite3
-
-global-exclude __pycache__/*
# Package info
__title__ = "nutra"
-__version__ = "0.2.3"
+__version__ = "0.2.4"
__author__ = "Shane Jaroch"
__email__ = "chown_tee@proton.me"
__license__ = "GPL v3"
-Subproject commit 4f9eec211c1073f093411f15e29cb2347534e7cd
+Subproject commit 47c6db2a418db690ba1b8e407756240ec2f296f3
import os
import sqlite3
-from ntclient import NT_DB_NAME, NUTRA_DIR, __db_target_nt__
+from ntclient import (
+ NT_DB_NAME,
+ NTSQLITE_BUILDPATH,
+ NTSQLITE_DESTINATION,
+ NUTRA_DIR,
+ __db_target_nt__,
+)
from ntclient.persistence.sql import _sql, _sql_headers, version
from ntclient.utils.exceptions import SqlConnectError, SqlInvalidVersionError
+def nt_ver() -> str:
+ """Gets version string for nt.sqlite3 database"""
+ con = nt_sqlite_connect(version_check=False)
+ return version(con)
+
+
+def nt_init() -> None:
+ """
+ Similar to usda_init(). This builds the nt.sqlite3 image, and copies into ~/.nutra
+ """
+
+ # TODO: don't overwrite,
+ # verbose toggle for download,
+ # option to upgrade
+ if os.path.isfile(NTSQLITE_DESTINATION):
+ if nt_ver() != __db_target_nt__:
+ # TODO: hard requirement? raise error?
+ print(
+ "WARN: upgrades/downgrades not supported "
+ + "(actual: {0} vs. target: {1}), ".format(nt_ver(), __db_target_nt__)
+ + "please remove `~/.nutra/nt.sqlite3` file or ignore this warning"
+ )
+ print("..DONE!")
+ os.remove(NTSQLITE_BUILDPATH) # clean up
+ else:
+ # TODO: is this logic (and these error messages) the best?
+ # what if .isdir() == True ? Fails with stacktrace?
+ os.rename(NTSQLITE_BUILDPATH, NTSQLITE_DESTINATION)
+ if not nt_ver() == __db_target_nt__:
+ raise SqlInvalidVersionError(
+ "ERROR: nt target [{0}] mismatch actual [{1}], ".format(
+ __db_target_nt__, nt_ver()
+ )
+ + ", please contact support or try again"
+ )
+ print("..DONE!")
+
+
+# ------------------------------------------------
+# SQL connection & utility methods
+# ------------------------------------------------
+
+
def nt_sqlite_connect(version_check=True) -> sqlite3.Connection:
"""Connects to the nt.sqlite3 file, or throws an exception"""
db_path = os.path.join(NUTRA_DIR, NT_DB_NAME)
raise SqlConnectError("ERROR: nt database doesn't exist, please run `nutra init`")
-def nt_ver() -> str:
- """Gets version string for nt.sqlite3 database"""
- con = nt_sqlite_connect(version_check=False)
- return version(con)
-
-
def sql(query, values=None) -> list:
"""Executes a SQL command to nt.sqlite3"""
con = nt_sqlite_connect()
"""Services module, currently only home to SQL/persistence init method"""
import os
-from ntclient import (
- NTSQLITE_BUILDPATH,
- NTSQLITE_DESTINATION,
- NUTRA_DIR,
- __db_target_nt__,
-)
+from ntclient import NUTRA_DIR
from ntclient.ntsqlite.sql import build_ntsqlite
-from ntclient.persistence.sql.nt import nt_ver
+from ntclient.persistence.sql.nt import nt_init
from ntclient.persistence.sql.usda import usda_init
from ntclient.services import analyze, recipe, usda
-from ntclient.utils.exceptions import SqlInvalidVersionError
def init(yes=False):
print("Nutra db ", end="")
build_ntsqlite()
- # TODO: don't overwrite,
- # verbose toggle for download,
- # option to upgrade
- if os.path.isfile(NTSQLITE_DESTINATION):
- if nt_ver() != __db_target_nt__:
- # TODO: hard requirement? raise error?
- print(
- "WARN: upgrades/downgrades not supported "
- + "(actual: {0} vs. target: {1}), ".format(nt_ver(), __db_target_nt__)
- + "please remove `~/.nutra/nt.sqlite3` file or ignore this warning"
- )
- print("..DONE!")
- os.remove(NTSQLITE_BUILDPATH) # clean up
- else:
- # TODO: is this logic (and these error messages) the best?
- # what if .isdir() == True ? Fails with stacktrace?
- os.rename(NTSQLITE_BUILDPATH, NTSQLITE_DESTINATION)
- if not nt_ver() == __db_target_nt__:
- raise SqlInvalidVersionError(
- "ERROR: nt target [{0}] mismatch actual [{1}], ".format(
- __db_target_nt__, nt_ver()
- )
- + ", please contact support or try again"
- )
- print("..DONE!")
+ nt_init()
print("\nAll checks have passed!")
return 0, True
flake8~=4.0
mypy~=0.960
pylint~=2.13
-yamllint~=1.26
+yamllint~=1.27