gitarsenal-cli 1.1.8 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitarsenal-cli",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "CLI tool for creating Modal sandboxes with GitHub repositories",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -211,6 +211,7 @@ def create_ssh_container():
211
211
  try:
212
212
  # Set the token directly in environment
213
213
  os.environ["MODAL_TOKEN_ID"] = MODAL_TOKEN
214
+ os.environ["MODAL_TOKEN"] = MODAL_TOKEN
214
215
  logger.info(f"Set MODAL_TOKEN_ID in environment (length: {len(MODAL_TOKEN)})")
215
216
 
216
217
  # Try to set token via CLI as well
@@ -256,8 +257,29 @@ def create_ssh_container():
256
257
  try:
257
258
  # Set token in environment for this thread
258
259
  os.environ["MODAL_TOKEN_ID"] = MODAL_TOKEN
260
+ os.environ["MODAL_TOKEN"] = MODAL_TOKEN
259
261
  logger.info(f"Set MODAL_TOKEN_ID in thread (length: {len(MODAL_TOKEN)})")
260
262
 
263
+ # Create a copy of the environment variables for the container creation
264
+ env_copy = os.environ.copy()
265
+ env_copy["MODAL_TOKEN_ID"] = MODAL_TOKEN
266
+ env_copy["MODAL_TOKEN"] = MODAL_TOKEN
267
+
268
+ # Try to set token via CLI again in this thread
269
+ try:
270
+ import subprocess
271
+ subprocess.run(
272
+ ["modal", "token", "set", MODAL_TOKEN],
273
+ capture_output=True, text=True, check=False
274
+ )
275
+ logger.info("Set Modal token via CLI in thread")
276
+ except Exception as e:
277
+ logger.warning(f"Failed to set token via CLI in thread: {e}")
278
+
279
+ # Explicitly print token status for debugging
280
+ logger.info(f"MODAL_TOKEN_ID in thread env: {os.environ.get('MODAL_TOKEN_ID')}")
281
+ logger.info(f"MODAL_TOKEN in thread env: {os.environ.get('MODAL_TOKEN')}")
282
+
261
283
  result = create_modal_ssh_container(
262
284
  gpu_type,
263
285
  repo_url=repo_url,
@@ -2069,26 +2069,40 @@ def create_modal_ssh_container(gpu_type, repo_url=None, repo_name=None, setup_co
2069
2069
 
2070
2070
  # Check if Modal is authenticated
2071
2071
  try:
2072
+ # Print all environment variables for debugging
2073
+ print("🔍 DEBUG: Checking environment variables")
2074
+ modal_token_id = os.environ.get("MODAL_TOKEN_ID")
2075
+ modal_token = os.environ.get("MODAL_TOKEN")
2076
+ print(f"🔍 MODAL_TOKEN_ID exists: {'Yes' if modal_token_id else 'No'}")
2077
+ print(f"🔍 MODAL_TOKEN exists: {'Yes' if modal_token else 'No'}")
2078
+ if modal_token_id:
2079
+ print(f"🔍 MODAL_TOKEN_ID length: {len(modal_token_id)}")
2080
+ if modal_token:
2081
+ print(f"🔍 MODAL_TOKEN length: {len(modal_token)}")
2082
+
2072
2083
  # Try to access Modal token to check authentication
2073
2084
  try:
2074
2085
  # Check if token is set in environment
2075
- modal_token = os.environ.get("MODAL_TOKEN_ID")
2076
- if not modal_token:
2086
+ modal_token_id = os.environ.get("MODAL_TOKEN_ID")
2087
+ if not modal_token_id:
2077
2088
  print("⚠️ MODAL_TOKEN_ID not found in environment.")
2078
2089
  # Try to get from MODAL_TOKEN
2079
2090
  modal_token = os.environ.get("MODAL_TOKEN")
2080
2091
  if modal_token:
2081
2092
  print("✅ Found token in MODAL_TOKEN environment variable")
2082
2093
  os.environ["MODAL_TOKEN_ID"] = modal_token
2094
+ modal_token_id = modal_token
2095
+ print(f"✅ Set MODAL_TOKEN_ID from MODAL_TOKEN (length: {len(modal_token)})")
2083
2096
 
2084
- if modal_token:
2085
- print(f"✅ Modal token found (length: {len(modal_token)})")
2097
+ if modal_token_id:
2098
+ print(f"✅ Modal token found (length: {len(modal_token_id)})")
2086
2099
 
2087
2100
  # Use the Modal CLI to set the token
2088
2101
  try:
2089
2102
  import subprocess
2103
+ print(f"🔄 Setting token via Modal CLI (token length: {len(modal_token_id)})")
2090
2104
  result = subprocess.run(
2091
- ["modal", "token", "set", modal_token],
2105
+ ["modal", "token", "set", modal_token_id],
2092
2106
  capture_output=True, text=True
2093
2107
  )
2094
2108
  if result.returncode == 0:
@@ -2099,20 +2113,51 @@ def create_modal_ssh_container(gpu_type, repo_url=None, repo_name=None, setup_co
2099
2113
  print(f"⚠️ Error setting token via CLI: {e}")
2100
2114
  else:
2101
2115
  print("❌ No Modal token found in environment variables")
2102
- return None
2116
+ # Try to get from file as a last resort
2117
+ try:
2118
+ home_dir = os.path.expanduser("~")
2119
+ modal_dir = os.path.join(home_dir, ".modal")
2120
+ token_file = os.path.join(modal_dir, "token.json")
2121
+ if os.path.exists(token_file):
2122
+ print(f"🔍 Found Modal token file at {token_file}")
2123
+ with open(token_file, 'r') as f:
2124
+ import json
2125
+ token_data = json.load(f)
2126
+ if "token_id" in token_data:
2127
+ modal_token_id = token_data["token_id"]
2128
+ os.environ["MODAL_TOKEN_ID"] = modal_token_id
2129
+ os.environ["MODAL_TOKEN"] = modal_token_id
2130
+ print(f"✅ Loaded token from file (length: {len(modal_token_id)})")
2131
+ else:
2132
+ print("❌ Token file does not contain token_id")
2133
+ else:
2134
+ print("❌ Modal token file not found")
2135
+ except Exception as e:
2136
+ print(f"❌ Error loading token from file: {e}")
2137
+
2138
+ if not os.environ.get("MODAL_TOKEN_ID"):
2139
+ print("❌ Could not find Modal token in any location")
2140
+ return None
2103
2141
 
2104
2142
  except Exception as e:
2105
2143
  print(f"⚠️ Error checking Modal token: {e}")
2106
2144
  # Try to use the token from environment
2107
- modal_token = os.environ.get("MODAL_TOKEN_ID") or os.environ.get("MODAL_TOKEN")
2108
- if not modal_token:
2145
+ modal_token_id = os.environ.get("MODAL_TOKEN_ID")
2146
+ modal_token = os.environ.get("MODAL_TOKEN")
2147
+ if modal_token_id:
2148
+ print(f"🔄 Using MODAL_TOKEN_ID from environment (length: {len(modal_token_id)})")
2149
+ elif modal_token:
2150
+ print(f"🔄 Using MODAL_TOKEN from environment (length: {len(modal_token)})")
2151
+ os.environ["MODAL_TOKEN_ID"] = modal_token
2152
+ modal_token_id = modal_token
2153
+ else:
2109
2154
  print("❌ No Modal token available. Cannot proceed.")
2110
2155
  return None
2111
2156
 
2112
- print(f"🔄 Using Modal token from environment (length: {len(modal_token)})")
2113
2157
  # Set it in both environment variables
2114
- os.environ["MODAL_TOKEN_ID"] = modal_token
2115
- os.environ["MODAL_TOKEN"] = modal_token
2158
+ os.environ["MODAL_TOKEN_ID"] = modal_token_id
2159
+ os.environ["MODAL_TOKEN"] = modal_token_id
2160
+ print("✅ Set both MODAL_TOKEN_ID and MODAL_TOKEN environment variables")
2116
2161
  except Exception as e:
2117
2162
  print(f"⚠️ Error checking Modal authentication: {e}")
2118
2163
  print("Continuing anyway, but Modal operations may fail")