Skip to content

Commit 9341632

Browse files
fix(jh): honour JULIA_DEPOT_PATH rather than .julia (#16)
* honour JULIA_DePOT_PATH rather than .julia * added reusable get julia depot path func * refactor
1 parent 2a07770 commit 9341632

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

CLAUDE.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ The CLI provides Julia installation and execution with JuliaHub configuration:
224224
- Installs latest stable Julia version
225225

226226
### Julia Credentials
227-
- **Authentication file**: Automatically creates `~/.julia/servers/<server>/auth.toml`
227+
- **Authentication file**: Automatically creates `$JULIA_DEPOT_PATH/servers/<server>/auth.toml` (or `~/.julia/servers/<server>/auth.toml` if `JULIA_DEPOT_PATH` is not set)
228+
- **Depot path detection**: Respects `JULIA_DEPOT_PATH` environment variable, uses first path if multiple are specified
228229
- **Atomic writes**: Uses temporary file + rename for safe credential updates
229230
- **Automatic updates**: Credentials are automatically refreshed when:
230231
- User runs `jh auth login`
@@ -252,7 +253,7 @@ jh run -- --project=. --threads=4 script.jl # Run with flags
252253
```bash
253254
jh run setup
254255
```
255-
- Creates/updates `~/.julia/servers/<server>/auth.toml` with current credentials
256+
- Creates/updates `$JULIA_DEPOT_PATH/servers/<server>/auth.toml` with current credentials (or `~/.julia/servers/<server>/auth.toml` if not set)
256257
- Does not start Julia
257258
- Useful for explicitly updating credentials
258259

@@ -265,6 +266,7 @@ jh run setup
265266
- File uploads use multipart form data with proper content types
266267
- Julia auth files use TOML format with `preferred_username` from JWT claims
267268
- Julia auth files use atomic writes (temp file + rename) to prevent corruption
269+
- Julia credentials respect `JULIA_DEPOT_PATH` environment variable (uses first path if multiple are specified)
268270
- Julia credentials are automatically updated after login and token refresh
269271
- Git commands use `http.extraHeader` for authentication and pass through all arguments
270272
- Git credential helper provides seamless authentication for standard Git commands
@@ -281,7 +283,9 @@ jh run setup
281283
The Julia credentials system consists of three main functions:
282284

283285
1. **`createJuliaAuthFile(server, token)`**:
284-
- Creates `~/.julia/servers/<server>/auth.toml` with TOML-formatted credentials
286+
- Determines depot path from `JULIA_DEPOT_PATH` environment variable (uses first path if multiple)
287+
- Falls back to `~/.julia` if `JULIA_DEPOT_PATH` is not set
288+
- Creates `{depot}/servers/<server>/auth.toml` with TOML-formatted credentials
285289
- Uses atomic writes: writes to temporary file, syncs, then renames
286290
- Includes all necessary fields: tokens, expiration, refresh URL, user info
287291
- Called by `setupJuliaCredentials()` and `updateJuliaCredentialsIfNeeded()`
@@ -306,7 +310,8 @@ The Julia credentials system consists of three main functions:
306310

307311
The `updateJuliaCredentialsIfNeeded(server, token)` function:
308312
- Called automatically by `ensureValidToken()` after token refresh
309-
- Checks if `~/.julia/servers/<server>/auth.toml` exists
313+
- Determines depot path from `JULIA_DEPOT_PATH` (same logic as `createJuliaAuthFile`)
314+
- Checks if `{depot}/servers/<server>/auth.toml` exists
310315
- If exists, updates it with refreshed token
311316
- If not exists, does nothing (user hasn't used Julia integration yet)
312317
- Errors are silently ignored to avoid breaking token operations

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ jh run -- --project=. --threads=4 script.jl
270270
```
271271

272272
Note: Arguments after `--` are passed directly to Julia. The `jh run` command:
273-
1. Sets up JuliaHub credentials in `~/.julia/servers/<server>/auth.toml`
273+
1. Sets up JuliaHub credentials in `$JULIA_DEPOT_PATH/servers/<server>/auth.toml` (or `~/.julia/servers/<server>/auth.toml` if `JULIA_DEPOT_PATH` is not set)
274274
2. Configures `JULIA_PKG_SERVER` environment variable
275275
3. Starts Julia with your specified arguments
276276

auth.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,14 @@ func ensureValidToken() (*StoredToken, error) {
339339
// updateJuliaCredentialsIfNeeded updates Julia credentials if the auth file exists
340340
// This is called after token refresh to keep credentials in sync
341341
func updateJuliaCredentialsIfNeeded(server string, token *StoredToken) error {
342-
homeDir, err := os.UserHomeDir()
342+
// Determine Julia depot path
343+
depotPath, err := getJuliaDepotPath()
343344
if err != nil {
344345
return err
345346
}
346347

347348
// Check if the auth.toml file exists
348-
authFilePath := filepath.Join(homeDir, ".julia", "servers", server, "auth.toml")
349+
authFilePath := filepath.Join(depotPath, "servers", server, "auth.toml")
349350
if _, err := os.Stat(authFilePath); os.IsNotExist(err) {
350351
// File doesn't exist, so user hasn't used Julia integration yet
351352
return nil

run.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,36 @@ import (
77
"path/filepath"
88
)
99

10+
func getJuliaDepotPath() (string, error) {
11+
var depotPath string
12+
if juliaDepot := os.Getenv("JULIA_DEPOT_PATH"); juliaDepot != "" {
13+
// Use first path from JULIA_DEPOT_PATH (paths are separated by : on Unix, ; on Windows)
14+
depotPaths := filepath.SplitList(juliaDepot)
15+
if len(depotPaths) > 0 {
16+
depotPath = depotPaths[0]
17+
}
18+
}
19+
20+
// Fall back to ~/.julia if JULIA_DEPOT_PATH is not set
21+
if depotPath == "" {
22+
homeDir, err := os.UserHomeDir()
23+
if err != nil {
24+
return "", fmt.Errorf("failed to get user home directory: %w", err)
25+
}
26+
depotPath = filepath.Join(homeDir, ".julia")
27+
}
28+
29+
return depotPath, nil
30+
}
31+
1032
func createJuliaAuthFile(server string, token *StoredToken) error {
11-
// Get user home directory
12-
homeDir, err := os.UserHomeDir()
33+
depotPath, err := getJuliaDepotPath()
1334
if err != nil {
14-
return fmt.Errorf("failed to get user home directory: %w", err)
35+
return err
1536
}
1637

17-
// Create ~/.julia/servers/{server}/ directory
18-
serverDir := filepath.Join(homeDir, ".julia", "servers", server)
38+
// Create {depot}/servers/{server}/ directory
39+
serverDir := filepath.Join(depotPath, "servers", server)
1940
if err := os.MkdirAll(serverDir, 0755); err != nil {
2041
return fmt.Errorf("failed to create server directory: %w", err)
2142
}

0 commit comments

Comments
 (0)