-
Notifications
You must be signed in to change notification settings - Fork 3
/
pymettalog
executable file
·175 lines (149 loc) · 5.39 KB
/
pymettalog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
# Get the absolute path to the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Function to prompt for user confirmation with 'N' as the default
confirm_with_default() {
echo -e -n "$2"
while true; do
if [ "$1" == "N" ]; then
read -s -p " (y/N): " -n 1 yn
else
read -s -p " (${1}/n): " -n 1 yn
fi
if [ -z "$yn" ]; then
yn="$1" # Corrected assignment without spaces
fi
case $yn in
[Yy]* ) echo "Y" && return 0;;
[Nn]* ) echo "N" && return 1;;
* ) echo -e "${YELLOW}Please answer yes or no.${NC}";;
esac
done
}
# Function to prompt for input with a default value
prompt_for_input() {
read -e -i "$2" -p "$1" value
echo -e "${value:-$2}"
}
# ANSI escape codes
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BOLD='\033[1m'
# ANSI escape code to reset color
NC='\033[0m' # No Color
# Define the name of your virtual environment directory
VENV_DIR="${SCRIPT_DIR}/venv"
# Function to install PyTorch and run make
install_and_make() {
echo "Installing PyTorch..."
pip install torch torchvision torchaudio
echo "Running make..."
make
}
# Check if the script is already running inside the intended virtual environment
if [[ "$VIRTUAL_ENV" == "$VENV_DIR" ]]; then
echo "Already running inside the intended virtual environment at ${VIRTUAL_ENV}."
install_and_make
else
if [ -z "$VIRTUAL_ENV" ]; then
echo "Not currently in a virtual environment."
else
echo "Running in a different virtual environment ($VIRTUAL_ENV)"
# lets ask if we can isntall things there by setting $VENV_DIR to $VIRTUAL_ENV or if we should deactivate OR make a subvenv
fi
# Check if the intended virtual environment directory exists
if [ ! -d "$VENV_DIR" ]; then
echo "Creating virtual environment at ${VENV_DIR}..."
python3 -m venv "$VENV_DIR"
fi
echo "Activating the intended virtual environment..."
source "$VENV_DIR/bin/activate"
# Verify the activation
if [[ "$VIRTUAL_ENV" == "$VENV_DIR" ]]; then
echo "Virtual environment activated at ${VIRTUAL_ENV}."
install_and_make
else
echo "Failed to activate the intended virtual environment."
exit 1
fi
fi
swi_prolog_version=$(swipl --version)
if [[ $swi_prolog_version == *"9.1"* ]]; then
echo -e "${GREEN}SWI-Prolog version 9.1 is already installed${NC}."
else
echo "${YELLOW}SWI-Prolog is not version 9.1${NC}."
[ /bin/false ] && (
sudo apt-add-repository -y ppa:swi-prolog/devel
#sudo apt-get remove -y swi-prolog*
sudo apt-get update
sudo apt-get install -y swi-prolog
# sudo apt-get install -y swi-prolog-bdb swi-prolog-odbc swi-prolog-java
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to install SWI-Prolog. Exiting script${NC}."
exit 1
fi
swi_prolog_version=$(swipl --version)
#if [[ $swi_prolog_version == *"9.1"* ]]; then
# echo -e "${GREEN}SWI-Prolog upgraded to 9.1{NC}."
#else
# echo "${YELLOW}SWI-Prolog is still not version 9.1 .. So Janus will probably fail if not already installed${NC}."
#fi
)
fi
function ensure_pip() {
# Check if pip is installed
if ! command -v pip &> /dev/null; then
echo "pip is not installed. Installing pip..."
sudo apt-get update
sudo apt-get install -y python3-pip
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to install pip. Exiting script${NC}."
exit 1
fi
else
echo "pip is already installed."
fi
}
# Assuming SWI-Prolog 9.1 is installed successfully
# Install Janus for SWI-Prolog
echo -e "${BLUE}Checking if Janus Python support is already installed${NC}..."
if ! swipl -g "use_module(library(janus)), halt(0)." -t "halt(1)" 2>/dev/null; then
# janus not installed, prompt the user
if [ "${easy_install}" == "Y" ] || confirm_with_default "Y" "Would you like to install Python (Janus) support"; then
echo "Installing Janus for SWI-Prolog..."
ensure_pip
sudo pip install git+https://github.com/SWI-Prolog/packages-swipy.git
sudo apt install -y libpython3-dev
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to install Janus. Exiting script${NC}."
exit 1
else
echo "Janus installed successfully."
fi
else
echo -e "${YELLOW}Skipping Janus Python support installation${NC}."
fi
else
echo -e "${GREEN}Janus Python support is already installed${NC}."
fi
# Install PySWIP for SWI-Prolog
echo -e "${BLUE}Checking if Pyswip is already installed${NC}..."
if ! python3 -c "import pyswip" &> /dev/null; then
# Pyswip not installed, prompt the user
if [ "${easy_install}" == "Y" ] || confirm_with_default "Y" "Would you like to install Pyswip"; then
echo -e "${BLUE}Installing Pyswip..${NC}."
ensure_pip
sudo pip install git+https://github.com/logicmoo/pyswip.git
echo -e "${GREEN}Pyswip installation complete${NC}."
else
echo -e "${YELLOW}Skipping Pyswip installation${NC}."
fi
else
echo -e "${GREEN}Pyswip is already installed${NC}."
fi
#python3 metta_vspace/metta_learner.py $@
python3 metta_vspace/mettalog.py $@
#python3 metta_vspace/metta_learner_no_panda.py $@
deactivate