Download check_git_status.py from p3rc03/2B: direct link, hf CLI and curl.
- Browser
- Download file 4.98 kB
-
https://huggingface.co/spaces/p3rc03/2B/resolve/main/check_git_status.py
- Command line
-
hf download hf://spaces/p3rc03/2B/check_git_status.py
-
curl -L -o check_git_status.py https://huggingface.co/spaces/p3rc03/2B/resolve/main/check_git_status.py
4.98 kB
| #!/usr/bin/env python | |
| """ | |
| Check Git status and configuration for Hugging Face Space deployment. | |
| This script helps troubleshoot git issues when deploying to Hugging Face Spaces. | |
| """ | |
| import subprocess | |
| import os | |
| import sys | |
| def run_cmd(cmd, description, show_output=True): | |
| """Run a command and return the result.""" | |
| print(f"\n{description}:") | |
| try: | |
| if show_output: | |
| subprocess.run(cmd, check=True) | |
| return True | |
| else: | |
| result = subprocess.run(cmd, check=True, capture_output=True, text=True) | |
| return result.stdout.strip() | |
| except subprocess.CalledProcessError as e: | |
| print(f"Error: {e}") | |
| if e.stderr: | |
| print(f"Details: {e.stderr}") | |
| return False | |
| def check_git_installation(): | |
| """Check if git is installed and properly configured.""" | |
| print("="*50) | |
| print("Checking Git Installation and Configuration") | |
| print("="*50) | |
| # Check git version | |
| if not run_cmd(["git", "--version"], "Git version"): | |
| print("Git is not installed. Please install Git and try again.") | |
| return False | |
| # Check git configuration | |
| user_name = run_cmd(["git", "config", "user.name"], "Git user name", False) | |
| user_email = run_cmd(["git", "config", "user.email"], "Git user email", False) | |
| if not user_name or not user_email: | |
| print("\nGit user name or email is not configured. Please set them:") | |
| print(" git config --global user.name \"Your Name\"") | |
| print(" git config --global user.email \"your.email@example.com\"") | |
| # Prompt to set them now | |
| if input("\nDo you want to set them now? (y/n): ").lower() == 'y': | |
| name = input("Enter your name: ") | |
| email = input("Enter your email: ") | |
| run_cmd(["git", "config", "--global", "user.name", name], "Setting Git user name", False) | |
| run_cmd(["git", "config", "--global", "user.email", email], "Setting Git user email", False) | |
| print("Git configuration updated.") | |
| else: | |
| return False | |
| else: | |
| print(f"\nGit user name: {user_name}") | |
| print(f"Git user email: {user_email}") | |
| return True | |
| def check_git_repository(): | |
| """Check the Git repository status.""" | |
| print("\n" + "="*50) | |
| print("Checking Git Repository Status") | |
| print("="*50) | |
| # Check if this is a git repository | |
| is_git_repo = os.path.exists(".git") | |
| print(f"\nIs Git repository: {'Yes' if is_git_repo else 'No'}") | |
| if not is_git_repo: | |
| print("This is not a git repository. You can initialize it with 'git init'") | |
| # Prompt to initialize git | |
| if input("\nDo you want to initialize git now? (y/n): ").lower() == 'y': | |
| run_cmd(["git", "init"], "Initializing Git repository") | |
| print("Git repository initialized.") | |
| else: | |
| return False | |
| # Check git status | |
| run_cmd(["git", "status"], "Git status") | |
| # Check remote repositories | |
| run_cmd(["git", "remote", "-v"], "Git remotes") | |
| return True | |
| def check_huggingface_configuration(): | |
| """Check Hugging Face-specific configurations.""" | |
| print("\n" + "="*50) | |
| print("Checking Hugging Face Configuration") | |
| print("="*50) | |
| # Check if huggingface_hub is installed | |
| try: | |
| import huggingface_hub | |
| print(f"\nhuggingface_hub version: {huggingface_hub.__version__}") | |
| except ImportError: | |
| print("\nhuggingface_hub is not installed. Installing...") | |
| subprocess.run([sys.executable, "-m", "pip", "install", "huggingface_hub"], check=True) | |
| print("huggingface_hub installed.") | |
| # Check environment variables | |
| hf_username = os.environ.get("HF_USERNAME") | |
| hf_token = os.environ.get("HF_TOKEN") | |
| print(f"\nHF_USERNAME is {'set' if hf_username else 'not set'}") | |
| print(f"HF_TOKEN is {'set' if hf_token else 'not set'}") | |
| if not hf_username or not hf_token: | |
| print("\nPlease set HF_USERNAME and HF_TOKEN environment variables.") | |
| print("You can run the deploy_to_hf.py script to do this.") | |
| return True | |
| def main(): | |
| """Main function to check git status.""" | |
| # Check git installation | |
| if not check_git_installation(): | |
| print("\nGit installation or configuration issue. Please fix and try again.") | |
| return | |
| # Check git repository | |
| if not check_git_repository(): | |
| print("\nGit repository issue. Please fix and try again.") | |
| return | |
| # Check Hugging Face configuration | |
| if not check_huggingface_configuration(): | |
| print("\nHugging Face configuration issue. Please fix and try again.") | |
| return | |
| print("\n" + "="*50) | |
| print("Git status check completed successfully!") | |
| print("="*50) | |
| print("\nYou are ready to deploy to Hugging Face Spaces.") | |
| print("Run 'python deploy_to_hf.py' to begin deployment.") | |
| if __name__ == "__main__": | |
| main() |