hemantn commited on
Commit
db23db1
Β·
1 Parent(s): bd0d9fa

Improve utility file copying for Google Colab and other environments

Browse files
Files changed (1) hide show
  1. adapter.py +37 -25
adapter.py CHANGED
@@ -29,25 +29,43 @@ def ensure_utility_files_available():
29
  missing_files.append(file)
30
 
31
  if missing_files:
 
 
32
  # Try to find the repository root (where all utility files are)
33
  # Look for common parent directories that might contain the files
34
  possible_paths = [
35
  os.path.join(current_dir, '..'), # Parent directory
36
  os.path.join(current_dir, '..', '..'), # Grandparent directory
 
37
  os.path.join(os.path.expanduser('~'), 'ablang2'), # Home directory
38
  '/data/hn533621/ablang2', # Known repository location
 
 
39
  ]
40
 
 
 
 
 
 
 
 
41
  for path in possible_paths:
42
  if os.path.exists(path):
 
43
  # Check if all missing files exist in this path
44
  all_found = True
45
  for file in missing_files:
46
- if not os.path.exists(os.path.join(path, file)):
 
47
  all_found = False
 
48
  break
 
 
49
 
50
  if all_found:
 
51
  # Copy all missing files
52
  for file in missing_files:
53
  src = os.path.join(path, file)
@@ -57,36 +75,30 @@ def ensure_utility_files_available():
57
  return True
58
 
59
  # If we get here, we couldn't find the files
60
- raise FileNotFoundError(
61
- f"Missing utility files: {missing_files}. "
62
- "These files are required for the adapter to work. "
63
- "Please ensure the repository is properly set up."
64
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  return True
67
 
68
  # Ensure utility files are available before importing
69
  ensure_utility_files_available()
70
 
71
- # Copy utility files to the current directory if they don't exist
72
- for file in UTILITY_FILES:
73
- src = os.path.join(current_dir, file)
74
- if not os.path.exists(src):
75
- # Try to find the file in possible source locations
76
- possible_paths = [
77
- os.path.join(current_dir, '..'), # Parent directory
78
- os.path.join(current_dir, '..', '..'), # Grandparent directory
79
- os.path.join(os.path.expanduser('~'), 'ablang2'), # Home directory
80
- '/data/hn533621/ablang2', # Known repository location
81
- ]
82
-
83
- for path in possible_paths:
84
- potential_src = os.path.join(path, file)
85
- if os.path.exists(potential_src):
86
- shutil.copy2(potential_src, src)
87
- print(f"βœ… Copied {file} to current directory")
88
- break
89
-
90
  # Debug: Check what files are in the current directory
91
  print(f"πŸ“ Files in current directory ({current_dir}):")
92
  for f in os.listdir(current_dir):
 
29
  missing_files.append(file)
30
 
31
  if missing_files:
32
+ print(f"πŸ” Looking for missing utility files: {missing_files}")
33
+
34
  # Try to find the repository root (where all utility files are)
35
  # Look for common parent directories that might contain the files
36
  possible_paths = [
37
  os.path.join(current_dir, '..'), # Parent directory
38
  os.path.join(current_dir, '..', '..'), # Grandparent directory
39
+ os.path.join(current_dir, '..', '..', '..'), # Great-grandparent directory
40
  os.path.join(os.path.expanduser('~'), 'ablang2'), # Home directory
41
  '/data/hn533621/ablang2', # Known repository location
42
+ '/content/ablang2', # Google Colab common location
43
+ '/tmp/ablang2', # Temporary directory
44
  ]
45
 
46
+ # Also try to find files in the Hugging Face cache structure
47
+ cache_dir = os.path.dirname(current_dir)
48
+ if 'huggingface' in cache_dir:
49
+ # Look in the repository root within the cache
50
+ repo_root = os.path.join(cache_dir, '..', '..', '..', '..')
51
+ possible_paths.append(repo_root)
52
+
53
  for path in possible_paths:
54
  if os.path.exists(path):
55
+ print(f"πŸ” Checking path: {path}")
56
  # Check if all missing files exist in this path
57
  all_found = True
58
  for file in missing_files:
59
+ file_path = os.path.join(path, file)
60
+ if not os.path.exists(file_path):
61
  all_found = False
62
+ print(f" ❌ Missing: {file}")
63
  break
64
+ else:
65
+ print(f" βœ… Found: {file}")
66
 
67
  if all_found:
68
+ print(f"🎯 Found all files in: {path}")
69
  # Copy all missing files
70
  for file in missing_files:
71
  src = os.path.join(path, file)
 
75
  return True
76
 
77
  # If we get here, we couldn't find the files
78
+ print(f"❌ Could not find utility files in any of the searched paths:")
79
+ for path in possible_paths:
80
+ print(f" - {path}")
81
+
82
+ # For Colab environments, provide a helpful error message
83
+ if 'google.colab' in str(sys.modules):
84
+ raise FileNotFoundError(
85
+ f"Missing utility files: {missing_files}. "
86
+ "This appears to be a Google Colab environment. "
87
+ "Please ensure you have cloned the repository and the utility files are available. "
88
+ "Try running: !git clone https://huggingface.co/hemantn/ablang2"
89
+ )
90
+ else:
91
+ raise FileNotFoundError(
92
+ f"Missing utility files: {missing_files}. "
93
+ "These files are required for the adapter to work. "
94
+ "Please ensure the repository is properly set up."
95
+ )
96
 
97
  return True
98
 
99
  # Ensure utility files are available before importing
100
  ensure_utility_files_available()
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  # Debug: Check what files are in the current directory
103
  print(f"πŸ“ Files in current directory ({current_dir}):")
104
  for f in os.listdir(current_dir):