Skip to content

Commit

Permalink
make: improve check for externally managed Python
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rst0git committed May 21, 2024
1 parent 516b369 commit d4d1646
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 40 deletions.
20 changes: 20 additions & 0 deletions Makefile.install
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ 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
endif
endif

# Default flags for pip install:
# --upgrade: Upgrade crit/pycriu packages
# --ignore-installed: Ignore existing packages and reinstall them
# --progress-bar off: Suppress the progress bar for cleaner output
PIPFLAGS ?= --upgrade --ignore-installed --progress-bar off

export SKIP_PIP_INSTALL PIPFLAGS

install-man:
$(Q) $(MAKE) -C Documentation install
.PHONY: install-man
Expand Down
27 changes: 7 additions & 20 deletions crit/Makefile
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -10,31 +7,21 @@ ${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: Externally managed Python environment"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1"
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: Externally managed python environment"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1"
endif
.PHONY: uninstall
27 changes: 7 additions & 20 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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: ;
Expand Down Expand Up @@ -57,17 +54,12 @@ 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: Externally managed Python environment"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1"
endif
.PHONY: install

Expand All @@ -80,16 +72,11 @@ 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: Externally managed Python environment"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1"
endif
.PHONY: uninstall

0 comments on commit d4d1646

Please sign in to comment.