Skip to content

Commit 1e17c6a

Browse files
committed
Merge branch 'master' into feature/se
2 parents fc161fb + e98b02b commit 1e17c6a

File tree

3 files changed

+319
-5
lines changed

3 files changed

+319
-5
lines changed

scripts/README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Python Version Check Script
2+
3+
This script checks for Python version 3.12 or higher and offers installation if requirements are not met.
4+
5+
## Supported Operating Systems
6+
7+
- **macOS** - uses Homebrew
8+
- **Ubuntu/Debian** - uses apt with deadsnakes PPA
9+
- **Arch Linux** - uses pacman
10+
11+
## Usage
12+
13+
1. Make the script executable:
14+
```bash
15+
chmod +x scripts/check_python.sh
16+
```
17+
18+
2. Run the script:
19+
```bash
20+
./scripts/check_python.sh
21+
```
22+
23+
## What the Script Does
24+
25+
1. **Python Version Check**: Searches for available Python commands and checks their versions
26+
2. **OS Detection**: Automatically detects the operating system
27+
3. **Installation Offer**: If a suitable version is not found, offers to install
28+
4. **Installation**: Uses the appropriate package manager for installation
29+
5. **Result Verification**: Ensures the installation was successful
30+
31+
## Example Output
32+
33+
### Successful Check
34+
```
35+
[INFO] Checking Python version requirements (>= 3.12)
36+
Found python3.12 version: 3.12.1
37+
[SUCCESS] Python requirement satisfied with python3.12
38+
[SUCCESS] Python version check passed!
39+
```
40+
41+
### Installation on Ubuntu
42+
```
43+
[INFO] Checking Python version requirements (>= 3.12)
44+
Found python3 version: 3.10.6
45+
[WARNING] Python 3.12+ not found or version is too old
46+
[INFO] Detected OS: ubuntu
47+
[WARNING] Do you want to install/update Python? (y/N)
48+
y
49+
[INFO] Installing Python on Ubuntu...
50+
[INFO] Updating package list...
51+
[INFO] Adding deadsnakes PPA...
52+
[INFO] Installing Python 3.12...
53+
[INFO] Verifying installation...
54+
Found python3.12 version: 3.12.7
55+
[SUCCESS] Installation successful! Python requirement satisfied with python3.12
56+
```
57+
58+
## Requirements
59+
60+
### macOS
61+
- Homebrew must be installed
62+
- If Homebrew is not installed, the script will provide installation instructions
63+
64+
### Ubuntu/Debian
65+
- Sudo privileges for package installation
66+
- Internet access to add PPA
67+
68+
### Arch Linux
69+
- Sudo privileges to use pacman
70+
- Internet access for package updates
71+
72+
## Security
73+
74+
The script:
75+
- Always asks for permission before installation
76+
- Uses official package repositories
77+
- Does not modify system files without permission
78+
- Can be safely interrupted at any time (Ctrl+C)
79+
80+
## Troubleshooting
81+
82+
### Script cannot find Python after installation
83+
Restart your terminal or run:
84+
```bash
85+
source ~/.bashrc # for bash
86+
source ~/.zshrc # for zsh
87+
```
88+
89+
### Permission errors
90+
Make sure you have sudo privileges and your user can install packages.
91+
92+
### Homebrew not found (macOS)
93+
Install Homebrew:
94+
```bash
95+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
96+
```
97+
98+
## Script Features
99+
100+
- **Multi-platform support**: Works on macOS, Ubuntu/Debian, and Arch Linux
101+
- **Smart detection**: Checks multiple Python command variants (python3.12, python3.13, python3, python)
102+
- **Safe installation**: Always prompts before making changes
103+
- **Colored output**: Easy-to-read status messages
104+
- **Error handling**: Graceful handling of edge cases and errors
105+
- **Verification**: Post-installation verification to ensure success

scripts/check_python.sh

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
#!/bin/bash
2+
3+
# Script to check and install Python 3.12 or higher
4+
# Supports: macOS, Ubuntu, Arch Linux
5+
6+
set -e
7+
8+
REQUIRED_MAJOR=3
9+
REQUIRED_MINOR=12
10+
11+
# Colors for output
12+
RED='\033[0;31m'
13+
GREEN='\033[0;32m'
14+
YELLOW='\033[1;33m'
15+
BLUE='\033[0;34m'
16+
NC='\033[0m' # No Color
17+
18+
print_info() {
19+
echo -e "${BLUE}[INFO]${NC} $1"
20+
}
21+
22+
print_success() {
23+
echo -e "${GREEN}[SUCCESS]${NC} $1"
24+
}
25+
26+
print_warning() {
27+
echo -e "${YELLOW}[WARNING]${NC} $1"
28+
}
29+
30+
print_error() {
31+
echo -e "${RED}[ERROR]${NC} $1"
32+
}
33+
34+
# Function to check Python version
35+
check_python_version() {
36+
local python_cmd=$1
37+
38+
if ! command -v "$python_cmd" &> /dev/null; then
39+
return 1
40+
fi
41+
42+
local version_output
43+
version_output=$($python_cmd --version 2>&1)
44+
45+
# Extract version numbers
46+
local version
47+
version=$(echo "$version_output" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
48+
49+
if [[ -z "$version" ]]; then
50+
return 1
51+
fi
52+
53+
local major minor patch
54+
IFS='.' read -r major minor patch <<< "$version"
55+
56+
echo "Found $python_cmd version: $version"
57+
58+
if [[ $major -gt $REQUIRED_MAJOR ]] ||
59+
[[ $major -eq $REQUIRED_MAJOR && $minor -ge $REQUIRED_MINOR ]]; then
60+
return 0
61+
else
62+
return 1
63+
fi
64+
}
65+
66+
# Function to detect OS
67+
detect_os() {
68+
if [[ "$OSTYPE" == "darwin"* ]]; then
69+
echo "macos"
70+
elif [[ -f /etc/arch-release ]]; then
71+
echo "arch"
72+
elif [[ -f /etc/debian_version ]] || [[ -f /etc/ubuntu-release ]]; then
73+
echo "ubuntu"
74+
else
75+
echo "unknown"
76+
fi
77+
}
78+
79+
# Function to install Python on macOS
80+
install_python_macos() {
81+
print_info "Installing Python on macOS..."
82+
83+
if ! command -v brew &> /dev/null; then
84+
print_error "Homebrew is not installed. Please install Homebrew first:"
85+
echo " /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
86+
exit 1
87+
fi
88+
89+
print_info "Updating Homebrew..."
90+
brew update
91+
92+
print_info "Installing Python 3.12..."
93+
brew install [email protected]
94+
95+
# Create symlinks if needed
96+
if [[ ! -L /usr/local/bin/python3.12 ]]; then
97+
98+
fi
99+
}
100+
101+
# Function to install Python on Ubuntu
102+
install_python_ubuntu() {
103+
print_info "Installing Python on Ubuntu..."
104+
105+
print_info "Updating package list..."
106+
sudo apt update
107+
108+
# Add deadsnakes PPA for newer Python versions
109+
print_info "Adding deadsnakes PPA..."
110+
sudo apt install -y software-properties-common
111+
sudo add-apt-repository -y ppa:deadsnakes/ppa
112+
sudo apt update
113+
114+
print_info "Installing Python 3.12..."
115+
sudo apt install -y python3.12 python3.12-venv python3.12-pip python3.12-dev
116+
117+
# Set up alternatives
118+
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
119+
}
120+
121+
# Function to install Python on Arch Linux
122+
install_python_arch() {
123+
print_info "Installing Python on Arch Linux..."
124+
125+
print_info "Updating package database..."
126+
sudo pacman -Sy
127+
128+
print_info "Installing Python..."
129+
sudo pacman -S --noconfirm python python-pip
130+
}
131+
132+
# Main function
133+
main() {
134+
print_info "Checking Python version requirements (>= ${REQUIRED_MAJOR}.${REQUIRED_MINOR})"
135+
136+
# Check various Python commands
137+
local python_found=false
138+
local python_commands=("python3.12" "python3.13" "python3.14" "python3" "python")
139+
140+
for cmd in "${python_commands[@]}"; do
141+
if check_python_version "$cmd"; then
142+
print_success "Python requirement satisfied with $cmd"
143+
python_found=true
144+
break
145+
fi
146+
done
147+
148+
if [[ "$python_found" == "true" ]]; then
149+
print_success "Python version check passed!"
150+
exit 0
151+
fi
152+
153+
print_warning "Python ${REQUIRED_MAJOR}.${REQUIRED_MINOR}+ not found or version is too old"
154+
155+
# Detect OS
156+
local os
157+
os=$(detect_os)
158+
print_info "Detected OS: $os"
159+
160+
# Ask user for permission to install
161+
echo
162+
print_warning "Do you want to install/update Python? (y/N)"
163+
read -r response
164+
165+
if [[ ! "$response" =~ ^[Yy]$ ]]; then
166+
print_info "Installation cancelled by user"
167+
exit 0
168+
fi
169+
170+
# Install based on OS
171+
case $os in
172+
"macos")
173+
install_python_macos
174+
;;
175+
"ubuntu")
176+
install_python_ubuntu
177+
;;
178+
"arch")
179+
install_python_arch
180+
;;
181+
*)
182+
print_error "Unsupported operating system: $os"
183+
print_info "Please install Python ${REQUIRED_MAJOR}.${REQUIRED_MINOR}+ manually"
184+
exit 1
185+
;;
186+
esac
187+
188+
# Verify installation
189+
print_info "Verifying installation..."
190+
sleep 2
191+
192+
python_found=false
193+
for cmd in "${python_commands[@]}"; do
194+
if check_python_version "$cmd"; then
195+
print_success "Installation successful! Python requirement satisfied with $cmd"
196+
python_found=true
197+
break
198+
fi
199+
done
200+
201+
if [[ "$python_found" == "false" ]]; then
202+
print_error "Installation completed but Python ${REQUIRED_MAJOR}.${REQUIRED_MINOR}+ still not found"
203+
print_info "You may need to restart your terminal or add Python to your PATH"
204+
exit 1
205+
fi
206+
}
207+
208+
# Run main function
209+
main "$@"

test-vectors/safrole/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
find_package(qdrvm-crates CONFIG REQUIRED)
88

99
# TODO(iceseer): re-enable safrole tests
10-
# add_test_vector(safrole tiny full)
10+
add_test_vector(safrole tiny full)
1111

12-
# add_test_vector_libraries(safrole
13-
# PkgConfig::libb2
14-
# ark_vrf::ark_vrf
15-
# )
12+
add_test_vector_libraries(safrole
13+
PkgConfig::libb2
14+
ark_vrf::ark_vrf
15+
)

0 commit comments

Comments
 (0)