danhtran2mind commited on
Commit
75c5859
·
verified ·
1 Parent(s): ff0e0bd

Update scripts/setup_third_party.py

Browse files
Files changed (1) hide show
  1. scripts/setup_third_party.py +101 -74
scripts/setup_third_party.py CHANGED
@@ -1,75 +1,102 @@
1
- import os
2
- import shutil
3
- import subprocess
4
- import argparse
5
- import sys
6
-
7
- def clone_repository(repo_url, target_dir, branch="main"):
8
- """Clone a git repository to the specified directory with specific branch."""
9
- if os.path.exists(target_dir):
10
- print(f"Directory {target_dir} already exists. Skipping clone.")
11
- return
12
-
13
- os.makedirs(os.path.dirname(target_dir), exist_ok=True)
14
-
15
- try:
16
- subprocess.run(
17
- ["git", "clone", "-b", branch, repo_url, target_dir],
18
- check=True,
19
- capture_output=True,
20
- text=True
21
- )
22
- print(f"Successfully cloned {repo_url} (branch: {branch}) to {target_dir}")
23
- except subprocess.CalledProcessError as e:
24
- print(f"Failed to clone repository: {e.stderr}")
25
- sys.exit(1)
26
-
27
- def handle_remove_readonly(func, path, _):
28
- os.chmod(path, 0o666)
29
- func(path)
30
-
31
- def main(args):
32
- # Define target directories
33
- temp_f5_tts_target_dir = os.path.join("src", "danhtran2mind_f5_tts")
34
- bigvgan_target_dir = os.path.join("src", "third_party", "BigVGAN")
35
- f5_tts_target_dir = os.path.join("src", "f5_tts")
36
-
37
- # Clone F5-TTS repository
38
- clone_repository(args.f5_tts_url, temp_f5_tts_target_dir, args.f5_tts_branch)
39
-
40
- # Clone BigVGAN repository
41
- clone_repository(args.bigvgan_url, bigvgan_target_dir, args.bigvgan_branch)
42
-
43
- # Move the directory
44
- shutil.move(os.path.join(temp_f5_tts_target_dir, "src", "f5_tts"), f5_tts_target_dir)
45
- shutil.copytree(os.path.join(temp_f5_tts_target_dir, "data"), "./data", dirs_exist_ok=True)
46
- # Remove the parent directory
47
- # shutil.rmtree(temp_f5_tts_target_dir)
48
- shutil.rmtree(temp_f5_tts_target_dir, onerror=handle_remove_readonly)
49
-
50
- if __name__ == "__main__":
51
- parser = argparse.ArgumentParser(description="Clone F5-TTS and BigVGAN repositories")
52
- parser.add_argument(
53
- "--f5-tts-url",
54
- default="https://github.com/danhtran2mind/F5-TTS",
55
- help="URL for F5-TTS repository"
56
- )
57
- parser.add_argument(
58
- "--bigvgan-url",
59
- default="https://github.com/NVIDIA/BigVGAN",
60
- help="URL for BigVGAN repository"
61
- )
62
- parser.add_argument(
63
- "--f5-tts-branch",
64
- default="main",
65
- help="Branch for F5-TTS repository"
66
- )
67
- parser.add_argument(
68
- "--bigvgan-branch",
69
- # default="7d2b454564a6c7d014227f635b7423881f14bdac",
70
- default="main",
71
- help="Branch or commit for BigVGAN repository"
72
- )
73
-
74
- args = parser.parse_args()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  main(args)
 
1
+ import os
2
+ import shutil
3
+ import subprocess
4
+ import argparse
5
+ import sys
6
+
7
+ def install_editable_package():
8
+ """Install the f5-tts package in editable mode without dependencies."""
9
+ try:
10
+ subprocess.run(
11
+ [sys.executable, "-m", "pip", "install", "-e", ".", "--no-deps"],
12
+ check=True,
13
+ capture_output=True,
14
+ text=True
15
+ )
16
+ print("Successfully installed f5-tts package in editable mode")
17
+ except subprocess.CalledProcessError as e:
18
+ print(f"Failed to install f5-tts package: {e.stderr}")
19
+ sys.exit(1)
20
+
21
+ def clone_repository(repo_url, target_dir, branch="main"):
22
+ """Clone a git repository to the specified directory with specific branch."""
23
+ if os.path.exists(target_dir):
24
+ print(f"Directory {target_dir} already exists. Skipping clone.")
25
+ return
26
+
27
+ os.makedirs(os.path.dirname(target_dir), exist_ok=True)
28
+
29
+ try:
30
+ subprocess.run(
31
+ ["git", "clone", "-b", branch, repo_url, target_dir],
32
+ check=True,
33
+ capture_output=True,
34
+ text=True
35
+ )
36
+ print(f"Successfully cloned {repo_url} (branch: {branch}) to {target_dir}")
37
+ except subprocess.CalledProcessError as e:
38
+ print(f"Failed to clone repository: {e.stderr}")
39
+ sys.exit(1)
40
+
41
+ def handle_remove_readonly(func, path, _):
42
+ os.chmod(path, 0o666)
43
+ func(path)
44
+
45
+ def setup_python_path():
46
+ """Add the src directory to sys.path to allow module imports."""
47
+ src_dir = os.path.abspath("src")
48
+ if src_dir not in sys.path:
49
+ sys.path.insert(0, src_dir)
50
+ print(f"Added {src_dir} to sys.path")
51
+ else:
52
+ print(f"{src_dir} already in sys.path")
53
+
54
+ def main(args):
55
+ # Define target directories
56
+ temp_f5_tts_target_dir = os.path.join("src", "danhtran2mind_f5_tts")
57
+ bigvgan_target_dir = os.path.join("src", "third_party", "BigVGAN")
58
+ f5_tts_target_dir = os.path.join("src", "f5_tts")
59
+
60
+ # Clone F5-TTS repository
61
+ clone_repository(args.f5_tts_url, temp_f5_tts_target_dir, args.f5_tts_branch)
62
+
63
+ # Clone BigVGAN repository
64
+ clone_repository(args.bigvgan_url, bigvgan_target_dir, args.bigvgan_branch)
65
+
66
+ # Move the directory
67
+ shutil.move(os.path.join(temp_f5_tts_target_dir, "src", "f5_tts"), f5_tts_target_dir)
68
+ shutil.copytree(os.path.join(temp_f5_tts_target_dir, "data"), "./data", dirs_exist_ok=True)
69
+ # Remove the nested f5_tts directory
70
+ if os.path.exists(os.path.join(f5_tts_target_dir, "f5_tts")):
71
+ shutil.rmtree(os.path.join(f5_tts_target_dir, "f5_tts"), onerror=handle_remove_readonly)
72
+ # Remove the parent directory
73
+ shutil.rmtree(temp_f5_tts_target_dir, onerror=handle_remove_readonly)
74
+
75
+ # Set up Python path to include src directory
76
+ install_editable_package()
77
+
78
+ if __name__ == "__main__":
79
+ parser = argparse.ArgumentParser(description="Clone F5-TTS and BigVGAN repositories and set up Python path")
80
+ parser.add_argument(
81
+ "--f5-tts-url",
82
+ default="https://github.com/danhtran2mind/F5-TTS",
83
+ help="URL for F5-TTS repository"
84
+ )
85
+ parser.add_argument(
86
+ "--bigvgan-url",
87
+ default="https://github.com/NVIDIA/BigVGAN",
88
+ help="URL for BigVGAN repository"
89
+ )
90
+ parser.add_argument(
91
+ "--f5-tts-branch",
92
+ default="main",
93
+ help="Branch for F5-TTS repository"
94
+ )
95
+ parser.add_argument(
96
+ "--bigvgan-branch",
97
+ default="main",
98
+ help="Branch or commit for BigVGAN repository"
99
+ )
100
+
101
+ args = parser.parse_args()
102
  main(args)