Skip to content

Commit b6c7a73

Browse files
committed
[readme/test] lets add a test script and its info
1 parent fe2f3a1 commit b6c7a73

File tree

4 files changed

+172
-5
lines changed

4 files changed

+172
-5
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ A graphical user interface for configuring GPU related environment variables and
5858
- Options for the program itself
5959
- Create or Delete Profiles, all of them with its own settings, witch you can apply trough the program or systray.
6060

61-
## Build Requirements:
61+
## Build/Test Requirements:
6262

6363
- Python 3.9 or higher
6464
- Pip
@@ -100,7 +100,7 @@ If this software is not provided, its options will be locked.
100100
```
101101
This will:
102102
- Copy the executable to `/usr/local/bin/`
103-
- Copy the helper scripts to `/usr/local/bin/`
103+
- Copy the `volt-helper` script to `/usr/local/bin/`
104104
- Create a desktop entry at `/usr/share/applications/volt-gui.desktop`
105105

106106
### Removal:
@@ -110,10 +110,26 @@ If this software is not provided, its options will be locked.
110110
```
111111
This will:
112112
- Remove the `volt-gui` executable from `/usr/local/bin/`
113-
- Remove the helper scripts from `/usr/local/bin/`
113+
- Remove the `volt-helper` script from `/usr/local/bin/`
114114
- Remove the `volt` bash script from `/usr/local/bin/`
115115
- Remove the desktop entry `/usr/share/applications/volt-gui.desktop`
116116

117+
## Testing volt-gui:
118+
In the case you want to contribute to the project you can use the provided `test.sh` script to test the changes you made. This script will create a Python virtual environment if one does not already exist. This way, you don't have to install the program dependencies systemwide.
119+
120+
The first time you run it, use the -c flag that will also copy the `volt-helper` to `/usr/local/bin/`, as the program requires it for appliying the settings:
121+
```
122+
./test.sh -c
123+
```
124+
125+
After this unless you make changes to the `volt-helper`, or the script have been updated, just run it without the flag to avoid unnecessary overwrites of the script:
126+
```
127+
./test.sh
128+
```
129+
130+
> [!NOTE]
131+
> You can use the `remove.sh` script to remove the `volt-helper`. The `py_env` folder should be deleted in the case you created it with your system python, and you want to use a python version that its inside a `distrobox` box, or vice versa.
132+
117133
## How to use `volt-gui`:
118134

119135
Simply launch volt-gui from your application menu or run `volt-gui` from the terminal.

build-nuitka.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ NUITKA_OPTS=(
2828

2929
# Cleanup function
3030
cleanup() {
31-
rm -rf "$BASE_FILENAME.build/" "$BASE_FILENAME.dist/" "$BASE_FILENAME.onefile-build/" **__pycache__*/ 2>/dev/null || true
31+
rm -rf "$BASE_FILENAME.build/" "$BASE_FILENAME.dist/" "$BASE_FILENAME.onefile-build/" 2>/dev/null || true
3232
}
3333

3434
# Check for required commands

build-pyinstaller.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ PYINSTALLER_OPTS=(
2727

2828
# Cleanup function
2929
cleanup() {
30-
rm -rf dist/ build/ **__pycache__*/ "${SPEC_FILE}" 2>/dev/null || true
30+
rm -rf dist/ build/ "${SPEC_FILE}" 2>/dev/null || true
3131
}
3232

3333
# Check for required commands

test.sh

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/bin/bash
2+
# Exit immediately on errors, unset variables, and pipe failures
3+
set -euo pipefail
4+
5+
# Color definitions
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
CYAN='\033[0;36m'
10+
NC='\033[0m' # No Color
11+
12+
# Configuration
13+
VENV_DIR="py_env"
14+
REQ_FILE="requirements.txt"
15+
REQ_HASH_FILE="$VENV_DIR/requirements.sha256"
16+
SRC_FILE="src/volt-gui.py"
17+
HELPER_SCRIPT="scripts/volt-helper"
18+
INSTALL_DIR="/usr/local/bin"
19+
20+
# Default behavior
21+
COPY_HELPER=false
22+
23+
# Check for required commands
24+
check_commands() {
25+
local commands=("python3" "pip")
26+
for cmd in "${commands[@]}"; do
27+
if ! command -v "$cmd" &> /dev/null; then
28+
echo -e "${RED}Error: Required command '$cmd' not found${NC}" >&2
29+
exit 1
30+
fi
31+
done
32+
}
33+
34+
# Create virtual environment
35+
create_venv() {
36+
if [[ ! -d "$VENV_DIR" ]]; then
37+
echo -e "${CYAN}Creating python3 virtual environment...${NC}"
38+
python3 -m venv "$VENV_DIR"
39+
fi
40+
}
41+
42+
# Verify required files
43+
verify_files() {
44+
if [[ ! -f "$REQ_FILE" ]]; then
45+
echo -e "${RED}Error: Requirements file $REQ_FILE not found${NC}" >&2
46+
exit 1
47+
fi
48+
49+
if [[ ! -f "$SRC_FILE" ]]; then
50+
echo -e "${RED}Error: Source file $SRC_FILE not found${NC}" >&2
51+
exit 1
52+
fi
53+
}
54+
55+
# Update dependencies if needed
56+
update_dependencies() {
57+
local current_hash stored_hash
58+
current_hash=$(shasum -a 256 "$REQ_FILE" | cut -d' ' -f1)
59+
stored_hash=$(cat "$REQ_HASH_FILE" 2>/dev/null || true)
60+
61+
if [[ ! -f "$REQ_HASH_FILE" ]] || [[ "$current_hash" != "$stored_hash" ]]; then
62+
echo -e "${CYAN}Updating dependencies...${NC}"
63+
pip install --upgrade pip
64+
pip install --no-cache-dir -r "$REQ_FILE"
65+
echo "$current_hash" > "$REQ_HASH_FILE"
66+
else
67+
echo -e "${GREEN}Dependencies are up to date${NC}"
68+
fi
69+
}
70+
71+
# Install helper script
72+
install_helper() {
73+
if [[ "$COPY_HELPER" == true ]]; then
74+
if [[ -f "$HELPER_SCRIPT" ]]; then
75+
echo -e "${CYAN}Installing helper script...${NC}"
76+
77+
# Check if we need sudo
78+
if [[ ! -w "$INSTALL_DIR" ]]; then
79+
echo -e "${YELLOW}Installing to $INSTALL_DIR requires sudo privileges${NC}"
80+
sudo cp "$HELPER_SCRIPT" "$INSTALL_DIR/"
81+
sudo chmod +x "$INSTALL_DIR/$(basename "$HELPER_SCRIPT")"
82+
else
83+
cp "$HELPER_SCRIPT" "$INSTALL_DIR/"
84+
chmod +x "$INSTALL_DIR/$(basename "$HELPER_SCRIPT")"
85+
fi
86+
87+
echo -e "${GREEN}Helper script installed to: ${YELLOW}$INSTALL_DIR/$(basename "$HELPER_SCRIPT")${NC}"
88+
else
89+
echo -e "${YELLOW}Warning: Helper script $HELPER_SCRIPT not found, skipping installation${NC}"
90+
fi
91+
fi
92+
}
93+
94+
# Run the application
95+
run_application() {
96+
echo -e "${CYAN}Running application in development mode...${NC}"
97+
echo -e "${YELLOW}Source file: $SRC_FILE${NC}"
98+
echo -e "${YELLOW}Virtual environment: $VENV_DIR${NC}"
99+
echo ""
100+
101+
# Run the Python application
102+
if ! python3 "$SRC_FILE"; then
103+
echo -e "\n${RED}Application exited with error${NC}" >&2
104+
exit 1
105+
fi
106+
}
107+
108+
# Parse command line arguments
109+
parse_args() {
110+
while [[ $# -gt 0 ]]; do
111+
case $1 in
112+
-c)
113+
COPY_HELPER=true
114+
shift
115+
;;
116+
*)
117+
echo -e "${RED}Error: Unknown option '$1'${NC}" >&2
118+
echo -e "${CYAN}Usage: $0 [-c]${NC}" >&2
119+
echo -e " -c Copy volt-helper script to $INSTALL_DIR" >&2
120+
exit 1
121+
;;
122+
esac
123+
done
124+
}
125+
126+
# Main execution
127+
main() {
128+
trap EXIT
129+
130+
# Parse command line arguments
131+
parse_args "$@"
132+
133+
check_commands
134+
verify_files
135+
create_venv
136+
137+
# Activate virtual environment
138+
echo -e "${CYAN}Activating virtual environment...${NC}"
139+
source "$VENV_DIR/bin/activate"
140+
141+
update_dependencies
142+
install_helper
143+
144+
echo -e "\n${GREEN}Setup complete! Starting application...${NC}"
145+
echo -e "${CYAN}────────────────────────────────────────${NC}"
146+
147+
run_application
148+
}
149+
150+
# Run main function with all arguments
151+
main "$@"

0 commit comments

Comments
 (0)