Skip to content

Commit

Permalink
Python: Adapt configure and make to use python-pip
Browse files Browse the repository at this point in the history
Since Pythons Setuptools deprecates the 'setup.py install' sequence,
Python PIP will be used on newer python versions as a build frontend
implementing the guidline described in PEP 517 (1).

Albeit this eliminates the deprecation warning
"SetuptoolsDeprecationWarning: setup.py install is deprecated.
Use build and pip and other standards-based tools.",
it creates other pitfalls because Python is moving towards PEP 688 (2)
which clearly describes the ownership of python packages.
When doing a 'configure, make, sudo make install' sequence,
one will get a warning
"WARNING: Running pip as the 'root' user can result in broken
permissions and conflicting behaviour with the system package manager."
which is true for MythTV. This should remind a user to first uninstall
MythTVs packages previously installed by the sytems installation manager.
The environemt variable "PIP_ROOT_USER_ACTION=ignore" silences this
warning.

If a OS distribution protects it's python package by the file
'EXTERNALLY-MANAGED' as described in PEP 688 and the root-flag is not
set, pip will not install packages in these locations.
The environment variable "PIP_BREAK_SYSTEM_PACKAGES=1" overrides this
behaviour.
This reminds the operator to better build system-packages and let the
standard OS installer know of these packages and install them.

(1) https://peps.python.org/pep-0517/
(2) https://peps.python.org/pep-0668/

Refs #731
  • Loading branch information
rcrdnalor committed May 15, 2023
1 parent 2e628f8 commit 8ece26b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions mythtv/bindings/python/.gitignore
@@ -1,4 +1,5 @@
build/
dist/
*.pyc
*.swo
MythTV.egg-info/
Expand Down
27 changes: 27 additions & 0 deletions mythtv/bindings/python/Makefile
Expand Up @@ -3,17 +3,42 @@ include ../../config.mak
ifdef INSTALL_ROOT
ROOT_FLAGS = --root="$(INSTALL_ROOT)"
else
ifndef USE_PYTHON_PIP
ROOT_FLAGS = --root="/"
endif
endif

ifneq ($(PREFIX:/=), /usr)
ifneq ($(PREFIX:/=), /usr/local)
PREFIX_FLAGS=--prefix="$(PREFIX)"
endif
endif

PIP_OPTIONS = --no-build-isolation --no-cache-dir --no-index --disable-pip-version-check --no-deps
WHEEL_DIR = dist

all: python_build

ifdef USE_PYTHON_PIP

clean:
$(RM) -r $(WHEEL_DIR)
$(RM) -r build
$(RM) -r MythTV.*

distcean: clean

python_build:
$(PYTHON) -m pip wheel $(PIP_OPTIONS) --wheel-dir ./$(WHEEL_DIR) .

install:
$(PYTHON) -m pip install $(ROOT_FLAGS) $(PREFIX_FLAGS) $(PIP_OPTIONS) --find-links ./$(WHEEL_DIR) MythTV

uninstall:
$(warning python pip uninstall is not supported for python bindings)

else

clean:
$(PYTHON) setup.py clean --all

Expand All @@ -28,4 +53,6 @@ install: setup.py
uninstall:
$(warning make -C bindings/python uninstall is not supported for python bindings)

endif

.PHONY: all clean distclean install python_build uninstall
3 changes: 3 additions & 0 deletions mythtv/bindings/python/pyproject.toml
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
30 changes: 27 additions & 3 deletions mythtv/configure
Expand Up @@ -1250,10 +1250,11 @@ EOF
}

check_python(){
log check_python
log check_python "$@"
version=${1}
check_cmd $python <<EOF
import sys
if sys.version_info < (3,6,0):
if sys.version_info < $version:
sys.exit(1)
EOF
}
Expand All @@ -1271,6 +1272,24 @@ sys.exit(0)
EOF
}

check_py_lib_version(){
log check_py_lib_version "$@"
lib=${1}
version=${2}
check_cmd $python <<EOF
import sys
try:
# see PEP 440
import $lib
vlist = [int(x) for x in $lib.__version__.split('.') if x.isnumeric()]
if tuple(vlist) < $version:
raise
except:
sys.exit(1)
sys.exit(0)
EOF
}

check_pl_lib(){
log check_pl_lib "$@"
check_cmd perl -e "use ${1};"
Expand Down Expand Up @@ -6539,12 +6558,13 @@ fi

# Check for python dependencies
if enabled bindings_python; then
check_python || disable_bindings_python "Python 3.6 or greater"
check_python "(3,8,0)" || disable_bindings_python "Python 3.8 or greater"
check_py_lib MySQLdb || disable_bindings_python "MySQLdb"
check_py_lib lxml || disable_bindings_python "lxml"
check_py_lib requests || disable_bindings_python "requests"
check_py_lib simplejson || disable_bindings_python "simplejson"
check_py_lib future || disable_bindings_python "future"
check_python "(3,11,1)" && check_py_lib wheel && check_py_lib_version pip "(23,0,1)" && USE_PYTHON_PIP="yes"
fi

# Check for perl dependencies
Expand Down Expand Up @@ -7454,6 +7474,10 @@ if test x"$CONFIG_INCLUDEPATH" != x"" ; then
echo "CONFIG_INCLUDEPATH=$CONFIG_INCLUDEPATH" >> $TMPMAK
fi

if test x"$USE_PYTHON_PIP" != x"" ; then
echo "USE_PYTHON_PIP=$USE_PYTHON_PIP" >> $TMPMAK
fi

cat >> $TMPH <<EOF
/* NOLINTEND(cppcoreguidelines-macro-usage) */
Expand Down

0 comments on commit 8ece26b

Please sign in to comment.