agentscope-ai / agentscope-ai/agentscope

fix: handle empty env vars in config loading (XDG_*, MODELSCOPE_*)

Aperta Adatta ai principianti
#2,447 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
31.6k
Fork
3.5k
Merge medio
1g 16h
PR unite (30g)
103

Descrizione

### Description

Similar to gptme's dirs handling, AgentScope's config loading checks `if var in os.environ` but doesn't handle empty string values.

### Example

```python
# Current
if "XDG_DATA_HOME" in os.environ:
path = Path(os.environ["XDG_DATA_HOME"]) / "agentscope"

# If env var is set to empty string (common in Docker or shell misconfig):
# Path("") / "agentscope" -> "agentscope" (relative, wrong location)
```

### Affected vars

- `XDG_DATA_HOME`, `XDG_CONFIG_HOME`, `XDG_STATE_HOME`
- Any custom env vars for model paths
- `AGENTSCOPE_*_DIR` etc.

### Proposed fix

Introduce helper:

```python
def get_env_path(var: str) -> Path | None:
val = os.environ.get(var, "").strip()
return Path(val) if val else None
```

And use:

```python
if (env_path := get_env_path("XDG_DATA_HOME")) is not None:
...
```

### Why

Prevents bugs in containers where env vars may be set to empty string. Improves robustness.

### Checklist

- [x] Searched existing issues
- [x] Single focused fix
- [x] Will add tests

Can I PR this?

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start in the config-loading code path that checks `XDG_*` and `AGENTSCOPE_*` env vars as described in the issue. First read how those env values are currently read and then switch to a helper that trims and ignores empty/whitespace values before building paths. Add/extend tests for env loading behavior, run the config-related tests (or the full test suite if no dedicated one is listed), and mark done when empty env vars are treated as unset and valid paths still behave correctly.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Attiva
Chiarezza
Specificata chiaramente
Idoneità per principianti
78/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.