Skip to content

Commit

Permalink
Add Makefile for using homebrew
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Nov 8, 2024
1 parent 9a26350 commit bb91bf6
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ py-gradle-master/
build/
.vscode/
.venv/
venv
Expand Down
81 changes: 81 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 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)"

.PHONY: create_venv requirements install_packages activate clean dist run require_sudo install

# Create virtual environment
create_venv:
@if ! [ -x "$$(command -v python3)" ]; then \
echo "Python 3 is not installed. Please install it."; \
exit 1; \
else \
echo "Using $$(python3 -V)."; \
fi
@if [ ! -d $(VENV_PATH) ]; then \
python3 -m venv $(VENV_PATH); \
echo "Virtual environment created in $(VENV_PATH)."; \
else \
echo "Virtual environment already exists."; \
fi

# Target to generate the requirements file
requirements: create_venv
$(PYTHON) -m pip install --upgrade pip
$(PYTHON) -m pip freeze > requirements.txt

# Target to install packages into venv
install_packages: activate requirements
echo "Installing $(EXECUTABLE_NAME) into $(INSTALL_PATH)"
$(PYTHON) -m pip install -r requirements.txt

# Target to activate the virtual environment
activate:
. $(VENV_PATH)/bin/activate

# Cleanup build
clean:
@if [ -d $(BUILD_DIR) ]; then \rm -rf $(BUILD_DIR); fi
@if [ -d $(DIST_DIR) ]; then \rm -rf $(DIST_DIR); fi

# Create a distribution
dist: clean install_packages
pyinstaller --onefile --name enrager --paths "$(SRC_DIR)" "$(APP)"

# Target to run the app
run:
PYTHONPATH="$(SRC_DIR)" $(PYTHON) "$(APP)" $(ARGS)

# Target to require sudo before executing other targets
require_sudo:
@if [ "$$(id -u)" -ne 0 ]; then \
echo "This target must be run as root. Please use sudo."; \
exit 1; \
fi

# 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)"; \
else \
echo "Executable not found in $(DIST_DIR). Ensure 'dist' target builds the executable correctly."; \
exit 1; \
fi

# Target to uninstall the executable
uninstall:
@if [ -f $(INSTALL_PATH) ]; then \
\rm -f $(INSTALL_PATH); \
echo "Uninstalled $(EXECUTABLE_NAME) from $(INSTALL_PATH)"; \
else \
echo "$(EXECUTABLE_NAME) is not installed."; \
fi

0 comments on commit bb91bf6

Please sign in to comment.