gitarsenal-cli 1.1.20 ā 1.1.21
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
@@ -9,6 +9,7 @@ import os
|
|
9
9
|
import sys
|
10
10
|
import json
|
11
11
|
import requests
|
12
|
+
import subprocess
|
12
13
|
from pathlib import Path
|
13
14
|
|
14
15
|
# Default tokens to use if we can't fetch from the server
|
@@ -29,17 +30,23 @@ def fetch_tokens_from_proxy(proxy_url=None, api_key=None):
|
|
29
30
|
# Use environment variables if not provided
|
30
31
|
if not proxy_url:
|
31
32
|
proxy_url = os.environ.get("MODAL_PROXY_URL")
|
33
|
+
if proxy_url:
|
34
|
+
print(f"š Using proxy URL from environment: {proxy_url}")
|
32
35
|
|
33
36
|
if not api_key:
|
34
37
|
api_key = os.environ.get("MODAL_PROXY_API_KEY")
|
38
|
+
if api_key:
|
39
|
+
print(f"š Using API key from environment (length: {len(api_key)})")
|
35
40
|
|
36
41
|
# Check if we have the necessary information
|
37
42
|
if not proxy_url:
|
38
43
|
print("ā No proxy URL provided or found in environment")
|
44
|
+
print("š” Set MODAL_PROXY_URL environment variable or use --proxy-url argument")
|
39
45
|
return None, None
|
40
46
|
|
41
47
|
if not api_key:
|
42
48
|
print("ā No API key provided or found in environment")
|
49
|
+
print("š” Set MODAL_PROXY_API_KEY environment variable or use --proxy-api-key argument")
|
43
50
|
return None, None
|
44
51
|
|
45
52
|
# Ensure the URL ends with a slash
|
@@ -79,6 +86,7 @@ def fetch_tokens_from_proxy(proxy_url=None, api_key=None):
|
|
79
86
|
def get_tokens():
|
80
87
|
"""
|
81
88
|
Get Modal tokens, trying to fetch from the proxy server first.
|
89
|
+
Also sets the tokens in environment variables.
|
82
90
|
|
83
91
|
Returns:
|
84
92
|
tuple: (token_id, token_secret)
|
@@ -89,15 +97,48 @@ def get_tokens():
|
|
89
97
|
# If we couldn't fetch from the server, use the default tokens
|
90
98
|
if not token_id or not token_secret:
|
91
99
|
print("ā ļø Using default tokens")
|
92
|
-
|
100
|
+
token_id = DEFAULT_TOKEN_ID
|
101
|
+
token_secret = DEFAULT_TOKEN_SECRET
|
102
|
+
|
103
|
+
# Set the tokens in environment variables
|
104
|
+
os.environ["MODAL_TOKEN_ID"] = token_id
|
105
|
+
os.environ["MODAL_TOKEN_SECRET"] = token_secret
|
106
|
+
print(f"ā
Set MODAL_TOKEN_ID and MODAL_TOKEN_SECRET environment variables")
|
93
107
|
|
94
108
|
return token_id, token_secret
|
95
109
|
|
96
110
|
if __name__ == "__main__":
|
111
|
+
# Parse command-line arguments if run directly
|
112
|
+
import argparse
|
113
|
+
|
114
|
+
parser = argparse.ArgumentParser(description='Fetch Modal tokens from the proxy server')
|
115
|
+
parser.add_argument('--proxy-url', help='URL of the proxy server')
|
116
|
+
parser.add_argument('--proxy-api-key', help='API key for the proxy server')
|
117
|
+
args = parser.parse_args()
|
118
|
+
|
119
|
+
# Set proxy URL and API key in environment variables if provided
|
120
|
+
if args.proxy_url:
|
121
|
+
os.environ["MODAL_PROXY_URL"] = args.proxy_url
|
122
|
+
print(f"ā
Set MODAL_PROXY_URL from command line: {args.proxy_url}")
|
123
|
+
|
124
|
+
if args.proxy_api_key:
|
125
|
+
os.environ["MODAL_PROXY_API_KEY"] = args.proxy_api_key
|
126
|
+
print(f"ā
Set MODAL_PROXY_API_KEY from command line")
|
127
|
+
|
128
|
+
# Get tokens
|
97
129
|
token_id, token_secret = get_tokens()
|
98
130
|
print(f"Token ID: {token_id}")
|
99
131
|
print(f"Token Secret: {token_secret}")
|
100
132
|
|
133
|
+
# Check if tokens are set in environment variables
|
134
|
+
print(f"\nš DEBUG: Checking environment variables")
|
135
|
+
print(f"š MODAL_TOKEN_ID exists: {'Yes' if os.environ.get('MODAL_TOKEN_ID') else 'No'}")
|
136
|
+
print(f"š MODAL_TOKEN_SECRET exists: {'Yes' if os.environ.get('MODAL_TOKEN_SECRET') else 'No'}")
|
137
|
+
if os.environ.get('MODAL_TOKEN_ID'):
|
138
|
+
print(f"š MODAL_TOKEN_ID length: {len(os.environ.get('MODAL_TOKEN_ID'))}")
|
139
|
+
if os.environ.get('MODAL_TOKEN_SECRET'):
|
140
|
+
print(f"š MODAL_TOKEN_SECRET length: {len(os.environ.get('MODAL_TOKEN_SECRET'))}")
|
141
|
+
|
101
142
|
# Write the tokens to a file for use by other scripts
|
102
143
|
tokens_file = Path(__file__).parent / "modal_tokens.json"
|
103
144
|
with open(tokens_file, 'w') as f:
|
@@ -105,4 +146,38 @@ if __name__ == "__main__":
|
|
105
146
|
"token_id": token_id,
|
106
147
|
"token_secret": token_secret
|
107
148
|
}, f)
|
108
|
-
print(f"ā
Tokens written to {tokens_file}")
|
149
|
+
print(f"\nā
Tokens written to {tokens_file}")
|
150
|
+
|
151
|
+
# Create token files in standard locations
|
152
|
+
modal_dir = Path.home() / ".modal"
|
153
|
+
modal_dir.mkdir(exist_ok=True)
|
154
|
+
token_file = modal_dir / "token.json"
|
155
|
+
with open(token_file, 'w') as f:
|
156
|
+
json.dump({
|
157
|
+
"token_id": token_id,
|
158
|
+
"token_secret": token_secret
|
159
|
+
}, f)
|
160
|
+
print(f"ā
Created token file at {token_file}")
|
161
|
+
|
162
|
+
modalconfig_file = Path.home() / ".modalconfig"
|
163
|
+
with open(modalconfig_file, 'w') as f:
|
164
|
+
f.write(f"token_id = {token_id}\n")
|
165
|
+
f.write(f"token_secret = {token_secret}\n")
|
166
|
+
print(f"ā
Created .modalconfig file at {modalconfig_file}")
|
167
|
+
|
168
|
+
# Try to use the Modal CLI to set the token
|
169
|
+
try:
|
170
|
+
print(f"\nš Setting token via Modal CLI...")
|
171
|
+
result = subprocess.run(
|
172
|
+
["modal", "token", "set", "--token-id", token_id, "--token-secret", token_secret, "--profile=fr8mafia", "--no-verify"],
|
173
|
+
capture_output=True, text=True
|
174
|
+
)
|
175
|
+
|
176
|
+
if result.returncode == 0:
|
177
|
+
print(f"ā
Successfully set token via Modal CLI")
|
178
|
+
else:
|
179
|
+
print(f"ā Failed to set token via Modal CLI: {result.stderr}")
|
180
|
+
except Exception as e:
|
181
|
+
print(f"ā Error using Modal CLI: {e}")
|
182
|
+
|
183
|
+
print(f"\nā
All token setup completed successfully")
|
@@ -9,8 +9,30 @@ import getpass
|
|
9
9
|
import requests
|
10
10
|
import secrets
|
11
11
|
import string
|
12
|
+
import argparse
|
12
13
|
from pathlib import Path
|
13
14
|
|
15
|
+
# Parse command-line arguments
|
16
|
+
parser = argparse.ArgumentParser(description='Launch a Modal sandbox')
|
17
|
+
parser.add_argument('--proxy-url', help='URL of the proxy server')
|
18
|
+
parser.add_argument('--proxy-api-key', help='API key for the proxy server')
|
19
|
+
parser.add_argument('--gpu', default='A10G', help='GPU type to use')
|
20
|
+
parser.add_argument('--repo-url', help='Repository URL')
|
21
|
+
parser.add_argument('--volume-name', help='Volume name')
|
22
|
+
parser.add_argument('--use-api', action='store_true', help='Use API to fetch setup commands')
|
23
|
+
|
24
|
+
# Parse only known args to avoid conflicts with other arguments
|
25
|
+
args, unknown = parser.parse_known_args()
|
26
|
+
|
27
|
+
# Set proxy URL and API key in environment variables if provided
|
28
|
+
if args.proxy_url:
|
29
|
+
os.environ["MODAL_PROXY_URL"] = args.proxy_url
|
30
|
+
print(f"ā
Set MODAL_PROXY_URL from command line: {args.proxy_url}")
|
31
|
+
|
32
|
+
if args.proxy_api_key:
|
33
|
+
os.environ["MODAL_PROXY_API_KEY"] = args.proxy_api_key
|
34
|
+
print(f"ā
Set MODAL_PROXY_API_KEY from command line")
|
35
|
+
|
14
36
|
# First, try to fetch tokens from the proxy server
|
15
37
|
try:
|
16
38
|
# Import the fetch_modal_tokens module
|
@@ -19,6 +41,13 @@ try:
|
|
19
41
|
token_id, token_secret = get_tokens()
|
20
42
|
print(f"ā
Modal tokens fetched successfully")
|
21
43
|
|
44
|
+
# Explicitly set the environment variables again to be sure
|
45
|
+
os.environ["MODAL_TOKEN_ID"] = token_id
|
46
|
+
os.environ["MODAL_TOKEN_SECRET"] = token_secret
|
47
|
+
|
48
|
+
# Also set the old environment variable for backward compatibility
|
49
|
+
os.environ["MODAL_TOKEN"] = token_id
|
50
|
+
|
22
51
|
# Set token variables for later use
|
23
52
|
token = token_id # For backward compatibility
|
24
53
|
except Exception as e:
|
@@ -77,9 +106,12 @@ except Exception as e:
|
|
77
106
|
# Print debug info
|
78
107
|
print(f"š DEBUG: Checking environment variables")
|
79
108
|
print(f"š MODAL_TOKEN_ID exists: {'Yes' if os.environ.get('MODAL_TOKEN_ID') else 'No'}")
|
109
|
+
print(f"š MODAL_TOKEN_SECRET exists: {'Yes' if os.environ.get('MODAL_TOKEN_SECRET') else 'No'}")
|
80
110
|
print(f"š MODAL_TOKEN exists: {'Yes' if os.environ.get('MODAL_TOKEN') else 'No'}")
|
81
111
|
if os.environ.get('MODAL_TOKEN_ID'):
|
82
112
|
print(f"š MODAL_TOKEN_ID length: {len(os.environ.get('MODAL_TOKEN_ID'))}")
|
113
|
+
if os.environ.get('MODAL_TOKEN_SECRET'):
|
114
|
+
print(f"š MODAL_TOKEN_SECRET length: {len(os.environ.get('MODAL_TOKEN_SECRET'))}")
|
83
115
|
if os.environ.get('MODAL_TOKEN'):
|
84
116
|
print(f"š MODAL_TOKEN length: {len(os.environ.get('MODAL_TOKEN'))}")
|
85
117
|
print(f"ā
Modal token setup completed")
|