From 0cfca4734589043f13ab5b26f3ccc9628f38f0c2 Mon Sep 17 00:00:00 2001 From: termux-pacman-bot Date: Sun, 18 Jan 2026 09:39:02 +0000 Subject: [PATCH] Update repo --- build-package.sh | 4 + disabled-packages/python-pandas/build.sh | 8 - .../build/setup/termux_setup_python_pip.sh | 4 + .../build/termux_create_debian_subpackages.sh | 2 + .../build/termux_create_pacman_subpackages.sh | 2 + .../build/termux_step_copy_into_massagedir.sh | 2 +- .../termux_step_create_debian_package.sh | 1 + .../termux_step_create_pacman_package.sh | 1 + .../termux_step_create_python_debscripts.sh | 158 ++++++++++++++++++ .../termux_step_create_subpkg_debscripts.sh | 2 +- .../termux_step_get_dependencies_python.sh | 4 +- scripts/build/termux_step_setup_variables.sh | 2 + scripts/build/termux_step_start_build.sh | 6 + 13 files changed, 184 insertions(+), 12 deletions(-) create mode 100644 scripts/build/termux_step_create_python_debscripts.sh diff --git a/build-package.sh b/build-package.sh index e11af68ef6..d96694a0ae 100755 --- a/build-package.sh +++ b/build-package.sh @@ -397,6 +397,10 @@ termux_step_post_massage() { # shellcheck source=scripts/build/termux_step_create_debscripts.sh source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_create_debscripts.sh" +# Function to generate debscripts for python packages. +# shellcheck source=scripts/build/termux_step_create_python_debscripts.sh +source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_create_python_debscripts.sh" + # Convert Debian maintainer scripts into pacman-compatible installation hooks. # This is used only when creating pacman packages. # shellcheck source=scripts/build/termux_step_create_pacman_install_hook.sh diff --git a/disabled-packages/python-pandas/build.sh b/disabled-packages/python-pandas/build.sh index 27547da146..ba1632e4ff 100644 --- a/disabled-packages/python-pandas/build.sh +++ b/disabled-packages/python-pandas/build.sh @@ -18,11 +18,3 @@ termux_step_pre_configure() { termux_step_make_install() { pip install --no-deps --no-build-isolation . --prefix $TERMUX_PREFIX } - -termux_step_create_debscripts() { - cat <<- EOF > ./postinst - #!$TERMUX_PREFIX/bin/sh - echo "Installing dependencies through pip..." - pip3 install ${TERMUX_PKG_PYTHON_TARGET_DEPS//, / } - EOF -} diff --git a/scripts/build/setup/termux_setup_python_pip.sh b/scripts/build/setup/termux_setup_python_pip.sh index 7f47f2eea7..ee8bd5feb4 100644 --- a/scripts/build/setup/termux_setup_python_pip.sh +++ b/scripts/build/setup/termux_setup_python_pip.sh @@ -68,5 +68,9 @@ termux_setup_python_pip() { export PATH="${TERMUX_PYTHON_CROSSENV_PREFIX}/build/bin:${PATH}" local _CROSS_PATH="${TERMUX_PYTHON_CROSSENV_PREFIX}/cross/bin" export PATH="${_CROSS_PATH}:$(echo -n $(tr ':' '\n' <<< "${PATH}" | grep -v "^${_CROSS_PATH}$") | tr ' ' ':')" + + local sysconfig_module=$(${TERMUX_PYTHON_CROSSENV_PREFIX}/build/bin/python -c "import sysconfig; print(sysconfig.__file__)") + cp -r "${sysconfig_module}" "${TERMUX_PYTHON_CROSSENV_BUILDHOME}" + sed -i "s|os.path.normpath(sys.*prefix)|\"${TERMUX_PREFIX}\"|g" "${TERMUX_PYTHON_CROSSENV_BUILDHOME}/${sysconfig_module##*/}" fi } diff --git a/scripts/build/termux_create_debian_subpackages.sh b/scripts/build/termux_create_debian_subpackages.sh index ef7ebee310..1967f79646 100644 --- a/scripts/build/termux_create_debian_subpackages.sh +++ b/scripts/build/termux_create_debian_subpackages.sh @@ -34,6 +34,7 @@ termux_create_debian_subpackages() { local TERMUX_SUBPKG_CONFFILES="" local TERMUX_SUBPKG_DEPEND_ON_PARENT="" local TERMUX_SUBPKG_EXCLUDED_ARCHES="" + local TERMUX_SUBPKG_PYTHON_RUNTIME_DEPS="" local SUB_PKG_MASSAGE_DIR=$SUB_PKG_DIR/massage/$TERMUX_PREFIX_CLASSICAL local SUB_PKG_PACKAGE_DIR=$SUB_PKG_DIR/package mkdir -p "$SUB_PKG_MASSAGE_DIR" "$SUB_PKG_PACKAGE_DIR" @@ -138,6 +139,7 @@ termux_create_debian_subpackages() { # Allow packages to create arbitrary control files. termux_step_create_subpkg_debscripts + termux_step_create_python_debscripts # Create control.tar.xz tar --sort=name \ diff --git a/scripts/build/termux_create_pacman_subpackages.sh b/scripts/build/termux_create_pacman_subpackages.sh index ef2b8f11f4..cb0366de8d 100644 --- a/scripts/build/termux_create_pacman_subpackages.sh +++ b/scripts/build/termux_create_pacman_subpackages.sh @@ -35,6 +35,7 @@ termux_create_pacman_subpackages() { local TERMUX_SUBPKG_DEPEND_ON_PARENT="" local TERMUX_SUBPKG_EXCLUDED_ARCHES="" local TERMUX_SUBPKG_GROUPS="" + local TERMUX_SUBPKG_PYTHON_RUNTIME_DEPS="" local SUB_PKG_MASSAGE_DIR=$SUB_PKG_DIR/massage/$TERMUX_PREFIX_CLASSICAL local SUB_PKG_PACKAGE_DIR=$SUB_PKG_DIR/package mkdir -p "$SUB_PKG_MASSAGE_DIR" "$SUB_PKG_PACKAGE_DIR" @@ -167,6 +168,7 @@ termux_create_pacman_subpackages() { # Write package installation hooks. termux_step_create_subpkg_debscripts + termux_step_create_python_debscripts termux_step_create_pacman_install_hook # Configuring the selection of a copress for a batch. diff --git a/scripts/build/termux_step_copy_into_massagedir.sh b/scripts/build/termux_step_copy_into_massagedir.sh index b77eacd3d3..888ac35203 100644 --- a/scripts/build/termux_step_copy_into_massagedir.sh +++ b/scripts/build/termux_step_copy_into_massagedir.sh @@ -2,6 +2,6 @@ termux_step_copy_into_massagedir() { local DEST="$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX_CLASSICAL" mkdir -p "$DEST" # Copy files changed during the build into massagedir in order to massage them - tar -C "$TERMUX_PREFIX_CLASSICAL" -N "$TERMUX_BUILD_TS_FILE" --exclude='tmp' -cf - . | \ + tar -C "$TERMUX_PREFIX_CLASSICAL" -N "$TERMUX_BUILD_TS_FILE" --exclude='tmp' --exclude='__pycache__' -cf - . | \ tar -C "$DEST" -xf - } diff --git a/scripts/build/termux_step_create_debian_package.sh b/scripts/build/termux_step_create_debian_package.sh index eb3bceed59..a2ce8f058f 100644 --- a/scripts/build/termux_step_create_debian_package.sh +++ b/scripts/build/termux_step_create_debian_package.sh @@ -54,6 +54,7 @@ termux_step_create_debian_package() { # Process `update-alternatives` entries from `.alternatives` files # These need to be merged into the `.postinst` and `.prerm` files, so after those are created. termux_step_update_alternatives + termux_step_create_python_debscripts # Create control.tar.xz tar --sort=name \ diff --git a/scripts/build/termux_step_create_pacman_package.sh b/scripts/build/termux_step_create_pacman_package.sh index ed987e3ea5..25a0ae4e7b 100644 --- a/scripts/build/termux_step_create_pacman_package.sh +++ b/scripts/build/termux_step_create_pacman_package.sh @@ -125,6 +125,7 @@ termux_step_create_pacman_package() { # Process `update-alternatives` entries from `.alternatives` files # These need to be merged into the `.postinst` and `.prerm` files, so after those are created. termux_step_update_alternatives + termux_step_create_python_debscripts termux_step_create_pacman_install_hook # ensure all elements of the package have the same mtime diff --git a/scripts/build/termux_step_create_python_debscripts.sh b/scripts/build/termux_step_create_python_debscripts.sh new file mode 100644 index 0000000000..e3c0a7ba35 --- /dev/null +++ b/scripts/build/termux_step_create_python_debscripts.sh @@ -0,0 +1,158 @@ +termux_step_create_python_debscripts() { + if [[ -n "${SUB_PKG_NAME-}" ]]; then + local _package_name="$SUB_PKG_NAME" + local _package_python_home="$SUB_PKG_DIR/massage$TERMUX_PREFIX/lib/python$TERMUX_PYTHON_VERSION" + local _package_python_deps="${TERMUX_SUBPKG_PYTHON_RUNTIME_DEPS//, / }" + else + local _package_name="$TERMUX_PKG_NAME" + local _package_python_home="$TERMUX_PKG_MASSAGEDIR$TERMUX_PREFIX/lib/python$TERMUX_PYTHON_VERSION" + local _package_python_deps="${TERMUX_PKG_PYTHON_RUNTIME_DEPS//, / }" + fi + + local py_file_in_lib_python="" pip_metadata_file="" + + # if the package does not contain any .py files in + # $TERMUX_PREFIX/lib/python$TERMUX_PYTHON_VERSION, + # then debpython (py3compile and py3clean) are not + # necessary or not currently supported for this package + if [[ -d "$_package_python_home" ]]; then + py_file_in_lib_python="$(find "$_package_python_home" -name "*.py" -print -quit)" + fi + + # metadata file that at least some packages have, which contains the 'pip'-facing name of the + # package and any PyPi dependencies it has. + if [[ -d "$_package_python_home/site-packages" ]]; then + pip_metadata_file="$(find "$_package_python_home/site-packages" -name "METADATA" -print -quit)" + fi + + # add the internal 'pip'-facing name of the package to the 'pip install' dependencies if it exists + # in the 'METADATA' file and the 'METADATA' file also marks the package as depending + # on any other 'pip'-facing packages, which will install all the 'pip'-facing dependencies + # the software marks itself as depending on from PyPi that are not already installed from other Termux packages. + # if more than one 'METADATA' file is detected, this condition will evaluate false so nothing will happen. + if [[ -f "$pip_metadata_file" ]] && grep -q '^Requires-Dist' "$pip_metadata_file"; then + local package_pip_name="$(grep 'Name:' "$pip_metadata_file" | cut -d' ' -f2)" + _package_python_deps+=" $package_pip_name" + fi + + # if there are no .py files in $TERMUX_PREFIX/lib/python$TERMUX_PYTHON_VERSION/, + # and the package has an empty $_package_python_deps, then this function does not need to do anything + if [[ -z "$py_file_in_lib_python" ]] && [[ -z "${_package_python_deps}" ]]; then + return + fi + + # if a postinst script does not already exist, create a new one + # but if the postinst script already exists and has 'exit 0' + # as its last line, remove that line so that it does not + # prevent execution of the additional commands + if [[ ! -f postinst ]]; then + echo "#!${TERMUX_PREFIX_CLASSICAL}/bin/sh" >postinst + chmod 0755 postinst + elif tail -n1 postinst | grep -q 'exit 0'; then + sed -i '$d' postinst + fi + + # if the package format is .deb, only run the script + # if the package is being configured (not failed) + if [[ "$TERMUX_PACKAGE_FORMAT" == "debian" ]]; then + cat <<-POSTINST_EOF >>postinst + if [ "\$1" != "configure" ]; then + exit 0 + fi + POSTINST_EOF + fi + + # if the package has runtime dependencies requiring pip, + # make this script install them + if [[ -n "${_package_python_deps}" ]]; then + local pip_package_name="python-pip" upgrade_flag="--upgrade" + + if [[ "$TERMUX_PACKAGE_LIBRARY" == "glibc" ]]; then + pip_package_name+="-glibc" + fi + + # if the list of dependencies to install from PyPi has the name of + # the current package with any 'python-' prefix stripped from it anywhere in it, + # do not use the '--upgrade' argument to pip, in order to avoid overwriting + # the non-PyPi local package files with a different software with the same name, + # or the same package of an incorrect version, from PyPi. + # this is particularly important for the 'nala' package, for example. + if [[ " $(tr ' ' '\n' <<<"${_package_python_deps}" | sed "s/'//g; s// /g; s/=/ /g" | awk '{printf $1 " "}')" =~ " ${_package_name//python-/} " ]]; then + upgrade_flag="" + fi + + cat <<-POSTINST_EOF >>postinst + echo "Installing dependencies for ${_package_name} through pip..." + LD_PRELOAD='' LDFLAGS="-lpython$TERMUX_PYTHON_VERSION" MATHLIB="m" "${TERMUX_PREFIX}/bin/pip3" install ${upgrade_flag} ${_package_python_deps} + POSTINST_EOF + + # ensure that pip is added as a dependency to all + # packages that run the 'pip' command during installation. + if ([[ "$TERMUX_PACKAGE_FORMAT" == "debian" ]] && ! grep -q -E "Depends.*$pip_package_name(,|$)" control) || ([[ "$TERMUX_PACKAGE_FORMAT" == "pacman" ]] && ! grep -q "depend = $pip_package_name" .PKGINFO); then + termux_error_exit "'$_package_name' must depend on '$pip_package_name' because it needs to run 'pip' during installation!" + fi + fi + + # if the package does not contain any .py files in + # $TERMUX_PREFIX/lib/python$TERMUX_PYTHON_VERSION, + # then this function does not need to do anything else + if [[ -z "$py_file_in_lib_python" ]]; then + return + fi + + # post-inst script to generate *.pyc files + cat <<-POSTINST_EOF >>postinst + if [ -f "${TERMUX_PREFIX}/bin/py3compile" ]; then + LD_PRELOAD='' "${TERMUX_PREFIX}/bin/py3compile" -p "$_package_name" "${TERMUX_PREFIX}/lib/python${TERMUX_PYTHON_VERSION}/" + fi + POSTINST_EOF + + # make the last command of the postinst script 'exit 0' + # because if the previous last command was a condition, + # and the condition failed, then the postinst script could + # fail, which would not actually be the desired result + cat <<-POSTINST_EOF >>postinst + exit 0 + POSTINST_EOF + + # if a prerm script does not already exist, create a new one + # but if the prerm script already exists and has 'exit 0' + # as its last line, remove that line so that it does not + # prevent execution of the additional commands + if [[ ! -f prerm ]]; then + echo "#!${TERMUX_PREFIX_CLASSICAL}/bin/sh" >prerm + chmod 0755 prerm + elif tail -n1 prerm | grep -q 'exit 0'; then + sed -i '$d' prerm + fi + + # if the package format is .deb, only run the script + # if the package is being removed (not failed) + if [[ "$TERMUX_PACKAGE_FORMAT" == "debian" ]]; then + cat <<-PRERM_EOF >>prerm + if [ "\$1" != "remove" ]; then + exit 0 + fi + PRERM_EOF + fi + + # pre-rm script to cleanup runtime-generated files. + cat <<-PRERM_EOF >>prerm + if [ -f "${TERMUX_PREFIX}/bin/py3clean" ]; then + LD_PRELOAD='' "${TERMUX_PREFIX}/bin/py3clean" -p "$_package_name" + fi + PRERM_EOF + + # make the last command of the prerm script 'exit 0' + # because if the previous last command was a condition, + # and the condition failed, then the prerm script could + # fail, which would not actually be the desired result + cat <<-PRERM_EOF >>prerm + exit 0 + PRERM_EOF + + # running py3compile in a package for pacman during a package update + if [[ "$TERMUX_PACKAGE_FORMAT" == "pacman" ]] && ! grep -qs 'post_install' postupg; then + echo "post_install" >>postupg + fi +} diff --git a/scripts/build/termux_step_create_subpkg_debscripts.sh b/scripts/build/termux_step_create_subpkg_debscripts.sh index ab438620e4..52c549a59f 100644 --- a/scripts/build/termux_step_create_subpkg_debscripts.sh +++ b/scripts/build/termux_step_create_subpkg_debscripts.sh @@ -1,3 +1,3 @@ termux_step_create_subpkg_debscripts() { - return + return 0 } diff --git a/scripts/build/termux_step_get_dependencies_python.sh b/scripts/build/termux_step_get_dependencies_python.sh index 5c079da66c..5da9a7bbbe 100644 --- a/scripts/build/termux_step_get_dependencies_python.sh +++ b/scripts/build/termux_step_get_dependencies_python.sh @@ -27,9 +27,9 @@ termux_step_get_dependencies_python() { done # adding and setting values ​​to work properly with python modules - export PYTHONPATH=$TERMUX_PYTHON_HOME/site-packages + export PYTHONPATH="${TERMUX_PYTHON_CROSSENV_BUILDHOME}:${TERMUX_PYTHON_HOME}/site-packages" if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then - export TERMUX_PYTHON_MAINPATH="${PYTHONPATH}:${TERMUX_PYTHON_CROSSENV_PREFIX}/build/lib/python${TERMUX_PYTHON_VERSION}/site-packages" + export TERMUX_PYTHON_MAINPATH="${PYTHONPATH}:${TERMUX_PYTHON_CROSSENV_BUILDHOME}/site-packages" fi export PYTHON_SITE_PKG=$PYTHONPATH fi diff --git a/scripts/build/termux_step_setup_variables.sh b/scripts/build/termux_step_setup_variables.sh index c43c494c25..e6fccbc375 100644 --- a/scripts/build/termux_step_setup_variables.sh +++ b/scripts/build/termux_step_setup_variables.sh @@ -180,7 +180,9 @@ termux_step_setup_variables() { TERMUX_PKG_PYTHON_TARGET_DEPS="" # python modules to be installed via pip3 TERMUX_PKG_PYTHON_BUILD_DEPS="" # python modules to be installed via build-pip TERMUX_PKG_PYTHON_COMMON_DEPS="" # python modules to be installed via pip3 or build-pip + TERMUX_PKG_PYTHON_RUNTIME_DEPS="" # python modules to be installed via pip3 in debscriptps TERMUX_PYTHON_CROSSENV_PREFIX="$TERMUX_TOPDIR/python${TERMUX_PYTHON_VERSION}-crossenv-prefix-$TERMUX_PACKAGE_LIBRARY-$TERMUX_ARCH" # python modules dependency location (only used in non-devices) + TERMUX_PYTHON_CROSSENV_BUILDHOME="$TERMUX_PYTHON_CROSSENV_PREFIX/build/lib/python${TERMUX_PYTHON_VERSION}" TERMUX_PYTHON_HOME=$TERMUX__PREFIX__LIB_DIR/python${TERMUX_PYTHON_VERSION} # location of python libraries TERMUX_LLVM_VERSION="$( # get the latest version of LLVM if [[ "${TERMUX_PACKAGE_LIBRARY}" == "bionic" ]]; then diff --git a/scripts/build/termux_step_start_build.sh b/scripts/build/termux_step_start_build.sh index 47ec3a9fb5..911e467652 100644 --- a/scripts/build/termux_step_start_build.sh +++ b/scripts/build/termux_step_start_build.sh @@ -22,6 +22,12 @@ termux_step_start_build() { # Enable python setting TERMUX_PKG_SETUP_PYTHON=true fi + if [ -z "$TERMUX_PKG_PYTHON_RUNTIME_DEPS" ]; then + TERMUX_PKG_PYTHON_RUNTIME_DEPS="$TERMUX_PKG_PYTHON_TARGET_DEPS" + fi + if [ "$TERMUX_PKG_PYTHON_RUNTIME_DEPS" = "false" ]; then + TERMUX_PKG_PYTHON_RUNTIME_DEPS="" + fi TERMUX_PKG_FULLVERSION=$TERMUX_PKG_VERSION if [ "$TERMUX_PKG_REVISION" != "0" ] || [ "$TERMUX_PKG_FULLVERSION" != "${TERMUX_PKG_FULLVERSION/-/}" ]; then