Skip to content

Commit 19e54ba

Browse files
authored
Merge pull request #49 from stackql/feature/refactor
refactor
2 parents 189cf56 + a069c53 commit 19e54ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4177
-1797
lines changed

.github/workflows/test.yaml

Lines changed: 80 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,94 +13,115 @@ jobs:
1313
- windows-latest
1414
- macos-latest
1515
python-version:
16-
- "3.8"
1716
- "3.9"
1817
- "3.10"
1918
- "3.11"
2019
- "3.12"
2120
- "3.13"
22-
exclude:
23-
- os: macos-latest
24-
python-version: "3.8"
25-
- os: macos-latest
26-
python-version: "3.13"
2721
runs-on: ${{matrix.os}}
28-
name: 'Run Tests on ${{matrix.os}} with Python ${{matrix.python-version}}'
22+
name: '${{matrix.os}} Python ${{matrix.python-version}}'
2923

3024
steps:
31-
- uses: actions/[email protected]
25+
- name: Checkout
26+
uses: actions/[email protected]
3227

3328
- name: Set up Python ${{ matrix.python-version }}
34-
uses: actions/setup-python@v5.1.0
29+
uses: actions/setup-python@v5.6.0
3530
with:
3631
python-version: ${{ matrix.python-version }}
3732

38-
- name: Install dependencies from requirements.txt
33+
- name: Upgrade pip
3934
shell: bash
4035
run: |
4136
python3 -m pip install --upgrade pip
42-
pip install -r requirements.txt
4337
44-
# Windows
45-
- name: Install psycopg
46-
if: matrix.os == 'windows-latest'
38+
- name: Install pystackql with all dependencies
39+
run: |
40+
pip install -e .
41+
42+
- name: Install test dependencies
4743
run: |
48-
pip install psycopg[binary]
49-
shell: powershell
50-
# End Windows
44+
pip install pytest>=6.2.5 pytest-cov>=2.12.0 nose>=1.3.7
5145
52-
# Linux
53-
- name: Install PostgreSQL dev libraries on Ubuntu
54-
if: matrix.os == 'ubuntu-latest'
46+
- name: setup-stackql
47+
uses: stackql/[email protected]
48+
with:
49+
use_wrapper: true
50+
51+
- name: Show stackql version (Linux/macOS)
52+
if: matrix.os != 'windows-latest'
53+
shell: bash
5554
run: |
56-
sudo apt-get update
57-
pip install psycopg
58-
# End Linux
55+
stackql --version
5956
60-
# macOS
61-
- name: Install PostgreSQL dev libraries on macOS
62-
if: matrix.os == 'macos-latest'
57+
- name: Show stackql version (Windows)
58+
if: matrix.os == 'windows-latest'
59+
shell: cmd
6360
run: |
64-
brew install postgresql@14
65-
pip install psycopg
66-
# End macOS
61+
stackql-bin.exe --version
6762
68-
- name: Install pystackql
63+
- name: Move stackql binary to temp dir (Linux/macOS)
64+
if: matrix.os != 'windows-latest'
65+
shell: bash
66+
run: |
67+
STACKQL_PATH=$(which stackql)
68+
mkdir -p /tmp || true
69+
cp "$STACKQL_PATH" /tmp/stackql
70+
echo "StackQL binary moved from ${STACKQL_PATH} to /tmp/stackql"
71+
72+
- name: Move stackql binary to temp dir (Windows)
73+
if: matrix.os == 'windows-latest'
74+
shell: pwsh
6975
run: |
70-
pip install .
76+
$bin = Join-Path $Env:STACKQL_CLI_PATH 'stackql-bin.exe'
77+
if (-Not (Test-Path $bin)) {
78+
throw "Binary not found at $bin"
79+
}
80+
Copy-Item $bin -Destination "C:\Temp\stackql.exe" -Force
81+
Write-Host "Moved real StackQL binary to C:\Temp\stackql.exe"
7182
72-
- name: Run tests
83+
- name: Run non-server tests
7384
env:
74-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
75-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
76-
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
77-
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
78-
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}
79-
CUSTOM_STACKQL_GITHUB_USERNAME: ${{ secrets.CUSTOM_STACKQL_GITHUB_USERNAME }}
80-
CUSTOM_STACKQL_GITHUB_PASSWORD: ${{ secrets.CUSTOM_STACKQL_GITHUB_PASSWORD }}
81-
AWS_REGION: ${{ vars.AWS_REGION }}
82-
AWS_REGIONS: ${{ vars.AWS_REGIONS }}
83-
GCP_PROJECT: ${{ vars.GCP_PROJECT }}
84-
GCP_ZONE: ${{ vars.GCP_ZONE }}
85+
GITHUB_ACTIONS: 'true'
8586
run: |
86-
python3 -m tests.pystackql_tests
87-
shell: bash
88-
if: matrix.os != 'windows-latest'
87+
python3 run_tests.py
8988
90-
- name: Run tests on Windows
89+
- name: Start StackQL server and run tests (Linux/macOS)
90+
if: matrix.os != 'windows-latest'
91+
shell: bash
9192
env:
92-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
93-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
94-
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
95-
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
96-
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}
97-
CUSTOM_STACKQL_GITHUB_USERNAME: ${{ secrets.CUSTOM_STACKQL_GITHUB_USERNAME }}
98-
CUSTOM_STACKQL_GITHUB_PASSWORD: ${{ secrets.CUSTOM_STACKQL_GITHUB_PASSWORD }}
99-
AWS_REGION: ${{ vars.AWS_REGION }}
100-
AWS_REGIONS: ${{ vars.AWS_REGIONS }}
101-
GCP_PROJECT: ${{ vars.GCP_PROJECT }}
102-
GCP_ZONE: ${{ vars.GCP_ZONE }}
93+
GITHUB_ACTIONS: 'true'
10394
run: |
104-
python3 -m tests.pystackql_tests
95+
nohup /tmp/stackql -v --pgsrv.port=5466 srv &
96+
sleep 5
97+
python3 run_server_tests.py
98+
99+
- name: Start StackQL server (Windows)
100+
if: matrix.os == 'windows-latest'
105101
shell: pwsh
102+
run: |
103+
Start-Process -FilePath "C:\Temp\stackql.exe" `
104+
-ArgumentList "-v", "--pgsrv.port=5466", "srv"
105+
Start-Sleep -Seconds 5
106+
107+
- name: Stop StackQL server (Linux/macOS)
108+
if: matrix.os != 'windows-latest'
109+
shell: bash
110+
run: |
111+
echo "Stopping StackQL server on Unix/macOS..."
112+
PID=$(pgrep -f "/tmp/stackql.*srv" || pgrep -f "stackql.*srv" || echo "")
113+
if [ -z "$PID" ]; then
114+
echo "No stackql server process found."
115+
else
116+
echo "stopping stackql server (PID: $PID)..."
117+
kill -9 $PID
118+
echo "stackql server stopped."
119+
fi
120+
121+
- name: Stop StackQL server (Windows)
106122
if: matrix.os == 'windows-latest'
123+
shell: cmd
124+
run: |
125+
echo "Stopping StackQL server on Windows..."
126+
taskkill /F /IM stackql.exe 2>nul || echo "No stackql.exe process found"
127+
echo "StackQL server stopped (Windows)"

.gitignore

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
# Miscellaneous
2-
/.stackql
3-
/.stackql/*
42
.pypirc
5-
63
/.vscode
74
/.vscode/*
85

6+
# Virtual environments
7+
.venv/
8+
venv/
9+
env/
10+
ENV/
11+
12+
# stackql
13+
.stackql/
14+
stackql
15+
stackql-*.sh
16+
.env
17+
nohup.out
18+
919
# Byte-compiled / optimized / DLL files
1020
__pycache__
1121
*.py[cod]

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v3.8.0 (2025-06-04)
4+
5+
### Updates
6+
7+
- Refactor
8+
- Enhanced test coverage
9+
310
## v3.7.2 (2024-11-19)
411

512
### Updates

launch_venv.sh

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/bin/bash
2+
# launch_venv.sh - Script to create, set up and activate a Python virtual environment for PyStackQL
3+
4+
# Use simpler code without colors when running with sh
5+
if [ -n "$BASH_VERSION" ]; then
6+
# Color definitions for bash
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
BLUE='\033[0;34m'
10+
RED='\033[0;31m'
11+
NC='\033[0m' # No Color
12+
13+
# Function to print colored text in bash
14+
cecho() {
15+
printf "%b%s%b\n" "$1" "$2" "$NC"
16+
}
17+
else
18+
# No colors for sh
19+
cecho() {
20+
echo "$2"
21+
}
22+
fi
23+
24+
# Default virtual environment name
25+
VENV_NAME=".venv"
26+
REQUIREMENTS_FILE="requirements.txt"
27+
28+
# Function to check if command exists
29+
command_exists() {
30+
command -v "$1" >/dev/null 2>&1
31+
}
32+
33+
# Banner
34+
cecho "$BLUE" "======================================="
35+
cecho "$BLUE" " PyStackQL Development Environment "
36+
cecho "$BLUE" "======================================="
37+
echo ""
38+
39+
# Check for Python
40+
if ! command_exists python3; then
41+
cecho "$RED" "Error: Python 3 is not installed."
42+
echo "Please install Python 3 and try again."
43+
exit 1
44+
fi
45+
46+
# Print Python version
47+
cecho "$YELLOW" "Using Python:"
48+
python3 --version
49+
echo ""
50+
51+
# Create virtual environment if it doesn't exist
52+
if [ ! -d "$VENV_NAME" ]; then
53+
cecho "$YELLOW" "Creating virtual environment in ${VENV_NAME}..."
54+
python3 -m venv "$VENV_NAME"
55+
if [ $? -ne 0 ]; then
56+
cecho "$RED" "Error: Failed to create virtual environment."
57+
exit 1
58+
fi
59+
cecho "$GREEN" "Virtual environment created successfully."
60+
else
61+
cecho "$YELLOW" "Using existing virtual environment in ${VENV_NAME}"
62+
fi
63+
64+
# Determine the activate script based on OS
65+
case "$OSTYPE" in
66+
msys*|win*|cygwin*)
67+
# Windows
68+
ACTIVATE_SCRIPT="$VENV_NAME/Scripts/activate"
69+
;;
70+
*)
71+
# Unix-like (Linux, macOS)
72+
ACTIVATE_SCRIPT="$VENV_NAME/bin/activate"
73+
;;
74+
esac
75+
76+
# Check if activation script exists
77+
if [ ! -f "$ACTIVATE_SCRIPT" ]; then
78+
cecho "$RED" "Error: Activation script not found at $ACTIVATE_SCRIPT"
79+
echo "The virtual environment may be corrupt. Try removing the $VENV_NAME directory and running this script again."
80+
exit 1
81+
fi
82+
83+
# Source the activation script
84+
cecho "$YELLOW" "Activating virtual environment..."
85+
. "$ACTIVATE_SCRIPT"
86+
if [ $? -ne 0 ]; then
87+
cecho "$RED" "Error: Failed to activate virtual environment."
88+
exit 1
89+
fi
90+
91+
# Install/upgrade pip, setuptools, and wheel
92+
cecho "$YELLOW" "Upgrading pip, setuptools, and wheel..."
93+
pip install --upgrade pip setuptools wheel
94+
if [ $? -ne 0 ]; then
95+
cecho "$RED" "Warning: Failed to upgrade pip, setuptools, or wheel. Continuing anyway."
96+
fi
97+
98+
# Check if requirements.txt exists
99+
if [ ! -f "$REQUIREMENTS_FILE" ]; then
100+
cecho "$RED" "Error: $REQUIREMENTS_FILE not found."
101+
echo "Please make sure the file exists in the current directory."
102+
cecho "$YELLOW" "Continuing with an activated environment without installing dependencies."
103+
else
104+
# Install requirements
105+
cecho "$YELLOW" "Installing dependencies from $REQUIREMENTS_FILE..."
106+
pip install -r "$REQUIREMENTS_FILE"
107+
if [ $? -ne 0 ]; then
108+
cecho "$RED" "Warning: Some dependencies may have failed to install."
109+
else
110+
cecho "$GREEN" "Dependencies installed successfully."
111+
fi
112+
fi
113+
114+
# Install the package in development mode if setup.py exists
115+
if [ -f "setup.py" ]; then
116+
cecho "$YELLOW" "Installing PyStackQL in development mode..."
117+
pip install .
118+
if [ $? -ne 0 ]; then
119+
cecho "$RED" "Warning: Failed to install package in development mode."
120+
else
121+
cecho "$GREEN" "Package installed in development mode."
122+
fi
123+
fi
124+
125+
# Success message
126+
echo ""
127+
cecho "$GREEN" "Virtual environment is now set up and activated!"
128+
cecho "$YELLOW" "You can use PyStackQL and run tests."
129+
echo ""
130+
cecho "$BLUE" "To run tests:"
131+
echo " python run_tests.py"
132+
echo ""
133+
cecho "$BLUE" "To deactivate the virtual environment when done:"
134+
echo " deactivate"
135+
echo ""
136+
cecho "$BLUE" "======================================="
137+
138+
# Keep the terminal open with the activated environment
139+
# The script will be source'd, so the environment stays active
140+
exec "${SHELL:-bash}"

pystackql/__init__.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
from .stackql import StackQL
2-
from .magic import StackqlMagic
3-
from .magics import StackqlServerMagic
1+
# pystackql/__init__.py
2+
3+
"""
4+
PyStackQL - Python wrapper for StackQL
5+
6+
This package provides a Python interface to the StackQL query language
7+
for cloud resource querying.
8+
"""
9+
10+
# Import the core StackQL class
11+
from .core import StackQL
12+
13+
# Import the magic classes for Jupyter integration
14+
from .magic_ext import StackqlMagic, StackqlServerMagic
15+
16+
# Define the public API
17+
__all__ = ['StackQL', 'StackqlMagic', 'StackqlServerMagic']

0 commit comments

Comments
 (0)