From: Shane Jaroch Date: Tue, 12 Jul 2022 19:19:23 +0000 (-0400) Subject: fix production issue, reorganize & shrink tarball X-Git-Tag: v0.2.4^2 X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=refs%2Fpull%2F5%2Fhead;p=nutratech%2Fcli.git fix production issue, reorganize & shrink tarball exclude 2nd LICENSE in ntclient/ntsqlite from pypi move nt_init out of main services call bump version move changelog back up, reduce tarball size fix: NTSQLITE_DESTINATION is not defined bump to release version --- diff --git a/ntclient/CHANGELOG.rst b/CHANGELOG.rst similarity index 100% rename from ntclient/CHANGELOG.rst rename to CHANGELOG.rst diff --git a/MANIFEST.in b/MANIFEST.in index 1345ae8..58ecfc5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,16 +1,8 @@ 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__/* diff --git a/ntclient/__init__.py b/ntclient/__init__.py index 57717f8..9f234f2 100755 --- a/ntclient/__init__.py +++ b/ntclient/__init__.py @@ -35,7 +35,7 @@ from ntclient.ntsqlite.sql import NT_DB_NAME # Package info __title__ = "nutra" -__version__ = "0.2.3" +__version__ = "0.2.4" __author__ = "Shane Jaroch" __email__ = "chown_tee@proton.me" __license__ = "GPL v3" diff --git a/ntclient/ntsqlite b/ntclient/ntsqlite index 4f9eec2..47c6db2 160000 --- a/ntclient/ntsqlite +++ b/ntclient/ntsqlite @@ -1 +1 @@ -Subproject commit 4f9eec211c1073f093411f15e29cb2347534e7cd +Subproject commit 47c6db2a418db690ba1b8e407756240ec2f296f3 diff --git a/ntclient/persistence/sql/nt/__init__.py b/ntclient/persistence/sql/nt/__init__.py index cc1e750..5300f1d 100644 --- a/ntclient/persistence/sql/nt/__init__.py +++ b/ntclient/persistence/sql/nt/__init__.py @@ -2,11 +2,60 @@ 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) @@ -29,12 +78,6 @@ def nt_sqlite_connect(version_check=True) -> sqlite3.Connection: 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() diff --git a/ntclient/services/__init__.py b/ntclient/services/__init__.py index b57f0db..4f3450e 100644 --- a/ntclient/services/__init__.py +++ b/ntclient/services/__init__.py @@ -1,17 +1,11 @@ """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): @@ -35,31 +29,7 @@ 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 diff --git a/requirements-lint.txt b/requirements-lint.txt index 642306b..1d5b3b6 100644 --- a/requirements-lint.txt +++ b/requirements-lint.txt @@ -5,4 +5,4 @@ doc8~=0.11 flake8~=4.0 mypy~=0.960 pylint~=2.13 -yamllint~=1.26 +yamllint~=1.27