Unverified Commit 96828064 authored by Timothy Jaeryang Baek's avatar Timothy Jaeryang Baek Committed by GitHub
Browse files

Merge pull request #4372 from JTHesse/main

build: Adding ability to install requirements from frontmatter for tools and functions
parents fc6fa788 367fa039
from importlib import util from importlib import util
import os import os
import re import re
import sys
import subprocess
from config import TOOLS_DIR, FUNCTIONS_DIR from config import TOOLS_DIR, FUNCTIONS_DIR
...@@ -52,6 +54,7 @@ def load_toolkit_module_by_id(toolkit_id): ...@@ -52,6 +54,7 @@ def load_toolkit_module_by_id(toolkit_id):
frontmatter = extract_frontmatter(toolkit_path) frontmatter = extract_frontmatter(toolkit_path)
try: try:
install_frontmatter_requirements(frontmatter.get("requirements", ""))
spec.loader.exec_module(module) spec.loader.exec_module(module)
print(f"Loaded module: {module.__name__}") print(f"Loaded module: {module.__name__}")
if hasattr(module, "Tools"): if hasattr(module, "Tools"):
...@@ -73,6 +76,7 @@ def load_function_module_by_id(function_id): ...@@ -73,6 +76,7 @@ def load_function_module_by_id(function_id):
frontmatter = extract_frontmatter(function_path) frontmatter = extract_frontmatter(function_path)
try: try:
install_frontmatter_requirements(frontmatter.get("requirements", ""))
spec.loader.exec_module(module) spec.loader.exec_module(module)
print(f"Loaded module: {module.__name__}") print(f"Loaded module: {module.__name__}")
if hasattr(module, "Pipe"): if hasattr(module, "Pipe"):
...@@ -88,3 +92,12 @@ def load_function_module_by_id(function_id): ...@@ -88,3 +92,12 @@ def load_function_module_by_id(function_id):
# Move the file to the error folder # Move the file to the error folder
os.rename(function_path, f"{function_path}.error") os.rename(function_path, f"{function_path}.error")
raise e raise e
def install_frontmatter_requirements(requirements):
if requirements:
req_list = [req.strip() for req in requirements.split(',')]
for req in req_list:
print(f"Installing requirement: {req}")
subprocess.check_call([sys.executable, "-m", "pip", "install", req])
else:
print("No requirements found in frontmatter.")
\ No newline at end of file
...@@ -30,7 +30,6 @@ if [[ "${USE_CUDA_DOCKER,,}" == "true" ]]; then ...@@ -30,7 +30,6 @@ if [[ "${USE_CUDA_DOCKER,,}" == "true" ]]; then
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib/python3.11/site-packages/torch/lib:/usr/local/lib/python3.11/site-packages/nvidia/cudnn/lib" export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib/python3.11/site-packages/torch/lib:/usr/local/lib/python3.11/site-packages/nvidia/cudnn/lib"
fi fi
# Check if SPACE_ID is set, if so, configure for space # Check if SPACE_ID is set, if so, configure for space
if [ -n "$SPACE_ID" ]; then if [ -n "$SPACE_ID" ]; then
echo "Configuring for HuggingFace Space deployment" echo "Configuring for HuggingFace Space deployment"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment