Skip to content

Commit

Permalink
Fix site-packages for freethreading and abi3
Browse files Browse the repository at this point in the history
  • Loading branch information
isuruf committed Aug 8, 2024
1 parent 08138e5 commit bdc3eeb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
32 changes: 19 additions & 13 deletions recipe/build_base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,15 @@ else
DBG=
fi

ABIFLAGS=${DBG}
VERABI=${VER}${DBG}
if [[ ${PY_FREETHREADING} == yes ]]; then
# This Python will not be usable with non-free threading Python modules.
THREAD=t
else
THREAD=
fi

ABIFLAGS=${DBG}${THREAD}
VERABI=${VER}${ABIFLAGS}

# Make sure the "python" value in conda_build_config.yaml is up to date.
test "${PY_VER}" = "${VER}"
Expand All @@ -75,7 +82,7 @@ test "${PY_VER}" = "${VER}"
unset _PYTHON_SYSCONFIGDATA_NAME
unset _CONDA_PYTHON_SYSCONFIGDATA_NAME

# Prevent lib/python${VER}/_sysconfigdata_*.py from ending up with full paths to these things
# Prevent lib/python${VERABI}/_sysconfigdata_*.py from ending up with full paths to these things
# in _build_env because _build_env will not get found during prefix replacement, only _h_env_placeh ...
AR=$(basename "${AR}")

Expand Down Expand Up @@ -397,15 +404,15 @@ fi
SYSCONFIG=$(find ${_buildd_static}/$(cat ${_buildd_static}/pybuilddir.txt) -name "_sysconfigdata*.py" -print0)
cat ${SYSCONFIG} | ${SYS_PYTHON} "${RECIPE_DIR}"/replace-word-pairs.py \
"${_FLAGS_REPLACE[@]}" \
> ${PREFIX}/lib/python${VER}/$(basename ${SYSCONFIG})
MAKEFILE=$(find ${PREFIX}/lib/python${VER}/ -path "*config-*/Makefile" -print0)
> ${PREFIX}/lib/python${VERABI}/$(basename ${SYSCONFIG})
MAKEFILE=$(find ${PREFIX}/lib/python${VERABI}/ -path "*config-*/Makefile" -print0)
cp ${MAKEFILE} /tmp/Makefile-$$
cat /tmp/Makefile-$$ | ${SYS_PYTHON} "${RECIPE_DIR}"/replace-word-pairs.py \
"${_FLAGS_REPLACE[@]}" \
> ${MAKEFILE}
# Check to see that our differences took.
# echo diff -urN ${SYSCONFIG} ${PREFIX}/lib/python${VER}/$(basename ${SYSCONFIG})
# diff -urN ${SYSCONFIG} ${PREFIX}/lib/python${VER}/$(basename ${SYSCONFIG})
# echo diff -urN ${SYSCONFIG} ${PREFIX}/lib/python${VERABI}/$(basename ${SYSCONFIG})
# diff -urN ${SYSCONFIG} ${PREFIX}/lib/python${VERABI}/$(basename ${SYSCONFIG})

# Python installs python${VER}m and python${VER}, one as a hardlink to the other. conda-build breaks these
# by copying. Since the executable may be static it may be very large so change one to be a symlink
Expand All @@ -422,7 +429,7 @@ ln -s ${PREFIX}/bin/python${VER} ${PREFIX}/bin/python3.1
# Remove test data to save space
# Though keep `support` as some things use that.
# TODO :: Make a subpackage for this once we implement multi-level testing.
pushd ${PREFIX}/lib/python${VER}
pushd ${PREFIX}/lib/python${VERABI}
mkdir test_keep
mv test/__init__.py test/support test/test_support* test/test_script_helper* test_keep/
rm -rf test */test
Expand All @@ -435,7 +442,7 @@ pushd ${PREFIX}
chmod +w lib/libpython${VERABI}.a
${STRIP} -S lib/libpython${VERABI}.a
fi
CONFIG_LIBPYTHON=$(find lib/python${VER}/config-${VERABI}* -name "libpython${VERABI}.a")
CONFIG_LIBPYTHON=$(find lib/python${VERABI}/config-${VERABI}* -name "libpython${VERABI}.a")
if [[ -f lib/libpython${VERABI}.a ]] && [[ -f ${CONFIG_LIBPYTHON} ]]; then
chmod +w ${CONFIG_LIBPYTHON}
rm ${CONFIG_LIBPYTHON}
Expand All @@ -461,7 +468,7 @@ esac
# Copy sysconfig that gets recorded to a non-default name
# using the new compilers with python will require setting _PYTHON_SYSCONFIGDATA_NAME
# to the name of this file (minus the .py extension)
pushd "${PREFIX}"/lib/python${VER}
pushd "${PREFIX}"/lib/python${VERABI}
# On Python 3.5 _sysconfigdata.py was getting copied in here and compiled for some reason.
# This breaks our attempt to find the right one as recorded_name.
find lib-dynload -name "_sysconfigdata*.py*" -exec rm {} \;
Expand Down Expand Up @@ -542,6 +549,5 @@ if [[ "$target_platform" == linux-* ]]; then
rm ${PREFIX}/include/uuid.h
fi

# Workaround for old conda versions which fail to install noarch packages for Python 3.10+
# https://github.com/conda/conda/issues/10969
ln -s "${PREFIX}/lib/python${VER}" "${PREFIX}/lib/python3.1"
# See ${RECIPE_DIR}/sitecustomize.py
cp "${RECIPE_DIR}/sitecustomize.py" "${PREFIX}/lib/python${VER}/sitecustomize.py"
15 changes: 15 additions & 0 deletions recipe/sitecustomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import site, sys, os

dirs_to_add = []
# Workaround for https://github.com/conda/conda/issues/14053
if sys.abiflags != '':
dirs_to_add.append(os.path.join(sys.prefix, 'lib', f'python3.{sys.version_info[1]}', 'site-packages'))
# Workaround for https://github.com/conda/conda/issues/10969
dirs_to_add.append(os.path.join(sys.prefix, 'lib', f'python3.1', 'site-packages'))
# A python version independent directory that ABI3 and noarch packages can use.
# This is unused at the moment, but keeping it here for experimentation.
dirs_to_add.append(os.path.join(sys.prefix, 'lib', f'python', 'site-packages'))

for d in dirs_to_add:
if os.path.exists(d):
site.addsitedir(d)

0 comments on commit bdc3eeb

Please sign in to comment.