Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ coverage.html
.env.production
.direnv

# Python virtual environments
venv/
.venv/
testsuite/venv/
testsuite/.venv/

# macOS-specific files
.DS_Store
108 changes: 103 additions & 5 deletions dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fi
RUN_TESTSUITE=false
SKIP_TESTS=false
VERBOSE=false
USE_GLOBAL_ENV=false

# Function to print colored output
print_step() {
Expand All @@ -41,6 +42,75 @@ print_error() {
printf "${RED}✗${NC} %s\n" "$1"
}

# Function to setup Python virtual environment
setup_venv() {
local venv_path="$1"

# Remove existing incomplete virtual environment if activate script is missing or pip is broken
if [ -d "$venv_path" ]; then
if [ ! -f "$venv_path/bin/activate" ]; then
print_warning "Removing incomplete virtual environment (missing activate)..."
rm -rf "$venv_path"
else
# Test if pip works in the existing virtual environment
if ! (source "$venv_path/bin/activate" && python -m pip --version > /dev/null 2>&1); then
print_warning "Removing broken virtual environment (pip not working)..."
rm -rf "$venv_path"
fi
fi
fi

if [ ! -d "$venv_path" ]; then
print_step "Creating Python virtual environment..."
if python3 -m venv "$venv_path" --upgrade-deps; then
print_success "Virtual environment created at $venv_path"
else
print_error "Failed to create virtual environment"
return 1
fi
else
print_step "Using existing virtual environment at $venv_path"
fi

# Check if activate script exists and has proper permissions
if [ ! -f "$venv_path/bin/activate" ]; then
print_error "Virtual environment activate script not found at $venv_path/bin/activate"
return 1
fi

# Ensure activate script has execution permissions
chmod +x "$venv_path/bin/activate"

# Activate virtual environment
source "$venv_path/bin/activate"

# Verify that we're in the virtual environment
if [ -z "$VIRTUAL_ENV" ]; then
print_error "Failed to activate virtual environment"
return 1
fi

# Upgrade pip to latest version
print_step "Upgrading pip in virtual environment..."
if python -m pip install --upgrade pip > /dev/null 2>&1; then
print_success "Pip upgraded successfully"
else
print_warning "Failed to upgrade pip - continuing anyway"
fi

return 0
}

# Function to cleanup virtual environment
cleanup_venv() {
if [ -n "$VIRTUAL_ENV" ]; then
deactivate 2>/dev/null || true
fi
}

# Setup trap for cleanup on exit/interruption
trap cleanup_venv EXIT INT TERM

# Function to show usage
usage() {
echo "Usage: $0 [OPTIONS]"
Expand All @@ -51,6 +121,7 @@ usage() {
echo " -t, --testsuite Run integration testsuite after unit tests"
echo " -s, --skip-tests Skip unit tests (only format, lint, and build)"
echo " -v, --verbose Enable verbose output"
echo " --use-global-env Use global Python environment instead of virtual environment"
echo " -h, --help Show this help message"
echo ""
echo "STEPS PERFORMED:"
Expand All @@ -77,6 +148,10 @@ while [[ $# -gt 0 ]]; do
VERBOSE=true
shift
;;
--use-global-env)
USE_GLOBAL_ENV=true
shift
;;
-h|--help)
usage
exit 0
Expand Down Expand Up @@ -165,12 +240,35 @@ if [ "$RUN_TESTSUITE" = true ]; then

cd testsuite

# Install requirements if needed (you might want to do this manually)
print_step "Installing testsuite requirements..."
if pip3 install -r requirements.txt > /dev/null 2>&1; then
print_success "Testsuite requirements installed"
# Use virtual environment by default, global environment if requested
if [ "$USE_GLOBAL_ENV" = true ]; then
# Install requirements globally
print_step "Installing testsuite requirements globally..."
print_warning "Using global Python environment - consider removing --use-global-env flag to use virtual environment"
if python3 -m pip install -r requirements.txt > /dev/null 2>&1; then
print_success "Testsuite requirements installed globally"
else
print_warning "Failed to install testsuite requirements - continuing anyway"
fi
else
print_warning "Failed to install testsuite requirements - continuing anyway"
# Setup virtual environment (default behavior)
VENV_PATH="./venv"

if ! setup_venv "$VENV_PATH"; then
print_error "Failed to setup virtual environment"
cd ..
exit 1
fi

# Install requirements in virtual environment
print_step "Installing testsuite requirements in virtual environment..."
if python -m pip install -r requirements.txt > /dev/null 2>&1; then
print_success "Testsuite requirements installed in virtual environment"
else
print_error "Failed to install testsuite requirements in virtual environment"
cd ..
exit 1
fi
fi

# Run the testsuite
Expand Down
19 changes: 19 additions & 0 deletions testsuite/core/tmux_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ class TmuxSPFManager(BaseSPFManager):
# Init should not allocate any resources
def __init__(self, spf_path : str):
super().__init__(spf_path)

# Check libtmux version requirement
min_version = (0, 31, 0)
current_version_str = libtmux.__version__

# Parse version string to tuple for comparison
try:
current_version = tuple(map(int, current_version_str.split('.')[:3]))
except (ValueError, AttributeError):
current_version = (0, 0, 0)

if current_version < min_version:
raise RuntimeError(
f"libtmux version 0.31.0 or higher is required. "
f"Current version: {current_version_str}. "
f"Please upgrade with: pip install 'libtmux>=0.31.0'"
)

self.logger = logging.getLogger()
self.server = libtmux.Server(socket_name=TmuxSPFManager.SPF_SOCKET_NAME)
self.logger.debug("server object : %s", self.server)
Expand All @@ -38,6 +56,7 @@ def start_spf(self, start_dir : str = None, args : list[str] = None) -> None:
time.sleep(TmuxSPFManager.SPF_START_DELAY)
self.logger.debug("spf_session initialised : %s", self.spf_session)

# If libtmux version is less than 0.3.1, active_pane does not exist.
self.spf_pane = self.spf_session.active_pane
self._is_spf_running = True

Expand Down
Loading