Start: Add check for uv
Uv is the definitive package installation tool for Python, so add support to check for it via the start script. Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
This commit is contained in:
parent
30a3cd75cf
commit
1f4186512e
3 changed files with 46 additions and 4 deletions
16
start.bat
16
start.bat
|
|
@ -5,13 +5,27 @@
|
||||||
|
|
||||||
cd "%~dp0"
|
cd "%~dp0"
|
||||||
|
|
||||||
|
where uv >nul 2>&1
|
||||||
|
if %errorlevel% equ 0 (
|
||||||
|
echo "HAS UV"
|
||||||
|
set HAS_UV=1
|
||||||
|
) else (
|
||||||
|
set HAS_UV=0
|
||||||
|
)
|
||||||
|
|
||||||
:: Don't create a venv if a conda environment is active
|
:: Don't create a venv if a conda environment is active
|
||||||
if exist "%CONDA_PREFIX%" (
|
if exist "%CONDA_PREFIX%" (
|
||||||
echo It looks like you're in a conda environment. Skipping venv check.
|
echo It looks like you're in a conda environment. Skipping venv check.
|
||||||
) else (
|
) else (
|
||||||
if not exist "venv\" (
|
if not exist "venv\" (
|
||||||
echo Venv doesn't exist! Creating one for you.
|
echo Venv doesn't exist! Creating one for you.
|
||||||
python -m venv venv
|
|
||||||
|
if %HAS_UV% equ 1 (
|
||||||
|
echo "It looks like you're using uv. Running appropriate commands."
|
||||||
|
uv venv venv -p 3.12
|
||||||
|
) else (
|
||||||
|
python -m venv venv
|
||||||
|
)
|
||||||
|
|
||||||
if exist "start_options.json" (
|
if exist "start_options.json" (
|
||||||
echo Removing old start_options.json
|
echo Removing old start_options.json
|
||||||
|
|
|
||||||
20
start.py
20
start.py
|
|
@ -9,7 +9,13 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
has_uv = subprocess.run(
|
||||||
|
["uv", "--version"],
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL
|
||||||
|
).returncode == 0
|
||||||
|
|
||||||
start_options = {}
|
start_options = {}
|
||||||
|
|
||||||
|
|
@ -151,8 +157,14 @@ def migrate_start_options(start_options: dict):
|
||||||
return migrated
|
return migrated
|
||||||
|
|
||||||
|
|
||||||
|
def run_pip(command: List[str]):
|
||||||
|
if has_uv:
|
||||||
|
command.insert(0, "uv")
|
||||||
|
|
||||||
|
subprocess.run(command)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
subprocess.run(["pip", "-V"])
|
|
||||||
|
|
||||||
# Create an argparser and add extra startup script args
|
# Create an argparser and add extra startup script args
|
||||||
# Try creating a full argparser if pydantic is installed
|
# Try creating a full argparser if pydantic is installed
|
||||||
|
|
@ -174,6 +186,10 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
add_start_args(parser)
|
add_start_args(parser)
|
||||||
args, _ = parser.parse_known_args()
|
args, _ = parser.parse_known_args()
|
||||||
|
|
||||||
|
# Log pip version
|
||||||
|
run_pip(["pip", "-V"])
|
||||||
|
|
||||||
script_ext = "bat" if platform.system() == "Windows" else "sh"
|
script_ext = "bat" if platform.system() == "Windows" else "sh"
|
||||||
do_start_options_write = False
|
do_start_options_write = False
|
||||||
|
|
||||||
|
|
@ -224,7 +240,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# pip install .[features]
|
# pip install .[features]
|
||||||
print(f"Running install command: {' '.join(install_command)}")
|
print(f"Running install command: {' '.join(install_command)}")
|
||||||
subprocess.run(install_command)
|
run_pip(install_command)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
if first_run:
|
if first_run:
|
||||||
|
|
|
||||||
14
start.sh
14
start.sh
|
|
@ -2,12 +2,24 @@
|
||||||
|
|
||||||
cd "$(dirname "$0")" || exit
|
cd "$(dirname "$0")" || exit
|
||||||
|
|
||||||
|
if command -v uv >/dev/null 2>&1; then
|
||||||
|
HAS_UV=1
|
||||||
|
else
|
||||||
|
HAS_UV=0
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$CONDA_PREFIX" ]; then
|
if [ -n "$CONDA_PREFIX" ]; then
|
||||||
echo "It looks like you're in a conda environment. Skipping venv check."
|
echo "It looks like you're in a conda environment. Skipping venv check."
|
||||||
else
|
else
|
||||||
if [ ! -d "venv" ]; then
|
if [ ! -d "venv" ]; then
|
||||||
echo "Venv doesn't exist! Creating one for you."
|
echo "Venv doesn't exist! Creating one for you."
|
||||||
python3 -m venv venv
|
|
||||||
|
if [ "$HAS_UV" -eq 1 ]; then
|
||||||
|
echo "It looks like you're using uv. Running appropriate commands."
|
||||||
|
uv venv venv -p 3.12
|
||||||
|
else
|
||||||
|
python3 -m venv venv
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -f "start_options.json" ]; then
|
if [ -f "start_options.json" ]; then
|
||||||
echo "Removing old start_options.json"
|
echo "Removing old start_options.json"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue