mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2026-04-20 22:13:43 +00:00
Follow-up to e2548f69: add missing paths module, fix gallery extension
This commit is contained in:
parent
8d43123f73
commit
ddcad3cc51
2 changed files with 31 additions and 2 deletions
28
modules/paths.py
Normal file
28
modules/paths.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def resolve_user_data_dir():
|
||||
"""
|
||||
Resolve the user_data directory path. Order of precedence:
|
||||
1. --user-data-dir CLI flag (pre-parsed from sys.argv before argparse)
|
||||
2. Auto-detect: if ./user_data doesn't exist but ../user_data does, use ../user_data
|
||||
3. Default: 'user_data'
|
||||
"""
|
||||
script_dir = Path(__file__).resolve().parent.parent
|
||||
|
||||
# Check sys.argv for --user-data-dir before argparse runs
|
||||
for i, arg in enumerate(sys.argv):
|
||||
if arg == '--user-data-dir' and i + 1 < len(sys.argv):
|
||||
return Path(sys.argv[i + 1])
|
||||
elif arg.startswith('--user-data-dir='):
|
||||
return Path(arg.split('=', 1)[1])
|
||||
|
||||
# Auto-detect: check if user_data exists locally vs one folder up
|
||||
local_path = script_dir / 'user_data'
|
||||
parent_path = script_dir.parent / 'user_data'
|
||||
|
||||
if not local_path.exists() and parent_path.exists():
|
||||
return parent_path
|
||||
|
||||
return Path('user_data')
|
||||
Loading…
Add table
Add a link
Reference in a new issue