@@ -48,19 +48,13 @@ PRIMARY_PYTHON?=python3
4848PYTHON_MIN_VERSION? =3.9
4949
5050# Install packages using the given package installer method.
51- # Supported are `pip` and `uv`. If uv is used, its global availability is
52- # checked. Otherwise, it is installed, either in the virtual environment or
53- # using the `PRIMARY_PYTHON`, dependent on the `VENV_ENABLED` setting. If
54- # `VENV_ENABLED` and uv is selected, uv is used to create the virtual
55- # environment.
51+ # Supported are `pip` and `uv`. When `uv` is selected, a global installation
52+ # is auto-detected and used if available. Otherwise, uv is installed in the
53+ # virtual environment or using `PRIMARY_PYTHON`, depending on the
54+ # `VENV_ENABLED` setting.
5655# Default: pip
5756PYTHON_PACKAGE_INSTALLER? =pip
5857
59- # Flag whether to use a global installed 'uv' or install
60- # it in the virtual environment.
61- # Default: false
62- MXENV_UV_GLOBAL? =false
63-
6458# Flag whether to use virtual environment. If `false`, the
6559# interpreter according to `PRIMARY_PYTHON` found in `PATH` is used.
6660# Default: true
@@ -139,30 +133,60 @@ else
139133MXENV_PYTHON =$(PRIMARY_PYTHON )
140134endif
141135
142- # Determine the package installer
136+ # Determine the package installer with non-interactive flags
143137ifeq ("$(PYTHON_PACKAGE_INSTALLER ) ","uv")
144- PYTHON_PACKAGE_COMMAND =uv pip
138+ PYTHON_PACKAGE_COMMAND =uv pip --quiet --no-progress
145139else
146140PYTHON_PACKAGE_COMMAND =$(MXENV_PYTHON ) -m pip
147141endif
148142
143+ # Auto-detect global uv availability (simple existence check)
144+ ifeq ("$(PYTHON_PACKAGE_INSTALLER ) ","uv")
145+ UV_AVAILABLE: =$(shell command -v uv >/dev/null 2>&1 && echo "true" || echo "false")
146+ else
147+ UV_AVAILABLE: =false
148+ endif
149+
150+ # Determine installation strategy
151+ USE_GLOBAL_UV: =$(shell [[ "$(PYTHON_PACKAGE_INSTALLER ) " == "uv" && "$(UV_AVAILABLE ) " == "true" ]] && echo "true" || echo "false")
152+ USE_LOCAL_UV: =$(shell [[ "$(PYTHON_PACKAGE_INSTALLER ) " == "uv" && "$(UV_AVAILABLE ) " == "false" ]] && echo "true" || echo "false")
153+
154+ # UV Python version (defaults to PRIMARY_PYTHON for backward compatibility)
155+ UV_PYTHON? =$(PRIMARY_PYTHON )
156+
157+ # Check if global UV is outdated (non-blocking warning)
158+ ifeq ("$(USE_GLOBAL_UV ) ","true")
159+ UV_OUTDATED: =$(shell uv self update --dry-run 2>&1 | grep -q "Would update" && echo "true" || echo "false")
160+ else
161+ UV_OUTDATED: =false
162+ endif
163+
149164MXENV_TARGET: =$(SENTINEL_FOLDER ) /mxenv.sentinel
150165$(MXENV_TARGET ) : $(SENTINEL )
151- ifneq ("$(PYTHON_PACKAGE_INSTALLER )$(MXENV_UV_GLOBAL ) ","uvfalse")
166+ # Validation: Check Python version if not using global uv
167+ ifneq ("$(USE_GLOBAL_UV ) ","true")
152168 @$(PRIMARY_PYTHON) -c "import sys; vi = sys.version_info; sys.exit(1 if (int(vi[0]), int(vi[1])) >= tuple(map(int, '$(PYTHON_MIN_VERSION)'.split('.'))) else 0)" \
153169 && echo "Need Python >= $(PYTHON_MIN_VERSION)" && exit 1 || :
154170else
155- @echo "Use Python $(PYTHON_MIN_VERSION) over uv "
171+ @echo "Using global uv for Python $(UV_PYTHON) "
156172endif
173+ # Validation: Check VENV_FOLDER is set if venv enabled
157174 @[[ "$(VENV_ENABLED)" == "true" && "$(VENV_FOLDER)" == "" ]] \
158175 && echo "VENV_FOLDER must be configured if VENV_ENABLED is true" && exit 1 || :
159- @[[ "$(VENV_ENABLED)$(PYTHON_PACKAGE_INSTALLER)" == "falseuv" ]] \
176+ # Validation: Check uv not used with system Python
177+ @[[ "$(VENV_ENABLED)" == "false" && "$(PYTHON_PACKAGE_INSTALLER)" == "uv" ]] \
160178 && echo "Package installer uv does not work with a global Python interpreter." && exit 1 || :
179+ # Warning: Notify if global UV is outdated
180+ ifeq ("$(UV_OUTDATED ) ","true")
181+ @echo "WARNING: A newer version of uv is available. Run 'uv self update' to upgrade."
182+ endif
183+
184+ # Create virtual environment
161185ifeq ("$(VENV_ENABLED ) ", "true")
162186ifeq ("$(VENV_CREATE ) ", "true")
163- ifeq ("$(PYTHON_PACKAGE_INSTALLER )$( MXENV_UV_GLOBAL ) ","uvtrue ")
164- @echo "Setup Python Virtual Environment using package 'uv' at '$(VENV_FOLDER)'"
165- @uv venv -p $(PRIMARY_PYTHON ) --seed $(VENV_FOLDER)
187+ ifeq ("$(USE_GLOBAL_UV ) ","true ")
188+ @echo "Setup Python Virtual Environment using global uv at '$(VENV_FOLDER)'"
189+ @uv venv --quiet --no-progress - p $(UV_PYTHON ) --seed $(VENV_FOLDER)
166190else
167191 @echo "Setup Python Virtual Environment using module 'venv' at '$(VENV_FOLDER)'"
168192 @$(PRIMARY_PYTHON) -m venv $(VENV_FOLDER)
@@ -172,10 +196,14 @@ endif
172196else
173197 @echo "Using system Python interpreter"
174198endif
175- ifeq ("$(PYTHON_PACKAGE_INSTALLER )$(MXENV_UV_GLOBAL ) ","uvfalse")
176- @echo "Install uv"
199+
200+ # Install uv locally if needed
201+ ifeq ("$(USE_LOCAL_UV ) ","true")
202+ @echo "Install uv in virtual environment"
177203 @$(MXENV_PYTHON) -m pip install uv
178204endif
205+
206+ # Install/upgrade core packages
179207 @$(PYTHON_PACKAGE_COMMAND) install -U pip setuptools wheel
180208 @echo "Install/Update MXStack Python packages"
181209 @$(PYTHON_PACKAGE_COMMAND) install -U $(MXDEV) $(MXMAKE)
0 commit comments