2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 09:58:09 +00:00

make: improve check for externally managed Python

Move PYTHON_EXTERNALLY_MANAGED and PIP_BREAK_SYSTEM_PACKAGES
into Makefile.install to avoid code duplication. In addition, add
PIPFLAGS variable to enable specifying pip options during installation.
This is particularly useful for packaging, where it is common for `pip install`
to run in an environment with pre-installed dependencies and without internet
access. In such environment, we need to specify the following options:

    --no-build-isolation --no-index --no-deps

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
This commit is contained in:
Radostin Stoyanov 2024-05-21 09:48:34 +01:00 committed by Andrei Vagin
parent fdf546dbd5
commit 4f15fe8c59
3 changed files with 33 additions and 40 deletions

View File

@ -29,6 +29,29 @@ LIBDIR ?= $(PREFIX)/lib
export PREFIX BINDIR SBINDIR MANDIR RUNDIR
export LIBDIR INCLUDEDIR LIBEXECDIR PLUGINDIR
# Detect externally managed Python environment (PEP 668).
PYTHON_EXTERNALLY_MANAGED := $(shell $(PYTHON) -c 'import os, sysconfig; print(int(os.path.isfile(os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED"))))')
PIP_BREAK_SYSTEM_PACKAGES ?= 0
# If Python environment is externally managed and PIP_BREAK_SYSTEM_PACKAGES is not set, skip pip install.
SKIP_PIP_INSTALL := 0
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
SKIP_PIP_INSTALL := 1
$(info Warn: Externally managed python environment)
$(info Consider using PIP_BREAK_SYSTEM_PACKAGES=1)
endif
endif
# Default flags for pip install:
# --upgrade: Upgrade crit/pycriu packages
# --ignore-installed: Ignore existing packages and reinstall them
PIPFLAGS ?= --upgrade --ignore-installed
export SKIP_PIP_INSTALL PIPFLAGS
install-man:
$(Q) $(MAKE) -C Documentation install
.PHONY: install-man

View File

@ -1,6 +1,3 @@
PYTHON_EXTERNALLY_MANAGED := $(shell $(PYTHON) -c 'import os, sysconfig; print(int(os.path.isfile(os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED"))))')
PIP_BREAK_SYSTEM_PACKAGES := 0
VERSION_FILE := $(if $(obj),$(addprefix $(obj)/,crit/version.py),crit/version.py)
all-y += ${VERSION_FILE}
@ -10,31 +7,19 @@ ${VERSION_FILE}:
$(Q) echo "__version__ = '${CRIU_VERSION}'" > $@
install: ${VERSION_FILE}
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP INSTALL crit: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make install"
else
ifeq ($(SKIP_PIP_INSTALL),0)
$(E) " INSTALL " crit
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
endif
$(Q) $(PYTHON) -m pip install $(PIPFLAGS) --prefix=$(DESTDIR)$(PREFIX) ./crit
else
$(E) " INSTALL " crit
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
$(E) " SKIP INSTALL crit"
endif
.PHONY: install
uninstall:
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP UNINSTALL crit: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make uninstall"
else
ifeq ($(SKIP_PIP_INSTALL),0)
$(E) " UNINSTALL" crit
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
endif
else
$(E) " UNINSTALL" crit
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
$(E) " SKIP UNINSTALL crit"
endif
.PHONY: uninstall

View File

@ -4,9 +4,6 @@ UAPI_HEADERS := lib/c/criu.h images/rpc.proto images/rpc.pb-c.h criu/include/ve
all-y += lib-c lib-a lib-py
PYTHON_EXTERNALLY_MANAGED := $(shell $(PYTHON) -c 'import os, sysconfig; print(int(os.path.isfile(os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED"))))')
PIP_BREAK_SYSTEM_PACKAGES := 0
#
# C language bindings.
lib/c/Makefile: ;
@ -57,17 +54,11 @@ install: lib-c lib-a lib-py lib/c/criu.pc.in
$(Q) mkdir -p $(DESTDIR)$(LIBDIR)/pkgconfig
$(Q) sed -e 's,@version@,$(CRIU_VERSION),' -e 's,@libdir@,$(LIBDIR),' -e 's,@includedir@,$(dir $(INCLUDEDIR)/criu/),' lib/c/criu.pc.in > lib/c/criu.pc
$(Q) install -m 644 lib/c/criu.pc $(DESTDIR)$(LIBDIR)/pkgconfig
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP INSTALL pycriu: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make install"
else
ifeq ($(SKIP_PIP_INSTALL),0)
$(E) " INSTALL " pycriu
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./lib
endif
$(Q) $(PYTHON) -m pip install $(PIPFLAGS) --prefix=$(DESTDIR)$(PREFIX) ./lib
else
$(E) " INSTALL " pycriu
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./lib
$(E) " SKIP INSTALL pycriu"
endif
.PHONY: install
@ -80,16 +71,10 @@ uninstall:
$(Q) $(RM) $(addprefix $(DESTDIR)$(INCLUDEDIR)/criu/,$(notdir $(UAPI_HEADERS)))
$(E) " UNINSTALL" pkgconfig/criu.pc
$(Q) $(RM) $(addprefix $(DESTDIR)$(LIBDIR)/pkgconfig/,criu.pc)
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP UNINSTALL pycriu: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make uninstall"
else
ifeq ($(SKIP_PIP_INSTALL),0)
$(E) " UNINSTALL" pycriu
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) pycriu
endif
else
$(E) " UNINSTALL" pycriu
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) pycriu
$(E) " SKIP UNINSTALL pycriu"
endif
.PHONY: uninstall