Skip to content

Commit c50fa1d

Browse files
committed
Updates
1 parent c6b54f0 commit c50fa1d

File tree

1 file changed

+46
-27
lines changed

1 file changed

+46
-27
lines changed

_posts/2024-10-26-dynamic-dependency-management.md

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ motion:
5454
- RPi.GPIO
5555
unix:
5656
- wiringpi
57+
additional:
58+
- "https://www.example.com/motion_install.md"
5759
```
5860

5961
### Modified `install.sh` Script
@@ -62,6 +64,7 @@ The install script below:
6264
1. Parses `python` and `unix` dependencies from each module's YAML file.
6365
2. Installs Unix dependencies with `apt-get install` and Python dependencies with `pip install`.
6466
3. Uses a **Python helper** embedded within the script to read YAML files (using `pyyaml`).
67+
4. Outputs a summary of installed modules and dependencies. This includes any additional URLs for manual configuration.
6568

6669
Here’s the modified `install.sh` script:
6770

@@ -72,9 +75,10 @@ Here’s the modified `install.sh` script:
7275
python3 -m venv --system-site-packages myenv
7376
source myenv/bin/activate
7477
75-
# Initialize arrays for dependencies and active module names
78+
# Initialize arrays for dependencies and additional setup URLs
7679
PYTHON_DEPENDENCIES=()
7780
UNIX_DEPENDENCIES=()
81+
ADDITIONAL_URLS=()
7882
ACTIVE_MODULES=()
7983
8084
# Helper function to parse dependencies from YAML files using Python
@@ -87,20 +91,21 @@ module_name = os.path.basename(config_file).replace('.yml', '') # Get the modul
8791
try:
8892
with open(config_file) as f:
8993
config = yaml.safe_load(f)
90-
# Check if the top level of the config is a dictionary to avoid AttributeError
9194
if isinstance(config, dict):
9295
for section in config.values():
93-
# Check if module is active before parsing dependencies
94-
if isinstance(section, dict) and section.get('enabled') is True:
96+
# Ensure each section has 'enabled' set to true and 'dependencies' exists
97+
if isinstance(section, dict) and section.get('enabled', False) and 'dependencies' in section:
9598
print(f"MODULE:{module_name}")
96-
if 'dependencies' in section:
97-
for dep_type, deps in section['dependencies'].items():
98-
if dep_type == 'python':
99-
for dep in deps:
100-
print(f"PYTHON:{dep}")
101-
elif dep_type == 'unix':
102-
for dep in deps:
103-
print(f"UNIX:{dep}")
99+
for dep_type, deps in section['dependencies'].items():
100+
if dep_type == 'python':
101+
for dep in deps:
102+
print(f"PYTHON:{dep}")
103+
elif dep_type == 'unix':
104+
for dep in deps:
105+
print(f"UNIX:{dep}")
106+
elif dep_type == 'additional':
107+
for url in deps:
108+
print(f"ADDITIONAL:{module_name}:{url}")
104109
except yaml.YAMLError as e:
105110
print(f"Error reading {config_file}: {e}", file=sys.stderr)
106111
EOF
@@ -116,6 +121,8 @@ for config_file in config/*.yml; do
116121
PYTHON_DEPENDENCIES+=("${dependency#PYTHON:}")
117122
elif [[ $dependency == UNIX:* ]]; then
118123
UNIX_DEPENDENCIES+=("${dependency#UNIX:}")
124+
elif [[ $dependency == ADDITIONAL:* ]]; then
125+
ADDITIONAL_URLS+=("${dependency#ADDITIONAL:}")
119126
fi
120127
done < <(parse_dependencies "$config_file")
121128
done
@@ -124,19 +131,20 @@ done
124131
UNIQUE_PYTHON_DEPENDENCIES=($(echo "${PYTHON_DEPENDENCIES[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
125132
UNIQUE_UNIX_DEPENDENCIES=($(echo "${UNIX_DEPENDENCIES[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
126133
UNIQUE_ACTIVE_MODULES=($(echo "${ACTIVE_MODULES[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
134+
UNIQUE_ADDITIONAL_URLS=($(echo "${ADDITIONAL_URLS[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
127135
128-
# Update apt-get and install Unix dependencies
129-
if [ ${#UNIQUE_UNIX_DEPENDENCIES[@]} -ne 0 ]; then
130-
sudo apt-get update
131-
for dep in "${UNIQUE_UNIX_DEPENDENCIES[@]}"; do
132-
sudo apt-get install -y "$dep"
133-
done
134-
fi
136+
# # Update apt-get and install Unix dependencies
137+
# if [ ${#UNIQUE_UNIX_DEPENDENCIES[@]} -ne 0 ]; then
138+
# sudo apt-get update
139+
# for dep in "${UNIQUE_UNIX_DEPENDENCIES[@]}"; do
140+
# sudo apt-get install -y "$dep"
141+
# done
142+
# fi
135143
136-
# Install Python dependencies explicitly using the virtual environment's pip
137-
for dep in "${UNIQUE_PYTHON_DEPENDENCIES[@]}"; do
138-
myenv/bin/python3 -m pip install "$dep"
139-
done
144+
# # Install Python dependencies explicitly using the virtual environment's pip
145+
# for dep in "${UNIQUE_PYTHON_DEPENDENCIES[@]}"; do
146+
# myenv/bin/python3 -m pip install "$dep"
147+
# done
140148
141149
# Set execute permissions for additional scripts
142150
chmod 777 startup.sh stop.sh
@@ -157,8 +165,14 @@ echo -e "\nUnix dependencies installed:"
157165
for dep in "${UNIQUE_UNIX_DEPENDENCIES[@]}"; do
158166
echo " - $dep"
159167
done
160-
echo "============================="
161168
169+
if [ ${#UNIQUE_ADDITIONAL_URLS[@]} -ne 0 ]; then
170+
echo -e "\nACTION REQUIRED: Additional manual configuration required for the following modules:"
171+
for dep in "${UNIQUE_ADDITIONAL_URLS[@]}"; do
172+
echo " - $dep"
173+
done
174+
fi
175+
echo "============================="
162176
```
163177

164178
### Explanation of Changes
@@ -194,7 +208,7 @@ Remember, only **active modules** will have their dependencies installed.
194208

195209
```plaintext
196210
==== Installation Summary ====
197-
Active modules installed: 12
211+
Active modules installed: 13
198212
- animate
199213
- braillespeak
200214
- buzzer
@@ -206,21 +220,26 @@ Active modules installed: 12
206220
- servos
207221
- tracking
208222
- translator
223+
- universalremote
209224
- vision
210225
211226
Python dependencies installed:
212227
- adafruit-circuitpython-seesaw
213228
- googletrans==3.1.0a0
214229
- gpiozero
230+
- lirc
215231
- pigpio
232+
- pubsub
216233
- pypubsub
217234
- python3-munkres
218235
- python3-opencv
219236
220237
Unix dependencies installed:
221238
- imx500-all
222-
=============================
223-
```
239+
- lirc
240+
241+
ACTION REQUIRED: Additional manual configuration required for the following modules:
242+
- motion:https://www.example.com/motion_install.md
224243
225244
## Read More
226245

0 commit comments

Comments
 (0)