Spaces:
Running
Running
attempts spaces fix
Browse files- docs/GIT_CONFIGURATION_FIX.md +257 -0
- launch.sh +2 -0
- scripts/trackio_tonic/deploy_trackio_space.py +43 -2
- tests/test_git_config_fix.py +231 -0
docs/GIT_CONFIGURATION_FIX.md
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Git Configuration Fix for Trackio Space Deployment
|
| 2 |
+
|
| 3 |
+
## Issue Identified
|
| 4 |
+
|
| 5 |
+
The Trackio Space deployment was failing with the error:
|
| 6 |
+
```
|
| 7 |
+
β Error uploading files: Command '['git', 'commit', '-m', 'Initial Trackio Space setup']' returned non-zero exit status 128.
|
| 8 |
+
```
|
| 9 |
+
|
| 10 |
+
This error occurs because git requires a user identity (email and name) to be configured before making commits. The deployment script was creating a temporary directory and initializing a git repository, but wasn't configuring the git user identity in that temporary directory.
|
| 11 |
+
|
| 12 |
+
## Root Cause
|
| 13 |
+
|
| 14 |
+
### **Problem**: Git Identity Not Configured in Temporary Directory
|
| 15 |
+
|
| 16 |
+
When the deployment script:
|
| 17 |
+
1. Creates a temporary directory
|
| 18 |
+
2. Changes to that directory (`os.chdir(temp_dir)`)
|
| 19 |
+
3. Initializes a git repository (`git init`)
|
| 20 |
+
4. Tries to commit (`git commit`)
|
| 21 |
+
|
| 22 |
+
The git repository in the temporary directory doesn't inherit the git configuration from the main directory, so it has no user identity configured.
|
| 23 |
+
|
| 24 |
+
### **Solution**: Configure Git Identity in Temporary Directory
|
| 25 |
+
|
| 26 |
+
The fix involves explicitly configuring git user identity in the temporary directory before attempting to commit.
|
| 27 |
+
|
| 28 |
+
## Fixes Applied
|
| 29 |
+
|
| 30 |
+
### 1. **Enhanced TrackioSpaceDeployer Constructor**
|
| 31 |
+
|
| 32 |
+
**Before**:
|
| 33 |
+
```python
|
| 34 |
+
def __init__(self, space_name: str, username: str, token: str):
|
| 35 |
+
self.space_name = space_name
|
| 36 |
+
self.username = username
|
| 37 |
+
self.token = token
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
**After**:
|
| 41 |
+
```python
|
| 42 |
+
def __init__(self, space_name: str, username: str, token: str, git_email: str = None, git_name: str = None):
|
| 43 |
+
self.space_name = space_name
|
| 44 |
+
self.username = username
|
| 45 |
+
self.token = token
|
| 46 |
+
|
| 47 |
+
# Git configuration
|
| 48 |
+
self.git_email = git_email or f"{username}@huggingface.co"
|
| 49 |
+
self.git_name = git_name or username
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
### 2. **Git Configuration in upload_files_to_space Method**
|
| 53 |
+
|
| 54 |
+
**Added to the method**:
|
| 55 |
+
```python
|
| 56 |
+
# Configure git user identity for this repository
|
| 57 |
+
try:
|
| 58 |
+
# Try to get existing git config
|
| 59 |
+
result = subprocess.run(["git", "config", "--global", "user.email"], capture_output=True, text=True)
|
| 60 |
+
if result.returncode == 0 and result.stdout.strip():
|
| 61 |
+
git_email = result.stdout.strip()
|
| 62 |
+
else:
|
| 63 |
+
git_email = self.git_email
|
| 64 |
+
|
| 65 |
+
result = subprocess.run(["git", "config", "--global", "user.name"], capture_output=True, text=True)
|
| 66 |
+
if result.returncode == 0 and result.stdout.strip():
|
| 67 |
+
git_name = result.stdout.strip()
|
| 68 |
+
else:
|
| 69 |
+
git_name = self.git_name
|
| 70 |
+
|
| 71 |
+
except Exception:
|
| 72 |
+
# Fallback to default values
|
| 73 |
+
git_email = self.git_email
|
| 74 |
+
git_name = self.git_name
|
| 75 |
+
|
| 76 |
+
# Set git config for this repository
|
| 77 |
+
subprocess.run(["git", "config", "user.email", git_email], check=True, capture_output=True)
|
| 78 |
+
subprocess.run(["git", "config", "user.name", git_name], check=True, capture_output=True)
|
| 79 |
+
|
| 80 |
+
print(f"β
Configured git with email: {git_email}, name: {git_name}")
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
### 3. **Updated Main Function**
|
| 84 |
+
|
| 85 |
+
**Enhanced to accept git configuration**:
|
| 86 |
+
```python
|
| 87 |
+
def main():
|
| 88 |
+
# Get user input
|
| 89 |
+
username = input("Enter your Hugging Face username: ").strip()
|
| 90 |
+
space_name = input("Enter Space name (e.g., trackio-monitoring): ").strip()
|
| 91 |
+
token = input("Enter your Hugging Face token: ").strip()
|
| 92 |
+
|
| 93 |
+
# Get git configuration (optional)
|
| 94 |
+
git_email = input("Enter your git email (optional, press Enter for default): ").strip()
|
| 95 |
+
git_name = input("Enter your git name (optional, press Enter for default): ").strip()
|
| 96 |
+
|
| 97 |
+
# Create deployer with git config
|
| 98 |
+
deployer = TrackioSpaceDeployer(space_name, username, token, git_email, git_name)
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
### 4. **Updated Launch Script**
|
| 102 |
+
|
| 103 |
+
**Enhanced to pass git configuration**:
|
| 104 |
+
```bash
|
| 105 |
+
# Create deployment script input
|
| 106 |
+
cat > deploy_input.txt << EOF
|
| 107 |
+
$HF_USERNAME
|
| 108 |
+
$TRACKIO_SPACE_NAME
|
| 109 |
+
$HF_TOKEN
|
| 110 |
+
$GIT_EMAIL
|
| 111 |
+
$HF_USERNAME
|
| 112 |
+
EOF
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
## Testing the Fix
|
| 116 |
+
|
| 117 |
+
### **Run Git Configuration Tests**
|
| 118 |
+
```bash
|
| 119 |
+
python tests/test_git_config_fix.py
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
Expected output:
|
| 123 |
+
```
|
| 124 |
+
π Testing Git Configuration Fix
|
| 125 |
+
========================================
|
| 126 |
+
π Testing git configuration in temporary directory...
|
| 127 |
+
β
Created temp directory: /tmp/tmp_xxxxx
|
| 128 |
+
β
Initialized git repository
|
| 129 |
+
β
Git email configured correctly
|
| 130 |
+
β
Git name configured correctly
|
| 131 |
+
β
Git commit successful
|
| 132 |
+
β
Cleanup successful
|
| 133 |
+
|
| 134 |
+
π Testing deployment script git configuration...
|
| 135 |
+
β
Git email set correctly
|
| 136 |
+
β
Git name set correctly
|
| 137 |
+
|
| 138 |
+
π Testing git configuration fallback...
|
| 139 |
+
β
Default git email set correctly
|
| 140 |
+
β
Default git name set correctly
|
| 141 |
+
|
| 142 |
+
π Testing git commit with configuration...
|
| 143 |
+
β
Created temp directory: /tmp/tmp_xxxxx
|
| 144 |
+
β
Git commit successful with configuration
|
| 145 |
+
β
Cleanup successful
|
| 146 |
+
|
| 147 |
+
π Test Results: 4/4 tests passed
|
| 148 |
+
β
All git configuration tests passed! The deployment should work correctly.
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
## Files Modified
|
| 152 |
+
|
| 153 |
+
### **Core Deployment Files**
|
| 154 |
+
1. **`scripts/trackio_tonic/deploy_trackio_space.py`**
|
| 155 |
+
- Enhanced constructor to accept git configuration
|
| 156 |
+
- Added git configuration in upload_files_to_space method
|
| 157 |
+
- Updated main function to accept git parameters
|
| 158 |
+
- Added fallback mechanisms for git configuration
|
| 159 |
+
|
| 160 |
+
### **Launch Script**
|
| 161 |
+
2. **`launch.sh`**
|
| 162 |
+
- Updated to pass git configuration to deployment script
|
| 163 |
+
- Enhanced input file creation with git parameters
|
| 164 |
+
|
| 165 |
+
### **Testing**
|
| 166 |
+
3. **`tests/test_git_config_fix.py`**
|
| 167 |
+
- Comprehensive testing of git configuration
|
| 168 |
+
- Tests for temporary directory git setup
|
| 169 |
+
- Tests for deployment script git handling
|
| 170 |
+
- Tests for fallback behavior
|
| 171 |
+
|
| 172 |
+
## Benefits of the Fix
|
| 173 |
+
|
| 174 |
+
### **1. Reliable Git Commits**
|
| 175 |
+
- Git user identity properly configured in temporary directory
|
| 176 |
+
- No more "exit status 128" errors
|
| 177 |
+
- Successful commits and pushes to Hugging Face Spaces
|
| 178 |
+
|
| 179 |
+
### **2. Flexible Configuration**
|
| 180 |
+
- Accepts custom git email and name
|
| 181 |
+
- Falls back to sensible defaults
|
| 182 |
+
- Works with existing git configuration
|
| 183 |
+
|
| 184 |
+
### **3. Better Error Handling**
|
| 185 |
+
- Graceful fallback to default values
|
| 186 |
+
- Clear error messages and logging
|
| 187 |
+
- Robust configuration validation
|
| 188 |
+
|
| 189 |
+
### **4. Professional Setup**
|
| 190 |
+
- Uses user's actual email address when provided
|
| 191 |
+
- Maintains proper git attribution
|
| 192 |
+
- Follows git best practices
|
| 193 |
+
|
| 194 |
+
## Usage Instructions
|
| 195 |
+
|
| 196 |
+
### **1. Test the Fix**
|
| 197 |
+
```bash
|
| 198 |
+
python tests/test_git_config_fix.py
|
| 199 |
+
```
|
| 200 |
+
|
| 201 |
+
### **2. Deploy with Git Configuration**
|
| 202 |
+
```bash
|
| 203 |
+
python scripts/trackio_tonic/deploy_trackio_space.py
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
When prompted:
|
| 207 |
+
- Enter your HF username
|
| 208 |
+
- Enter space name
|
| 209 |
+
- Enter your HF token
|
| 210 |
+
- Enter your git email (or press Enter for default)
|
| 211 |
+
- Enter your git name (or press Enter for default)
|
| 212 |
+
|
| 213 |
+
### **3. Use with Launch Script**
|
| 214 |
+
```bash
|
| 215 |
+
./launch.sh
|
| 216 |
+
```
|
| 217 |
+
|
| 218 |
+
The launch script will automatically pass the git configuration to the deployment script.
|
| 219 |
+
|
| 220 |
+
## Troubleshooting
|
| 221 |
+
|
| 222 |
+
### **Common Issues**
|
| 223 |
+
|
| 224 |
+
#### **1. Git Configuration Still Fails**
|
| 225 |
+
```bash
|
| 226 |
+
# Check if git is properly configured
|
| 227 |
+
git config --list
|
| 228 |
+
|
| 229 |
+
# Set git config manually if needed
|
| 230 |
+
git config --global user.email "[email protected]"
|
| 231 |
+
git config --global user.name "Your Name"
|
| 232 |
+
```
|
| 233 |
+
|
| 234 |
+
#### **2. Permission Issues**
|
| 235 |
+
```bash
|
| 236 |
+
# Check HF token permissions
|
| 237 |
+
huggingface-cli whoami
|
| 238 |
+
|
| 239 |
+
# Verify token has write access
|
| 240 |
+
huggingface-cli repo create test-repo --type space
|
| 241 |
+
```
|
| 242 |
+
|
| 243 |
+
#### **3. Space Creation Fails**
|
| 244 |
+
```bash
|
| 245 |
+
# Check if space name is available
|
| 246 |
+
# Try a different space name
|
| 247 |
+
# Verify HF token is valid
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
## Next Steps
|
| 251 |
+
|
| 252 |
+
1. **Test the fix**: Run the git configuration tests
|
| 253 |
+
2. **Deploy a test space**: Use the updated deployment script
|
| 254 |
+
3. **Verify deployment**: Check that the space is created successfully
|
| 255 |
+
4. **Use in production**: Deploy your actual Trackio Space
|
| 256 |
+
|
| 257 |
+
The git configuration fix should resolve the deployment issues and allow successful Trackio Space creation! π
|
launch.sh
CHANGED
|
@@ -495,6 +495,8 @@ cat > deploy_input.txt << EOF
|
|
| 495 |
$HF_USERNAME
|
| 496 |
$TRACKIO_SPACE_NAME
|
| 497 |
$HF_TOKEN
|
|
|
|
|
|
|
| 498 |
EOF
|
| 499 |
|
| 500 |
# Run deployment script
|
|
|
|
| 495 |
$HF_USERNAME
|
| 496 |
$TRACKIO_SPACE_NAME
|
| 497 |
$HF_TOKEN
|
| 498 |
+
$GIT_EMAIL
|
| 499 |
+
$HF_USERNAME
|
| 500 |
EOF
|
| 501 |
|
| 502 |
# Run deployment script
|
scripts/trackio_tonic/deploy_trackio_space.py
CHANGED
|
@@ -25,12 +25,16 @@ except ImportError:
|
|
| 25 |
class TrackioSpaceDeployer:
|
| 26 |
"""Deployer for Trackio on Hugging Face Spaces"""
|
| 27 |
|
| 28 |
-
def __init__(self, space_name: str, username: str, token: str):
|
| 29 |
self.space_name = space_name
|
| 30 |
self.username = username
|
| 31 |
self.token = token
|
| 32 |
self.space_url = f"https://huggingface.co/spaces/{username}/{space_name}"
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# Initialize HF API
|
| 35 |
if HF_HUB_AVAILABLE:
|
| 36 |
self.api = HfApi(token=self.token)
|
|
@@ -179,6 +183,33 @@ class TrackioSpaceDeployer:
|
|
| 179 |
subprocess.run(["git", "init"], check=True, capture_output=True)
|
| 180 |
subprocess.run(["git", "remote", "add", "origin", f"https://huggingface.co/spaces/{self.username}/{self.space_name}"], check=True, capture_output=True)
|
| 181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
# Add all files
|
| 183 |
subprocess.run(["git", "add", "."], check=True, capture_output=True)
|
| 184 |
subprocess.run(["git", "commit", "-m", "Initial Trackio Space setup"], check=True, capture_output=True)
|
|
@@ -273,12 +304,22 @@ def main():
|
|
| 273 |
space_name = input("Enter Space name (e.g., trackio-monitoring): ").strip()
|
| 274 |
token = input("Enter your Hugging Face token: ").strip()
|
| 275 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
if not username or not space_name or not token:
|
| 277 |
print("β Username, Space name, and token are required")
|
| 278 |
sys.exit(1)
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
# Create deployer
|
| 281 |
-
deployer = TrackioSpaceDeployer(space_name, username, token)
|
| 282 |
|
| 283 |
# Run deployment
|
| 284 |
success = deployer.deploy()
|
|
|
|
| 25 |
class TrackioSpaceDeployer:
|
| 26 |
"""Deployer for Trackio on Hugging Face Spaces"""
|
| 27 |
|
| 28 |
+
def __init__(self, space_name: str, username: str, token: str, git_email: str = None, git_name: str = None):
|
| 29 |
self.space_name = space_name
|
| 30 |
self.username = username
|
| 31 |
self.token = token
|
| 32 |
self.space_url = f"https://huggingface.co/spaces/{username}/{space_name}"
|
| 33 |
|
| 34 |
+
# Git configuration
|
| 35 |
+
self.git_email = git_email or f"{username}@huggingface.co"
|
| 36 |
+
self.git_name = git_name or username
|
| 37 |
+
|
| 38 |
# Initialize HF API
|
| 39 |
if HF_HUB_AVAILABLE:
|
| 40 |
self.api = HfApi(token=self.token)
|
|
|
|
| 183 |
subprocess.run(["git", "init"], check=True, capture_output=True)
|
| 184 |
subprocess.run(["git", "remote", "add", "origin", f"https://huggingface.co/spaces/{self.username}/{self.space_name}"], check=True, capture_output=True)
|
| 185 |
|
| 186 |
+
# Configure git user identity for this repository
|
| 187 |
+
# Get git config from the original directory or use defaults
|
| 188 |
+
try:
|
| 189 |
+
# Try to get existing git config
|
| 190 |
+
result = subprocess.run(["git", "config", "--global", "user.email"], capture_output=True, text=True)
|
| 191 |
+
if result.returncode == 0 and result.stdout.strip():
|
| 192 |
+
git_email = result.stdout.strip()
|
| 193 |
+
else:
|
| 194 |
+
git_email = self.git_email
|
| 195 |
+
|
| 196 |
+
result = subprocess.run(["git", "config", "--global", "user.name"], capture_output=True, text=True)
|
| 197 |
+
if result.returncode == 0 and result.stdout.strip():
|
| 198 |
+
git_name = result.stdout.strip()
|
| 199 |
+
else:
|
| 200 |
+
git_name = self.git_name
|
| 201 |
+
|
| 202 |
+
except Exception:
|
| 203 |
+
# Fallback to default values
|
| 204 |
+
git_email = self.git_email
|
| 205 |
+
git_name = self.git_name
|
| 206 |
+
|
| 207 |
+
# Set git config for this repository
|
| 208 |
+
subprocess.run(["git", "config", "user.email", git_email], check=True, capture_output=True)
|
| 209 |
+
subprocess.run(["git", "config", "user.name", git_name], check=True, capture_output=True)
|
| 210 |
+
|
| 211 |
+
print(f"β
Configured git with email: {git_email}, name: {git_name}")
|
| 212 |
+
|
| 213 |
# Add all files
|
| 214 |
subprocess.run(["git", "add", "."], check=True, capture_output=True)
|
| 215 |
subprocess.run(["git", "commit", "-m", "Initial Trackio Space setup"], check=True, capture_output=True)
|
|
|
|
| 304 |
space_name = input("Enter Space name (e.g., trackio-monitoring): ").strip()
|
| 305 |
token = input("Enter your Hugging Face token: ").strip()
|
| 306 |
|
| 307 |
+
# Get git configuration (optional)
|
| 308 |
+
git_email = input("Enter your git email (optional, press Enter for default): ").strip()
|
| 309 |
+
git_name = input("Enter your git name (optional, press Enter for default): ").strip()
|
| 310 |
+
|
| 311 |
if not username or not space_name or not token:
|
| 312 |
print("β Username, Space name, and token are required")
|
| 313 |
sys.exit(1)
|
| 314 |
|
| 315 |
+
# Use empty strings if not provided
|
| 316 |
+
if not git_email:
|
| 317 |
+
git_email = None
|
| 318 |
+
if not git_name:
|
| 319 |
+
git_name = None
|
| 320 |
+
|
| 321 |
# Create deployer
|
| 322 |
+
deployer = TrackioSpaceDeployer(space_name, username, token, git_email, git_name)
|
| 323 |
|
| 324 |
# Run deployment
|
| 325 |
success = deployer.deploy()
|
tests/test_git_config_fix.py
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test script to verify the git configuration fix for Trackio Space deployment
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import sys
|
| 8 |
+
import tempfile
|
| 9 |
+
import shutil
|
| 10 |
+
import subprocess
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
# Add project root to path
|
| 14 |
+
project_root = Path(__file__).parent.parent
|
| 15 |
+
sys.path.insert(0, str(project_root))
|
| 16 |
+
|
| 17 |
+
def test_git_config_in_temp_dir():
|
| 18 |
+
"""Test that git configuration works in temporary directory"""
|
| 19 |
+
print("π Testing git configuration in temporary directory...")
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
# Create temporary directory
|
| 23 |
+
temp_dir = tempfile.mkdtemp()
|
| 24 |
+
print(f"β
Created temp directory: {temp_dir}")
|
| 25 |
+
|
| 26 |
+
# Change to temp directory
|
| 27 |
+
original_dir = os.getcwd()
|
| 28 |
+
os.chdir(temp_dir)
|
| 29 |
+
|
| 30 |
+
# Initialize git repository
|
| 31 |
+
subprocess.run(["git", "init"], check=True, capture_output=True)
|
| 32 |
+
print("β
Initialized git repository")
|
| 33 |
+
|
| 34 |
+
# Test git configuration
|
| 35 |
+
test_email = "[email protected]"
|
| 36 |
+
test_name = "Test User"
|
| 37 |
+
|
| 38 |
+
# Set git config
|
| 39 |
+
subprocess.run(["git", "config", "user.email", test_email], check=True, capture_output=True)
|
| 40 |
+
subprocess.run(["git", "config", "user.name", test_name], check=True, capture_output=True)
|
| 41 |
+
|
| 42 |
+
# Verify git config
|
| 43 |
+
result = subprocess.run(["git", "config", "user.email"], capture_output=True, text=True)
|
| 44 |
+
if result.returncode == 0 and result.stdout.strip() == test_email:
|
| 45 |
+
print("β
Git email configured correctly")
|
| 46 |
+
else:
|
| 47 |
+
print(f"β Git email not configured correctly: {result.stdout}")
|
| 48 |
+
return False
|
| 49 |
+
|
| 50 |
+
result = subprocess.run(["git", "config", "user.name"], capture_output=True, text=True)
|
| 51 |
+
if result.returncode == 0 and result.stdout.strip() == test_name:
|
| 52 |
+
print("β
Git name configured correctly")
|
| 53 |
+
else:
|
| 54 |
+
print(f"β Git name not configured correctly: {result.stdout}")
|
| 55 |
+
return False
|
| 56 |
+
|
| 57 |
+
# Test git commit
|
| 58 |
+
# Create a test file
|
| 59 |
+
with open("test.txt", "w") as f:
|
| 60 |
+
f.write("Test file for git commit")
|
| 61 |
+
|
| 62 |
+
subprocess.run(["git", "add", "test.txt"], check=True, capture_output=True)
|
| 63 |
+
subprocess.run(["git", "commit", "-m", "Test commit"], check=True, capture_output=True)
|
| 64 |
+
print("β
Git commit successful")
|
| 65 |
+
|
| 66 |
+
# Return to original directory
|
| 67 |
+
os.chdir(original_dir)
|
| 68 |
+
|
| 69 |
+
# Clean up
|
| 70 |
+
shutil.rmtree(temp_dir)
|
| 71 |
+
print("β
Cleanup successful")
|
| 72 |
+
|
| 73 |
+
return True
|
| 74 |
+
|
| 75 |
+
except Exception as e:
|
| 76 |
+
print(f"β Error testing git config: {e}")
|
| 77 |
+
# Return to original directory
|
| 78 |
+
os.chdir(original_dir)
|
| 79 |
+
return False
|
| 80 |
+
|
| 81 |
+
def test_deployment_script_git_config():
|
| 82 |
+
"""Test that the deployment script handles git configuration correctly"""
|
| 83 |
+
print("\nπ Testing deployment script git configuration...")
|
| 84 |
+
|
| 85 |
+
try:
|
| 86 |
+
sys.path.insert(0, str(project_root / "scripts" / "trackio_tonic"))
|
| 87 |
+
from deploy_trackio_space import TrackioSpaceDeployer
|
| 88 |
+
|
| 89 |
+
# Test with git configuration
|
| 90 |
+
deployer = TrackioSpaceDeployer(
|
| 91 |
+
"test-space",
|
| 92 |
+
"test-user",
|
| 93 |
+
"test-token",
|
| 94 |
+
git_email="[email protected]",
|
| 95 |
+
git_name="Test User"
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
# Check that git config is set
|
| 99 |
+
if deployer.git_email == "[email protected]":
|
| 100 |
+
print("β
Git email set correctly")
|
| 101 |
+
else:
|
| 102 |
+
print(f"β Git email not set correctly: {deployer.git_email}")
|
| 103 |
+
return False
|
| 104 |
+
|
| 105 |
+
if deployer.git_name == "Test User":
|
| 106 |
+
print("β
Git name set correctly")
|
| 107 |
+
else:
|
| 108 |
+
print(f"β Git name not set correctly: {deployer.git_name}")
|
| 109 |
+
return False
|
| 110 |
+
|
| 111 |
+
return True
|
| 112 |
+
|
| 113 |
+
except Exception as e:
|
| 114 |
+
print(f"β Error testing deployment script: {e}")
|
| 115 |
+
return False
|
| 116 |
+
|
| 117 |
+
def test_git_config_fallback():
|
| 118 |
+
"""Test git configuration fallback behavior"""
|
| 119 |
+
print("\nπ Testing git configuration fallback...")
|
| 120 |
+
|
| 121 |
+
try:
|
| 122 |
+
sys.path.insert(0, str(project_root / "scripts" / "trackio_tonic"))
|
| 123 |
+
from deploy_trackio_space import TrackioSpaceDeployer
|
| 124 |
+
|
| 125 |
+
# Test without git configuration (should use defaults)
|
| 126 |
+
deployer = TrackioSpaceDeployer("test-space", "test-user", "test-token")
|
| 127 |
+
|
| 128 |
+
# Check default values
|
| 129 |
+
expected_email = "[email protected]"
|
| 130 |
+
expected_name = "test-user"
|
| 131 |
+
|
| 132 |
+
if deployer.git_email == expected_email:
|
| 133 |
+
print("β
Default git email set correctly")
|
| 134 |
+
else:
|
| 135 |
+
print(f"β Default git email not set correctly: {deployer.git_email}")
|
| 136 |
+
return False
|
| 137 |
+
|
| 138 |
+
if deployer.git_name == expected_name:
|
| 139 |
+
print("β
Default git name set correctly")
|
| 140 |
+
else:
|
| 141 |
+
print(f"β Default git name not set correctly: {deployer.git_name}")
|
| 142 |
+
return False
|
| 143 |
+
|
| 144 |
+
return True
|
| 145 |
+
|
| 146 |
+
except Exception as e:
|
| 147 |
+
print(f"β Error testing git config fallback: {e}")
|
| 148 |
+
return False
|
| 149 |
+
|
| 150 |
+
def test_git_commit_with_config():
|
| 151 |
+
"""Test that git commit works with proper configuration"""
|
| 152 |
+
print("\nπ Testing git commit with configuration...")
|
| 153 |
+
|
| 154 |
+
try:
|
| 155 |
+
# Create temporary directory
|
| 156 |
+
temp_dir = tempfile.mkdtemp()
|
| 157 |
+
print(f"β
Created temp directory: {temp_dir}")
|
| 158 |
+
|
| 159 |
+
# Change to temp directory
|
| 160 |
+
original_dir = os.getcwd()
|
| 161 |
+
os.chdir(temp_dir)
|
| 162 |
+
|
| 163 |
+
# Initialize git repository
|
| 164 |
+
subprocess.run(["git", "init"], check=True, capture_output=True)
|
| 165 |
+
|
| 166 |
+
# Set git configuration
|
| 167 |
+
subprocess.run(["git", "config", "user.email", "[email protected]"], check=True, capture_output=True)
|
| 168 |
+
subprocess.run(["git", "config", "user.name", "Test User"], check=True, capture_output=True)
|
| 169 |
+
|
| 170 |
+
# Create test file
|
| 171 |
+
with open("test.txt", "w") as f:
|
| 172 |
+
f.write("Test content")
|
| 173 |
+
|
| 174 |
+
# Add and commit
|
| 175 |
+
subprocess.run(["git", "add", "test.txt"], check=True, capture_output=True)
|
| 176 |
+
subprocess.run(["git", "commit", "-m", "Test commit"], check=True, capture_output=True)
|
| 177 |
+
print("β
Git commit successful with configuration")
|
| 178 |
+
|
| 179 |
+
# Return to original directory
|
| 180 |
+
os.chdir(original_dir)
|
| 181 |
+
|
| 182 |
+
# Clean up
|
| 183 |
+
shutil.rmtree(temp_dir)
|
| 184 |
+
print("β
Cleanup successful")
|
| 185 |
+
|
| 186 |
+
return True
|
| 187 |
+
|
| 188 |
+
except Exception as e:
|
| 189 |
+
print(f"β Error testing git commit: {e}")
|
| 190 |
+
# Return to original directory
|
| 191 |
+
os.chdir(original_dir)
|
| 192 |
+
return False
|
| 193 |
+
|
| 194 |
+
def main():
|
| 195 |
+
"""Run all git configuration tests"""
|
| 196 |
+
print("π Testing Git Configuration Fix")
|
| 197 |
+
print("=" * 40)
|
| 198 |
+
|
| 199 |
+
tests = [
|
| 200 |
+
test_git_config_in_temp_dir,
|
| 201 |
+
test_deployment_script_git_config,
|
| 202 |
+
test_git_config_fallback,
|
| 203 |
+
test_git_commit_with_config
|
| 204 |
+
]
|
| 205 |
+
|
| 206 |
+
passed = 0
|
| 207 |
+
total = len(tests)
|
| 208 |
+
|
| 209 |
+
for test in tests:
|
| 210 |
+
try:
|
| 211 |
+
if test():
|
| 212 |
+
passed += 1
|
| 213 |
+
except Exception as e:
|
| 214 |
+
print(f"β Test {test.__name__} crashed: {e}")
|
| 215 |
+
|
| 216 |
+
print(f"\nπ Test Results: {passed}/{total} tests passed")
|
| 217 |
+
|
| 218 |
+
if passed == total:
|
| 219 |
+
print("β
All git configuration tests passed! The deployment should work correctly.")
|
| 220 |
+
print("\nπ― Next steps:")
|
| 221 |
+
print("1. Run the deployment script: python scripts/trackio_tonic/deploy_trackio_space.py")
|
| 222 |
+
print("2. Provide your HF username, space name, token, and git config")
|
| 223 |
+
print("3. The git commit should now work correctly")
|
| 224 |
+
return True
|
| 225 |
+
else:
|
| 226 |
+
print("β Some git configuration tests failed. Please check the errors above.")
|
| 227 |
+
return False
|
| 228 |
+
|
| 229 |
+
if __name__ == "__main__":
|
| 230 |
+
success = main()
|
| 231 |
+
sys.exit(0 if success else 1)
|