]> Nutra Git (v2) - nutratech/cli.git/commitdiff
use makefile syntax, not bash. upgrade deps
authorShane Jaroch <chown_tee@proton.me>
Fri, 12 Apr 2024 19:26:56 +0000 (15:26 -0400)
committerShane Jaroch <chown_tee@proton.me>
Fri, 12 Apr 2024 19:28:38 +0000 (15:28 -0400)
Makefile
requirements-lint.txt

index e5313005be767d33faa1e7b78eda93de502fced6..89aae81d8e92705eeb6cd35c5d536def1d2d58ad 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ SHELL=/bin/bash
 .PHONY: _help
 _help:
        @printf "\nUsage: make <command>, valid commands:\n\n"
-       @grep "##" $(MAKEFILE_LIST) | grep -v IGNORE_ME | sed -e 's/##//' | column -t -s $$'\t'
+       @grep "##" $(MAKEFILE_LIST) | grep -v ^# | grep -v IGNORE_ME | sed -e 's/##//' | column -t -s $$'\t'
 
 
 
@@ -16,11 +16,15 @@ _help:
 
 .PHONY: init
 init:  ## Set up a Python virtual environment
+       # Fetch submodule
        git submodule update --init
+       # Re-add virtual environment
        rm -rf .venv
        ${PY_SYS_INTERPRETER} -m venv .venv
+       # Upgrade dependencies and pip, if NOT running in CI automation
        - if [ -z "${CI}" ]; then ${PY_SYS_INTERPRETER} -m venv --upgrade-deps .venv; fi
        direnv allow
+       @echo "INFO: Successfully initialized venv, run 'make deps' now!"
 
 # include .env
 SKIP_VENV ?=
@@ -29,7 +33,8 @@ PWD ?= $(shell pwd)
 .PHONY: _venv
 _venv:
        # Test to enforce venv usage across important make targets
-       [ "${SKIP_VENV}" ] || [ "${PYTHON}" = "${PWD}/.venv/bin/python" ]
+       test "${SKIP_VENV}" || test "${PYTHON}" = "${PWD}/.venv/bin/python"
+       @echo "OK"
 
 
 
@@ -54,10 +59,12 @@ REQ_LINT := requirements-lint.txt
 REQ_TEST := requirements-test.txt
 REQ_TEST_OLD := requirements-test-old.txt
 
+# TODO: this is a fragile hack (to get it to work in CI and locally too)
 PIP_OPT_ARGS ?= $(shell if [ "$(SKIP_VENV)" ]; then echo "--user"; fi)
 
 .PHONY: deps
 deps: _venv    ## Install requirements
+       # Install requirements
        ${PIP} install wheel
        ${PIP} install ${PIP_OPT_ARGS} -r requirements.txt
        - ${PIP} install ${PIP_OPT_ARGS} -r ${REQ_OPT}
@@ -71,40 +78,61 @@ deps: _venv ## Install requirements
 
 .PHONY: format
 format: _venv  ## Format with isort & black
-       if [ "${CHANGED_FILES_PY_FLAG}" ]; then isort ${CHANGED_FILES_PY} ; fi
-       if [ "${CHANGED_FILES_PY_FLAG}" ]; then black ${CHANGED_FILES_PY} ; fi
+ifneq ($(CHANGED_FILES_PY),)
+       isort ${CHANGED_FILES_PY}
+       black ${CHANGED_FILES_PY}
+else
+       $(info No changed Python files, skipping.)
+endif
 
 
-LINT_LOCS := ntclient/ tests/ setup.py
+LINT_LOCS := ntclient/ tests/ setup.py
 CHANGED_FILES_RST ?= $(shell git diff origin/master --name-only --diff-filter=MACRU \*.rst)
 CHANGED_FILES_PY ?= $(shell git diff origin/master --name-only --diff-filter=MACRU \*.py)
-CHANGED_FILES_PY_FLAG ?= $(shell if [ "$(CHANGED_FILES_PY)" ]; then echo 1; fi)
 
 .PHONY: lint
 lint: _venv    ## Lint code and documentation
+ifneq ($(CHANGED_FILES_RST),)
        # lint RST
-       if [ "${CHANGED_FILES_RST}" ]; then doc8 --quiet ${CHANGED_FILES_RST}; fi
+       doc8 --quiet ${CHANGED_FILES_RST}
+       @echo "OK"
+else
+       $(info No changed RST files, skipping.)
+endif
+ifneq ($(CHANGED_FILES_PY),)
        # check formatting: Python
-       if [ "${CHANGED_FILES_PY_FLAG}" ]; then isort --diff --check ${CHANGED_FILES_PY} ; fi
-       if [ "${CHANGED_FILES_PY_FLAG}" ]; then black --check ${CHANGED_FILES_PY} ; fi
+       isort --diff --check ${CHANGED_FILES_PY}
+       black --check ${CHANGED_FILES_PY}
        # lint Python
-       if [ "${CHANGED_FILES_PY_FLAG}" ]; then pycodestyle --statistics ${CHANGED_FILES_PY}; fi
-       if [ "${CHANGED_FILES_PY_FLAG}" ]; then bandit -q -c .banditrc -r ${CHANGED_FILES_PY}; fi
-       if [ "${CHANGED_FILES_PY_FLAG}" ]; then flake8 ${CHANGED_FILES_PY}; fi
-       if [ "${CHANGED_FILES_PY_FLAG}" ]; then mypy ${CHANGED_FILES_PY}; fi
-       if [ "${CHANGED_FILES_PY_FLAG}" ]; then pylint ${CHANGED_FILES_PY}; fi
+       pycodestyle --statistics ${CHANGED_FILES_PY}
+       bandit -q -c .banditrc -r ${CHANGED_FILES_PY}
+       flake8 ${CHANGED_FILES_PY}
+       mypy ${CHANGED_FILES_PY}
+       pylint ${CHANGED_FILES_PY}
+       @echo "OK"
+else
+       $(info No changed Python files, skipping.)
+endif
 
 .PHONY: pylint
 pylint:
-       if [ "${CHANGED_FILES_PY_FLAG}" ]; then pylint ${CHANGED_FILES_PY}; fi
+ifneq ($(CHANGED_FILES_PY),)
+       pylint ${CHANGED_FILES_PY}
+else
+       $(info No changed Python files, skipping.)
+endif
 
 .PHONY: mypy
 mypy:
-       if [ "${CHANGED_FILES_PY_FLAG}" ]; then mypy ${CHANGED_FILES_PY}; fi
+ifneq ($(CHANGED_FILES_PY),)
+       mypy ${CHANGED_FILES_PY}
+else
+       $(info No changed Python files, skipping.)
+endif
 
 
 .PHONY: test
-test: _venv    ## Run CLI unittests
+test: _venv    ## Run CLI unit tests
        coverage run
        coverage report
        - grep fail_under setup.cfg
@@ -156,7 +184,8 @@ RECURSIVE_CLEAN_LOCS ?= $(shell find ntclient/ tests/ \
 -name __pycache__ \
 -o -name .coverage \
 -o -name .mypy_cache \
--o -name .pytest_cache)
+-o -name .pytest_cache \
+)
 
 .PHONY: clean
 clean: ## Clean up __pycache__ and leftover bits
@@ -164,8 +193,10 @@ clean:     ## Clean up __pycache__ and leftover bits
        rm -rf build/
        rm -rf nutra.egg-info/
        rm -rf .pytest_cache/ .mypy_cache/
+ifneq ($(RECURSIVE_CLEAN_LOCS),)
        # Recursively find & remove
-       if [ "${RECURSIVE_CLEAN_LOCS}" ]; then rm -rf ${RECURSIVE_CLEAN_LOCS}; fi
+       rm -rf ${RECURSIVE_CLEAN_LOCS}
+endif
 
 
 
@@ -175,4 +206,4 @@ clean:      ## Clean up __pycache__ and leftover bits
 
 .PHONY: extras/cloc
 extras/cloc:   ## Count lines of source code
-       - cloc HEAD
+       - cloc HEAD ntclient/ntsqlite
index 23d3c6284f9c1736efb86e73ffd5de1bfeddaa21..4d03f88f2a5c4d44f060e97158b856d27a2873fc 100644 (file)
@@ -6,6 +6,6 @@ mypy==1.9.0
 pylint==3.1.0
 types-colorama==0.4.15.20240311
 types-psycopg2==2.9.21.20240311
-types-requests==2.31.0.20240311
+types-requests==2.31.0.20240406
 types-setuptools==69.2.0.20240317
 types-tabulate==0.9.0.20240106