File size: 2,365 Bytes
822dc53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import subprocess
from huggingface_hub import login

def clone_and_initialize_repo(repo_url, target_dir):
    """
    Clone a GitHub repository using a personal access token and initialize submodules.
    """
    github_token = os.getenv("GITHUB_TOKEN")
    if not github_token:
        raise ValueError("Error: GITHUB_TOKEN is not set in environment variables.")

    # Construct the authenticated repository URL
    authenticated_repo_url = repo_url.replace(
        "https://", f"https://{github_token}@"
    )

    try:
        # Clone the repository
        print(f"Cloning repository from {repo_url} into {target_dir}...")
        subprocess.run(
            ["git", "clone", "--recurse-submodules", authenticated_repo_url, target_dir],
            check=True
        )

        # Navigate to the repository directory
        os.chdir(target_dir)

        # Initialize and update submodules
        print("Initializing and updating submodules...")
        subprocess.run(["git", "submodule", "update", "--init", "--recursive"], check=True)

        print("Repository cloned and submodules initialized successfully.")
    except subprocess.CalledProcessError as e:
        print(f"Error during repository cloning or submodule initialization: {e}")
        raise


def huggingface_login():
    """
    Log in to Hugging Face using the API token from environment variables.
    """
    hf_token = os.getenv("HF_TOKEN")
    if not hf_token:
        raise ValueError("Error: HF_TOKEN is not set in environment variables.")

    try:
        print("Logging in to Hugging Face...")
        login(token=hf_token, add_to_git_credential=False)
        print("Hugging Face login successful.")
    except Exception as e:
        print(f"Error during Hugging Face login: {e}")
        raise


def main():
    """
    Main function to perform all operations.
    """
    # Define the repository URL and target directory
    repo_url = "https://github.com/dadwadw233/BoxDreamer.git"
    target_dir = "./BoxDreamer"

    try:
        # Clone the repository and initialize submodules
        clone_and_initialize_repo(repo_url, target_dir)

        # Log in to Hugging Face
        huggingface_login()

        print("All operations completed successfully.")
    except Exception as e:
        print(f"An error occurred: {e}")


if __name__ == "__main__":
    main()