From 8189628da671ddd4205a114e5d14601c12519bc0 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Sun, 17 Jul 2022 14:00:50 -0400 Subject: [PATCH] Dev - win32 testing and Makefile fixes (#6) * don't include upgrade_scripts/ for now (empty) * try adding test-win32 job * test alias; skip tests on win32 (for now) * win32 workflow: line endings, better note we're skipping `make test` to directly test out `make install && nutra init` * fix PY_SYS_INTERPRETER on Windows_NT * uncomment target * automate init with -y flag to skip stdin * add debug flag to init -y * remove .env.bat (not need anymore, Makefile does) * bump version * separate workflows for linux / win32 * update readme badges * rename to NUTRA_HOME, try full path * test out on my windows VM --- .env.bat | 1 - .../workflows/{test.yml => test-linux.yml} | 28 ++++++++-- .github/workflows/test-win32.yml | 55 +++++++++++++++++++ CHANGELOG.rst | 1 + MANIFEST.in | 1 - Makefile | 10 +++- README.rst | 14 ++++- ntclient/__init__.py | 8 ++- ntclient/persistence/__init__.py | 4 +- ntclient/persistence/sql/nt/__init__.py | 4 +- ntclient/persistence/sql/usda/__init__.py | 10 ++-- ntclient/services/__init__.py | 6 +- tests/test_cli.py | 8 ++- 13 files changed, 121 insertions(+), 29 deletions(-) delete mode 100644 .env.bat rename .github/workflows/{test.yml => test-linux.yml} (52%) create mode 100644 .github/workflows/test-win32.yml diff --git a/.env.bat b/.env.bat deleted file mode 100644 index 4db2110..0000000 --- a/.env.bat +++ /dev/null @@ -1 +0,0 @@ -set PY_SYS_INTERPRETER=python3 diff --git a/.github/workflows/test.yml b/.github/workflows/test-linux.yml similarity index 52% rename from .github/workflows/test.yml rename to .github/workflows/test-linux.yml index 4091385..98df1bf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test-linux.yml @@ -1,11 +1,12 @@ --- -name: CI +name: test-linux "on": push: {} jobs: - test: + test-linux: runs-on: ubuntu-latest + steps: - name: Checkout uses: actions/checkout@v3 @@ -16,7 +17,7 @@ jobs: uses: actions/cache@v3 with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} restore-keys: | ${{ runner.os }}-pip- @@ -26,8 +27,25 @@ jobs: pip install testresources==2.0.1 make _deps + # TODO: Tests for: python-argcomplete (tab-completion) + - name: Test + run: | + export NUTRA_HOME=$(pwd)/tests/.nutra.test + make _test + - name: Lint run: make _lint - - name: Test - run: make _test + - name: Install + run: make install + + - name: Basic Tests / CLI / Integration + run: | + n -v + nutra -d init -y + nutra --no-pager nt + nutra --no-pager sort -c 789 + nutra --no-pager search ultraviolet mushrooms + nutra --no-pager anl 9050 + nutra --no-pager recipe + nutra day tests/resources/day/human-test.csv diff --git a/.github/workflows/test-win32.yml b/.github/workflows/test-win32.yml new file mode 100644 index 0000000..264a006 --- /dev/null +++ b/.github/workflows/test-win32.yml @@ -0,0 +1,55 @@ +--- +name: test-win32 +"on": + push: {} + +jobs: + test-win32: + runs-on: windows-latest + + steps: + - name: Configure Line Endings / git / LF + run: | + git config --global core.autocrlf input + git config --global core.eol lf + + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Reload Cache / pip + uses: actions/cache@v3 + with: + path: ~\AppData\Local\pip\Cache + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install requirements + run: | + make _deps + + # TODO: Tests for: python-argcomplete (tab-completion) + - name: Test + run: | + $curDir = (Get-Location).toString() + $Env:NUTRA_HOME = $curDir + '/tests/.nutra.test' + make _test + + - name: Lint + run: make _lint + + - name: Install + run: make install + + - name: Basic Tests / CLI / Integration + run: | + n -v + nutra -d init -y + nutra --no-pager nt + nutra --no-pager sort -c 789 + nutra --no-pager search ultraviolet mushrooms + nutra --no-pager anl 9050 + nutra --no-pager recipe + nutra day tests/resources/day/human-test.csv diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d60c838..6742be6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -16,6 +16,7 @@ Added ~~~~~ - Basic functionality of ``import`` and ``export`` sub-commands +- Automated CI/CD integration tests for ``Windows`` platform diff --git a/MANIFEST.in b/MANIFEST.in index 58ecfc5..16472c8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,6 +3,5 @@ include requirements-*.txt include ntclient/ntsqlite/sql/*.sql include ntclient/ntsqlite/sql/data/*.csv -include ntclient/ntsqlite/sql/upgrade_scripts/*.sql global-exclude nt.sqlite3 diff --git a/Makefile b/Makefile index fef247a..5f24690 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,15 @@ _venv: # Install requirements # --------------------------------------- -PY_SYS_INTERPRETER ?= /usr/bin/python3 +PY_SYS_INTERPRETER ?= +ifeq ($(PY_SYS_INTERPRETER),) + ifeq ($(OS),Windows_NT) + PY_SYS_INTERPRETER += python3 + else + PY_SYS_INTERPRETER += /usr/bin/python3 + endif +endif + PY_VIRTUAL_INTERPRETER ?= python PIP ?= $(PY_VIRTUAL_INTERPRETER) -m pip diff --git a/README.rst b/README.rst index 1c2c8bc..7e47c3a 100644 --- a/README.rst +++ b/README.rst @@ -2,20 +2,28 @@ nutratracker ************** +.. image:: https://github.com/nutratech/cli/actions/workflows/test-linux.yml/badge.svg + :target: https://github.com/nutratech/cli/actions/workflows/test-linux.yml + :alt: Build status unknown (Linux) +.. image:: https://github.com/nutratech/cli/actions/workflows/test-win32.yml/badge.svg + :target: https://github.com/nutratech/cli/actions/workflows/test-win32.yml + :alt: Build status unknown (Windows) + .. image:: https://badgen.net/pypi/v/nutra :target: https://pypi.org/project/nutra/ :alt: Latest version unknown -.. image:: https://github.com/nutratech/cli/actions/workflows/test.yml/badge.svg - :target: https://github.com/nutratech/cli/actions/workflows/test.yml - :alt: Build status unknown + .. image:: https://pepy.tech/badge/nutra/month :target: https://pepy.tech/project/nutra :alt: Monthly downloads unknown + .. image:: https://img.shields.io/pypi/pyversions/nutra.svg :alt: Python3 (3.4 - 3.10) + .. image:: https://badgen.net/badge/code%20style/black/000 :target: https://github.com/ambv/black :alt: Code style: black + .. image:: https://badgen.net/pypi/license/nutra :target: https://www.gnu.org/licenses/gpl-3.0.en.html :alt: License GPL-3 diff --git a/ntclient/__init__.py b/ntclient/__init__.py index 9f234f2..20b551f 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.4" +__version__ = "0.2.5.dev0" __author__ = "Shane Jaroch" __email__ = "chown_tee@proton.me" __license__ = "GPL v3" @@ -49,14 +49,16 @@ USDA_XZ_SHA256 = "25dba8428ced42d646bec704981d3a95dc7943240254e884aad37d59eee961 # Global variables ROOT_DIR = os.path.abspath(os.path.dirname(__file__)) -NUTRA_DIR = os.getenv("NUTRA_HOME", os.path.join(os.path.expanduser("~"), ".nutra")) +NUTRA_HOME = os.getenv("NUTRA_HOME", os.path.join(os.path.expanduser("~"), ".nutra")) USDA_DB_NAME = "usda.sqlite" # NOTE: NT_DB_NAME = "nt.sqlite3" is defined in ntclient.ntsqlite.sql DEBUG = False PAGING = True NTSQLITE_BUILDPATH = os.path.join(ROOT_DIR, "ntsqlite", "sql", NT_DB_NAME) -NTSQLITE_DESTINATION = os.path.join(NUTRA_DIR, NT_DB_NAME) +NTSQLITE_DESTINATION = os.path.join(NUTRA_HOME, NT_DB_NAME) +print(NTSQLITE_BUILDPATH) +print(NTSQLITE_DESTINATION) # Check Python version PY_MIN_VER = (3, 4, 0) diff --git a/ntclient/persistence/__init__.py b/ntclient/persistence/__init__.py index d48acaa..5a97959 100644 --- a/ntclient/persistence/__init__.py +++ b/ntclient/persistence/__init__.py @@ -8,12 +8,12 @@ Created on Sat Mar 23 13:09:07 2019 import json import os -from ntclient import NUTRA_DIR +from ntclient import NUTRA_HOME # TODO: init, handle when it doesn't exist yet # TODO: prompt to create profile if copying default `prefs.json` with PROFILE_ID: -1 # (non-existent) -PREFS_FILE = os.path.join(NUTRA_DIR, "prefs.json") +PREFS_FILE = os.path.join(NUTRA_HOME, "prefs.json") PREFS = {} PROFILE_ID = None diff --git a/ntclient/persistence/sql/nt/__init__.py b/ntclient/persistence/sql/nt/__init__.py index 5300f1d..5860999 100644 --- a/ntclient/persistence/sql/nt/__init__.py +++ b/ntclient/persistence/sql/nt/__init__.py @@ -6,7 +6,7 @@ from ntclient import ( NT_DB_NAME, NTSQLITE_BUILDPATH, NTSQLITE_DESTINATION, - NUTRA_DIR, + NUTRA_HOME, __db_target_nt__, ) from ntclient.persistence.sql import _sql, _sql_headers, version @@ -58,7 +58,7 @@ def nt_init() -> None: 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) + db_path = os.path.join(NUTRA_HOME, NT_DB_NAME) if os.path.isfile(db_path): con = sqlite3.connect(db_path) con.row_factory = sqlite3.Row diff --git a/ntclient/persistence/sql/usda/__init__.py b/ntclient/persistence/sql/usda/__init__.py index 4c3df95..ba9e6eb 100644 --- a/ntclient/persistence/sql/usda/__init__.py +++ b/ntclient/persistence/sql/usda/__init__.py @@ -4,7 +4,7 @@ import sqlite3 import tarfile import urllib.request -from ntclient import NUTRA_DIR, USDA_DB_NAME, __db_target_usda__ +from ntclient import NUTRA_HOME, USDA_DB_NAME, __db_target_usda__ from ntclient.persistence.sql import _sql, _sql_headers, version from ntclient.utils.exceptions import SqlConnectError, SqlInvalidVersionError @@ -20,7 +20,7 @@ def usda_init(yes=False) -> None: if yes or input_agree().lower() == "y": # TODO: save with version in filename? Don't re-download tarball, just extract? - save_path = os.path.join(NUTRA_DIR, "%s.tar.xz" % USDA_DB_NAME) + save_path = os.path.join(NUTRA_HOME, "%s.tar.xz" % USDA_DB_NAME) # Download usda.sqlite3.tar.xz print("curl -L %s -o %s.tar.xz" % (url, USDA_DB_NAME)) @@ -29,7 +29,7 @@ def usda_init(yes=False) -> None: # Extract the archive with tarfile.open(save_path, mode="r:xz") as usda_sqlite_file: print("\ntar xvf %s.tar.xz" % USDA_DB_NAME) - usda_sqlite_file.extractall(NUTRA_DIR) + usda_sqlite_file.extractall(NUTRA_HOME) print("==> done downloading %s" % USDA_DB_NAME) @@ -40,7 +40,7 @@ def usda_init(yes=False) -> None: ) ) - if USDA_DB_NAME not in os.listdir(NUTRA_DIR): + if USDA_DB_NAME not in os.listdir(NUTRA_HOME): print("INFO: usda.sqlite3 doesn't exist, is this a fresh install?") download_extract_usda() elif usda_ver() != __db_target_usda__: @@ -65,7 +65,7 @@ def usda_sqlite_connect(version_check=True) -> sqlite3.Connection: """Connects to the usda.sqlite3 file, or throws an exception""" # TODO: support as customizable env var ? - db_path = os.path.join(NUTRA_DIR, USDA_DB_NAME) + db_path = os.path.join(NUTRA_HOME, USDA_DB_NAME) if os.path.isfile(db_path): con = sqlite3.connect(db_path) # con.row_factory = sqlite3.Row # see: https://chrisostrouchov.com/post/python_sqlite/ diff --git a/ntclient/services/__init__.py b/ntclient/services/__init__.py index 4f3450e..60e0ae7 100644 --- a/ntclient/services/__init__.py +++ b/ntclient/services/__init__.py @@ -1,7 +1,7 @@ """Services module, currently only home to SQL/persistence init method""" import os -from ntclient import NUTRA_DIR +from ntclient import NUTRA_HOME from ntclient.ntsqlite.sql import build_ntsqlite from ntclient.persistence.sql.nt import nt_init from ntclient.persistence.sql.usda import usda_init @@ -18,8 +18,8 @@ def init(yes=False): 4. prefs.json """ print("Nutra directory ", end="") - if not os.path.isdir(NUTRA_DIR): - os.makedirs(NUTRA_DIR, 0o755) + if not os.path.isdir(NUTRA_HOME): + os.makedirs(NUTRA_HOME, 0o755) print("..DONE!") # TODO: print off checks, return False if failed diff --git a/tests/test_cli.py b/tests/test_cli.py index 555614c..5450227 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -12,7 +12,7 @@ import pytest from ntclient import ( NTSQLITE_BUILDPATH, - NUTRA_DIR, + NUTRA_HOME, USDA_DB_NAME, __db_target_nt__, __db_target_usda__, @@ -30,7 +30,9 @@ from ntclient.services import init from ntclient.utils.exceptions import SqlInvalidVersionError TEST_HOME = os.path.dirname(os.path.abspath(__file__)) -os.environ["NUTRA_HOME"] = os.path.join(TEST_HOME, ".nutra.test") +# NOTE: this doesn't work currently, b/c it's already read up (in imports above) +# We're just setting it on the shell, as an env var +# os.environ["NUTRA_HOME"] = os.path.join(TEST_HOME, ".nutra.test") # TODO: integration tests.. create user, recipe, log.. analyze & compare arg_parser = build_argparser() @@ -259,7 +261,7 @@ def test_802_usda_downloads_fresh_if_missing_or_deleted(): # remove whole `.nutra` in a special test? try: # TODO: export USDA_DB_PATH at package level, don't pepper os.path.join() throughout code? - usda_path = os.path.join(NUTRA_DIR, USDA_DB_NAME) + usda_path = os.path.join(NUTRA_HOME, USDA_DB_NAME) os.remove(usda_path) except (FileNotFoundError, PermissionError) as err: # TODO: resolve PermissionError on Windows -- 2.52.0