84 lines
3.2 KiB
Batchfile
84 lines
3.2 KiB
Batchfile
@echo off
|
|
rem ai-chat-exporter.cmd - run the exporter without activating a virtualenv.
|
|
rem
|
|
rem Command Prompt (cmd.exe) - the documented way:
|
|
rem cd C:\path\to\AIChatExporter
|
|
rem ai-chat-exporter export --provider all
|
|
rem
|
|
rem cmd.exe searches the current directory before PATH and resolves the bare
|
|
rem name through PATHEXT (which includes .CMD), so no ".\" and no extension are
|
|
rem needed. The extensionless POSIX sibling is ignored: it is not in PATHEXT.
|
|
rem
|
|
rem PowerShell does NOT search the current directory, and ".\ai-chat-exporter"
|
|
rem there would resolve to the extensionless POSIX script, which PowerShell
|
|
rem cannot run. In PowerShell, name this file explicitly:
|
|
rem .\ai-chat-exporter.cmd export --provider all
|
|
rem
|
|
rem Creates .venv and installs dependencies on first run, so a fresh clone needs
|
|
rem no "python -m venv" / ".venv\Scripts\activate" ceremony. Reinstalls
|
|
rem automatically when pyproject.toml changes.
|
|
rem
|
|
rem The working directory is deliberately NOT changed - EXPORT_DIR, CACHE_DIR
|
|
rem and .env discovery are all relative to it. POSIX equivalent: ai-chat-exporter
|
|
|
|
setlocal enabledelayedexpansion
|
|
|
|
set "DIR=%~dp0"
|
|
if "%DIR:~-1%"=="\" set "DIR=%DIR:~0,-1%"
|
|
set "VENV=%DIR%\.venv"
|
|
set "PY=%VENV%\Scripts\python.exe"
|
|
set "STAMP=%VENV%\.deps-stamp"
|
|
|
|
rem See the POSIX script for why this warns rather than blocks: cache\ resolves
|
|
rem against the current directory, so the wrong one silently starts a second
|
|
rem archive instead of failing.
|
|
if /i not "%CD%"=="%DIR%" if "%AI_CHAT_EXPORTER_QUIET_CWD%"=="" (
|
|
echo warning: running from %CD%, not %DIR% 1>&2
|
|
echo cache\ and exports\ resolve against the current directory, 1>&2
|
|
echo so this may start a separate archive. Set 1>&2
|
|
echo AI_CHAT_EXPORTER_QUIET_CWD=1 to silence this. 1>&2
|
|
)
|
|
|
|
if not exist "%PY%" (
|
|
echo Creating virtualenv in %VENV% ... 1>&2
|
|
rem The py launcher is the reliable way to get a specific version; fall back
|
|
rem to whatever "python" is if it is not installed.
|
|
where py >nul 2>&1
|
|
if !errorlevel! equ 0 (
|
|
py -3 -m venv "%VENV%"
|
|
) else (
|
|
python -m venv "%VENV%"
|
|
)
|
|
if not exist "%PY%" (
|
|
echo error: could not create a virtualenv - install Python 3.11+ from 1>&2
|
|
echo python.org or the Microsoft Store, then re-run. 1>&2
|
|
exit /b 1
|
|
)
|
|
if exist "%STAMP%" del "%STAMP%"
|
|
)
|
|
|
|
rem Staleness check, in pure batch: %%~tF is the file's last-modified stamp, so
|
|
rem storing it and comparing strings needs no external process. The obvious
|
|
rem alternative - asking PowerShell to compare timestamps - costs ~1s of
|
|
rem interpreter startup on *every* command, which is a lot to pay to almost
|
|
rem always learn that nothing changed.
|
|
set "PYPROJ_TIME="
|
|
for %%F in ("%DIR%\pyproject.toml") do set "PYPROJ_TIME=%%~tF"
|
|
|
|
set "SAVED_TIME="
|
|
if exist "%STAMP%" set /p SAVED_TIME=<"%STAMP%"
|
|
|
|
if not "%SAVED_TIME%"=="%PYPROJ_TIME%" (
|
|
echo Installing dependencies ... 1>&2
|
|
"%PY%" -m pip install --quiet --upgrade pip
|
|
"%PY%" -m pip install --quiet -e "%DIR%"
|
|
if !errorlevel! neq 0 (
|
|
echo error: dependency installation failed. 1>&2
|
|
exit /b !errorlevel!
|
|
)
|
|
> "%STAMP%" echo !PYPROJ_TIME!
|
|
)
|
|
|
|
"%PY%" -m src.main %*
|
|
exit /b %errorlevel%
|