Dev - win32 testing and Makefile fixes (#6)
authorShane Jaroch <chown_tee@proton.me>
Sun, 17 Jul 2022 18:00:50 +0000 (14:00 -0400)
committerGitHub <noreply@github.com>
Sun, 17 Jul 2022 18:00:50 +0000 (14:00 -0400)
* 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

13 files changed:
.env.bat [deleted file]
.github/workflows/test-linux.yml [moved from .github/workflows/test.yml with 52% similarity]
.github/workflows/test-win32.yml [new file with mode: 0644]
CHANGELOG.rst
MANIFEST.in
Makefile
README.rst
ntclient/__init__.py
ntclient/persistence/__init__.py
ntclient/persistence/sql/nt/__init__.py
ntclient/persistence/sql/usda/__init__.py
ntclient/services/__init__.py
tests/test_cli.py

diff --git a/.env.bat b/.env.bat
deleted file mode 100644 (file)
index 4db2110..0000000
--- a/.env.bat
+++ /dev/null
@@ -1 +0,0 @@
-set PY_SYS_INTERPRETER=python3
similarity index 52%
rename from .github/workflows/test.yml
rename to .github/workflows/test-linux.yml
index 409138593d2daaa474b605f5882d856b7106de69..98df1bf1ac10fd8520d1b75e50b1a51b81fcbe07 100644 (file)
@@ -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 (file)
index 0000000..264a006
--- /dev/null
@@ -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
index d60c8387e50f120e1ce8105938ae20e92bfd986d..6742be63b0027e78afb4d435e9da532873ac4b46 100644 (file)
@@ -16,6 +16,7 @@ Added
 ~~~~~
 
 - Basic functionality of ``import`` and ``export`` sub-commands
+- Automated CI/CD integration tests for ``Windows`` platform
 
 
 
index 58ecfc5a19405ed27fbb367113011e9cdd28d742..16472c86062e6095066daa0e299b1fad96e7c27e 100644 (file)
@@ -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
index fef247ab670bf083bd990c030660146871b17f3d..5f24690a29836a1df380e343d86c27ceae2a3ee7 100644 (file)
--- 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
index 1c2c8bcedc6122829da73895f824c6cc8f62c577..7e47c3ab4bad87c54739c9e95d981bbd08d98272 100644 (file)
@@ -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
index 9f234f2057b69547749b5d38a7f5cb4479caad8e..20b551fb6fe551788ace0119f2b269de45ec4ef6 100755 (executable)
@@ -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)
index d48acaaea2ba15356f880cb50e49429f155a91c5..5a9795964c942db5be0d2e56689ac33706bf264b 100644 (file)
@@ -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
 
index 5300f1d811b1f8117f9141df9d93d3aa19fa8ee2..5860999ada54702f5aad2e4f2ac278ecdd1d5dcc 100644 (file)
@@ -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
index 4c3df950b32df9915f09877f74a783046cc76025..ba9e6ebfec0e9c1fd1908470074c65f61bd12caa 100644 (file)
@@ -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/
index 4f3450ea66c582e85c417a007cb05dfbbeffcb26..60e0ae725933cb94504c2365d7346fb1c9f73536 100644 (file)
@@ -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
index 555614c124946c2b3ed8486e9ea5a71ad75cdc8e..5450227b630f884118cf5f7539cac1a772fef8b4 100644 (file)
@@ -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