nixpkgs/pkgs/development/python-modules/pytest-forked/setup-hook.sh
Yueh-Shun Li 054c5f0e10 treewide: handle preDistPhases __structuredAttrs-agnostically
Always specify the preDistPhases attribute as a list instead of a string.

Append elements to the preDistPhases Bash variable using appendToVar
instead of string or Bash array concatenation.

Handle element insertion before a specific element using string
substitution as before, but handle both structured and unstructured
attributes.
2024-09-03 05:33:59 +08:00

33 lines
1.1 KiB
Bash

pytestForkedHook() {
pytestFlagsArray+=(
"--forked"
)
# Using --forked on darwin leads to crashes when fork safety is
# enabled. This often happens when urllib tries to request proxy
# settings on MacOS through `urllib.request.getproxies()`
# - https://github.com/python/cpython/issues/77906
if [[ "$OSTYPE" == "darwin"* ]]; then
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
fi
}
# the flags should be added before pytestCheckHook runs so
# until we have dependency mechanism in generic builder, we need to use this ugly hack.
if [ -z "${dontUsePytestForked-}" ] && [ -z "${dontUsePytestCheck-}" ]; then
if [[ " ${preDistPhases[*]:-} " =~ " pytestCheckPhase " ]]; then
_preDistPhases="${preDistPhases[*]} "
_preDistPhases="${_preDistPhases/ pytestCheckPhase / pytestForkedHook pytestCheckPhase }"
if [[ -n "${__structuredAttrs-}" ]]; then
preDistPhases=()
else
preDistPhases=""
fi
appendToVar preDistPhases $_preDistPhases
unset _preDistPhases
else
appendToVar preDistPhases pytestForkedHook
fi
fi