Skip to content

Commit

Permalink
Starting using venv with Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Nov 11, 2024
1 parent 1302399 commit 0ab6b96
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
44 changes: 25 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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; \
Expand All @@ -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
2 changes: 2 additions & 0 deletions buildTools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ black
mypy
pylint
pdoc
pytest
PyInstaller
6 changes: 3 additions & 3 deletions dependencies.hspd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/main/askai/__classpath__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions src/main/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 0ab6b96

Please sign in to comment.