diff --git a/Makefile b/Makefile index ae3314e..1f5bdf0 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ PYTHON_PACKAGE_INSTALLER?=uv # Flag whether to use a global installed 'uv' or install # it in the virtual environment. # Default: false -PYTHON_UV_GLOBAL?=true +PYTHON_UV_GLOBAL?=false # Flag whether to use virtual environment. If `false`, the # interpreter according to `PRIMARY_PYTHON` found in `PATH` is used. diff --git a/src/mxmake/tests/test_parser.py b/src/mxmake/tests/test_parser.py index a7a511b..eafcc24 100644 --- a/src/mxmake/tests/test_parser.py +++ b/src/mxmake/tests/test_parser.py @@ -21,6 +21,8 @@ def test_MakefileParser(self, tempdir): "core.base.EXTRA_PATH": "", "core.mxenv.PRIMARY_PYTHON": "python3", "core.mxenv.PYTHON_MIN_VERSION": "3.7", + "core.mxenv.PYTHON_PACKAGE_INSTALLER": "pip", + "core.mxenv.PYTHON_UV_GLOBAL": "false", "core.mxenv.VENV_ENABLED": "true", "core.mxenv.VENV_CREATE": "true", "core.mxenv.VENV_FOLDER": "venv", @@ -65,6 +67,8 @@ def test_MakefileParser(self, tempdir): "core.base.EXTRA_PATH": "", "core.mxenv.PRIMARY_PYTHON": "python3", "core.mxenv.PYTHON_MIN_VERSION": "3.7", + "core.mxenv.PYTHON_PACKAGE_INSTALLER": "pip", + "core.mxenv.PYTHON_UV_GLOBAL": "false", "core.mxenv.VENV_ENABLED": "true", "core.mxenv.VENV_CREATE": "true", "core.mxenv.VENV_FOLDER": "venv", diff --git a/src/mxmake/tests/test_templates.py b/src/mxmake/tests/test_templates.py index 78a2b0c..7984627 100644 --- a/src/mxmake/tests/test_templates.py +++ b/src/mxmake/tests/test_templates.py @@ -526,6 +526,8 @@ def test_Makefile(self, tempdir): "core.base.EXTRA_PATH": "", "core.mxenv.PRIMARY_PYTHON": "python3", "core.mxenv.PYTHON_MIN_VERSION": "3.7", + "core.mxenv.PYTHON_PACKAGE_INSTALLER": "pip", + "core.mxenv.PYTHON_UV_GLOBAL": "false", "core.mxenv.VENV_ENABLED": "true", "core.mxenv.VENV_CREATE": "true", "core.mxenv.VENV_FOLDER": "venv", @@ -596,6 +598,11 @@ def test_Makefile(self, tempdir): # Default: pip PYTHON_PACKAGE_INSTALLER?=pip + # Flag whether to use a global installed 'uv' or install + # it in the virtual environment. + # Default: false + PYTHON_UV_GLOBAL?=false + # Flag whether to use virtual environment. If `false`, the # interpreter according to `PRIMARY_PYTHON` found in `PATH` is used. # Default: true @@ -683,20 +690,44 @@ def test_Makefile(self, tempdir): MXENV_PYTHON=$(PRIMARY_PYTHON) endif + # determine the package installer + ifeq ("$(PYTHON_PACKAGE_INSTALLER)","uv") + # use uv + PYTHON_PACKAGE_COMMAND=uv pip + else + # use/default to pip + PYTHON_PACKAGE_COMMAND=$(MXENV_PYTHON) -m pip + endif # /PYTHON_PACKAGE_INSTALLER + MXENV_TARGET:=$(SENTINEL_FOLDER)/mxenv.sentinel $(MXENV_TARGET): $(SENTINEL) ifeq ("$(VENV_ENABLED)", "true") + # Use a venv ifeq ("$(VENV_CREATE)", "true") - @echo "Setup Python Virtual Environment under '$(VENV_FOLDER)'" - @$(PRIMARY_PYTHON) -m venv $(VENV_FOLDER) - endif - endif - @$(MXENV_PYTHON) -m ensurepip -U - @$(PYTHON_PACKAGE_COMMAND) install -U pip setuptools wheel - @$(PYTHON_PACKAGE_COMMAND) install -U $(MXDEV) - @$(PYTHON_PACKAGE_COMMAND) install -U $(MXMAKE) - @touch $(MXENV_TARGET) - + # Create a venv + ifeq ("$(PYTHON_PACKAGE_INSTALLER)$(PYTHON_UV_GLOBAL)", "uvtrue") + # create venv with global uv + @echo "Setup Python Virtual Environment using package 'uv' at '$(VENV_FOLDER)'" + @uv venv -p $(PRIMARY_PYTHON) --seed $(VENV_FOLDER) + else + @echo "Setup Python Virtual Environment using module 'venv' at '$(VENV_FOLDER)'" + @$(MXENV_PYTHON) -m venv $(VENV_FOLDER) + @$(MXENV_PYTHON) -m ensurepip -U + endif # /PYTHON_PACKAGE_INSTALLER uv and PYTHON_UV_GLOBAL + + ifeq ("$(PYTHON_PACKAGE_INSTALLER)$(PYTHON_UV_GLOBAL)", "uvfalse") + @echo "Install uv" + @$(MXENV_PYTHON) -m pip install uv + endif # /PYTHON_PACKAGE_INSTALLER uv and not PYTHON_UV_GLOBAL + # always update pip, setuptools and wheel + @$(PYTHON_PACKAGE_COMMAND) install -U pip setuptools wheel + endif # /VENV_CREATE + else + @echo "Using system Python interpreter" + endif # /VENV_ENABLED + @echo "Install/Update MXStack Python packages" + @$(PYTHON_PACKAGE_COMMAND) install -U $(MXDEV) $(MXMAKE) + @touch $(MXENV_TARGET) .PHONY: mxenv mxenv: $(MXENV_TARGET)