From 0ab6b96867caf6eed4a948086f8398836ea03b26 Mon Sep 17 00:00:00 2001 From: Hugo Saporetti Junior Date: Mon, 11 Nov 2024 19:57:22 -0300 Subject: [PATCH] Starting using venv with Makefile --- Makefile | 44 +++++++++++++++++++-------------- buildTools.txt | 2 ++ dependencies.hspd | 6 ++--- gradle.properties | 2 +- src/main/askai/__classpath__.py | 2 +- src/main/requirements.txt | 6 ++--- 6 files changed, 35 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 9ba86684..0aefe133 100755 --- a/Makefile +++ b/Makefile @@ -1,14 +1,15 @@ # Makefile for AskAI project -VENV_PATH=venv -PYTHON=$(VENV_PATH)/bin/python -SRC_DIR=src/main/askai/ -BUILD_DIR=build/ -DIST_DIR=dist/ -APP=$(SRC_DIR)/__main__.py -EXECUTABLE_NAME=askai -PREFIX?=/opt/homebrew/bin -INSTALL_PATH="$(PREFIX)/$(EXECUTABLE_NAME)" +VENV_PATH="venv" +PYTHON="$(VENV_PATH)/bin/python" +SRC_DIR="src/main" +BUILD_DIR="build" +DIST_DIR="dist" +MAIN_FILE="$(SRC_DIR)/askai/__main__.py" +REQS_FILE="$(SRC_DIR)/requirements.txt" +PREFIX?="/opt/homebrew/bin" +INSTALL_PATH="$(PREFIX)/$(BIN_NAME)" +BIN_NAME="taius" .PHONY: create_venv requirements install_packages activate clean dist run require_sudo install @@ -30,12 +31,17 @@ create_venv: # Target to generate the requirements file requirements: create_venv $(PYTHON) -m pip install --upgrade pip - $(PYTHON) -m pip freeze > requirements.txt + @if ! [ -f "$(REQS_FILE)" ]; then \ + echo "Requirements file not found: '$(REQS_FILE)'. Generating..."; \ + $(PYTHON) -m pip freeze > "$(REQS_FILE)"; \ + else \ + echo "Using the existing requirements file: '$(REQS_FILE)'. "; \ + fi # Target to install packages into venv install_packages: activate requirements - echo "Installing $(EXECUTABLE_NAME) into $(INSTALL_PATH)" - $(PYTHON) -m pip install -r requirements.txt + echo "Installing $(BIN_NAME) into $(INSTALL_PATH)" + $(PYTHON) -m pip install -r "$(REQS_FILE)" # Target to activate the virtual environment activate: @@ -48,11 +54,11 @@ clean: # Create a distribution dist: clean install_packages - pyinstaller --onefile --name enrager --paths "$(SRC_DIR)" "$(APP)" + pyinstaller --onefile --name "$(BIN_NAME)" --paths "$(SRC_DIR)" "$(MAIN_FILE)" # Target to run the app run: - PYTHONPATH="$(SRC_DIR)" $(PYTHON) "$(APP)" $(ARGS) + PYTHONPATH="$(SRC_DIR)" $(PYTHON) "$(MAIN_FILE)" $(ARGS) # Target to require sudo before executing other targets require_sudo: @@ -63,9 +69,9 @@ require_sudo: # Target to install the executable, depends on the 'dist' target install: dist - @if [ -f $(DIST_DIR)/$(EXECUTABLE_NAME) ]; then \ - \cp $(DIST_DIR)/$(EXECUTABLE_NAME) $(INSTALL_PATH); \ - echo "Installed $(EXECUTABLE_NAME) to $(INSTALL_PATH)"; \ + @if [ -f $(DIST_DIR)/$(BIN_NAME) ]; then \ + \cp $(DIST_DIR)/$(BIN_NAME) $(INSTALL_PATH); \ + echo "Installed $(BIN_NAME) into $(INSTALL_PATH)"; \ else \ echo "Executable not found in $(DIST_DIR). Ensure 'dist' target builds the executable correctly."; \ exit 1; \ @@ -75,7 +81,7 @@ install: dist uninstall: @if [ -f $(INSTALL_PATH) ]; then \ \rm -f $(INSTALL_PATH); \ - echo "Uninstalled $(EXECUTABLE_NAME) from $(INSTALL_PATH)"; \ + echo "Uninstalled $(BIN_NAME) from $(INSTALL_PATH)"; \ else \ - echo "$(EXECUTABLE_NAME) is not installed."; \ + echo "$(BIN_NAME) is not installed."; \ fi diff --git a/buildTools.txt b/buildTools.txt index 2e94cdab..8869f990 100644 --- a/buildTools.txt +++ b/buildTools.txt @@ -11,3 +11,5 @@ black mypy pylint pdoc +pytest +PyInstaller diff --git a/dependencies.hspd b/dependencies.hspd index d0797e7d..ea22eeae 100644 --- a/dependencies.hspd +++ b/dependencies.hspd @@ -8,9 +8,9 @@ */ /* HSPyLib projects */ -package: hspylib, version: 1.12.51, mode: ge -package: hspylib-clitt, version: 0.9.139, mode: ge -package: hspylib-setman, version: 0.10.42, mode: ge +package: hspylib, version: 1.12.53, mode: ge +package: hspylib-clitt, version: 0.9.140, mode: ge +package: hspylib-setman, version: 0.10.43, mode: ge /* General */ package: retry2, version: 0.9.5, mode: eq diff --git a/gradle.properties b/gradle.properties index ebca80b8..5ce55689 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,4 +5,4 @@ app_name = hspylib-askai app_version = 1.2.1 # Build Tools -buildTools = setuptools, wheel, build, twine, bumpver, pipenv, isort, black, mypy, pylint, pdoc, pytest +buildTools = setuptools, wheel, build, twine, bumpver, pipenv, isort, black, mypy, pylint, pdoc, pytest, PyInstaller diff --git a/src/main/askai/__classpath__.py b/src/main/askai/__classpath__.py index ed8b960a..9184dd34 100644 --- a/src/main/askai/__classpath__.py +++ b/src/main/askai/__classpath__.py @@ -40,7 +40,7 @@ except pydantic.v1.error_wrappers.ValidationError as err: if not ApiKeys.prompt(): log.error(err.json()) - sys.exit(ExitStatus.ABNORMAL) + sys.exit(ExitStatus.ABNORMAL.val) class _Classpath(Classpath): diff --git a/src/main/requirements.txt b/src/main/requirements.txt index 4c73156d..f1186dbf 100644 --- a/src/main/requirements.txt +++ b/src/main/requirements.txt @@ -1,8 +1,8 @@ ###### AUTO-GENERATED Requirements file for: AskAI ###### -hspylib>=1.12.51 -hspylib-clitt>=0.9.139 -hspylib-setman>=0.10.42 +hspylib>=1.12.53 +hspylib-clitt>=0.9.140 +hspylib-setman>=0.10.43 retry2==0.9.5 pause==0.3 tqdm==4.66.5