Skip to content

Commit 19f806d

Browse files
committed
build: don't allow setuptools to sneakily install build-time deps
see https://pip.pypa.io/en/stable/reference/pip_install/#controlling-setup-requires > Setuptools offers the setup_requires setup() keyword for specifying > dependencies that need to be present in order for the setup.py > script to run. Internally, Setuptools uses easy_install to > fulfill these dependencies. > pip has no way to control how these dependencies are located. > None of the package index options have an effect. With these changes, we will now instead hard fail if this were to happen. related: #5859 (comment)
1 parent a83805e commit 19f806d

File tree

6 files changed

+36
-0
lines changed

6 files changed

+36
-0
lines changed

contrib/build-linux/appimage/build.sh

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ python='appdir_python'
9494
info "installing pip."
9595
"$python" -m ensurepip
9696

97+
break_legacy_easy_install
98+
9799

98100
info "preparing electrum-locale."
99101
(

contrib/build-linux/sdist/build.sh

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ DISTDIR="$PROJECT_ROOT/dist"
1212
# note that at least py3.7 is needed, to have https://bugs.python.org/issue30693
1313
python3 --version || fail "python interpreter not found"
1414

15+
break_legacy_easy_install
16+
1517
# upgrade to modern pip so that it knows the flags we need.
1618
# we will then install a pinned version of pip as part of requirements-build-sdist
1719
python3 -m pip install --upgrade pip

contrib/build-wine/prepare-wine.sh

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ for msifile in core dev exe lib pip tools; do
6060
wine msiexec /i "$PYTHON_DOWNLOADS/${msifile}.msi" /qb TARGETDIR=$PYHOME
6161
done
6262

63+
break_legacy_easy_install
64+
6365
info "Installing build dependencies."
6466
$PYTHON -m pip install --no-dependencies --no-warn-script-location -r "$CONTRIB"/deterministic-build/requirements-build-wine.txt
6567

contrib/build_tools_util.sh

+22
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,25 @@ fi
129129

130130
export GCC_STRIP_BINARIES="${GCC_STRIP_BINARIES:-0}"
131131

132+
133+
function break_legacy_easy_install() {
134+
# We don't want setuptools sneakily installing dependencies, invisible to pip.
135+
# This ensures that if setuptools calls distutils which then calls easy_install,
136+
# easy_install will not download packages over the network.
137+
# see https://pip.pypa.io/en/stable/reference/pip_install/#controlling-setup-requires
138+
# see https://github.com/pypa/setuptools/issues/1916#issuecomment-743350566
139+
info "Intentionally breaking legacy easy_install."
140+
DISTUTILS_CFG="${HOME}/.pydistutils.cfg"
141+
DISTUTILS_CFG_BAK="${HOME}/.pydistutils.cfg.orig"
142+
# If we are not inside docker, we might be overwriting a config file on the user's system...
143+
if [ -e "$DISTUTILS_CFG" ] && [ ! -e "$DISTUTILS_CFG_BAK" ]; then
144+
warn "Overwriting python distutils config file at '$DISTUTILS_CFG'. A copy will be saved at '$DISTUTILS_CFG_BAK'."
145+
mv "$DISTUTILS_CFG" "$DISTUTILS_CFG_BAK"
146+
fi
147+
cat <<EOF > "$DISTUTILS_CFG"
148+
[easy_install]
149+
index_url = ''
150+
find_links = ''
151+
EOF
152+
}
153+

contrib/osx/make_osx

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install -s $PYTHON_VERSION && \
7272
pyenv global $PYTHON_VERSION || \
7373
fail "Unable to use Python $PYTHON_VERSION"
7474

75+
break_legacy_easy_install
76+
7577
# create a fresh virtualenv
7678
# This helps to avoid older versions of pip-installed dependencies interfering with the build.
7779
VENV_DIR="$CONTRIB_OSX/build-venv"

setup.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[easy_install]
2+
# We don't want setuptools sneakily installing dependencies, invisible to pip.
3+
# see https://pip.pypa.io/en/stable/reference/pip_install/#controlling-setup-requires
4+
# see https://github.com/pypa/setuptools/issues/1916#issuecomment-743350566
5+
index_url = ''
6+
find_links = ''

0 commit comments

Comments
 (0)