Skip to content

PYTHON-2345 Ensure release files can be installed #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion .evergreen/build-mac.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/bash -ex

# Get access to testinstall.
. .evergreen/utils.sh

# Create temp directory for validated files.
rm -rf validdist
mkdir -p validdist
mv dist/* validdist || true

for VERSION in 2.7 3.4 3.5 3.6 3.7 3.8; do
if [[ $VERSION == "2.7" ]]; then
PYTHON=/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Expand All @@ -9,7 +17,27 @@ for VERSION in 2.7 3.4 3.5 3.6 3.7 3.8; do
PYTHON=/Library/Frameworks/Python.framework/Versions/$VERSION/bin/python3
fi
rm -rf build
$PYTHON setup.py bdist_wheel

# Install wheel if not already there.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was needed to fix this error:

+ /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python setup.py bdist_wheel
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
  warnings.warn(msg)
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help
error: invalid command 'bdist_wheel'

https://evergreen.mongodb.com/task/mongo_python_driver_Release__platform~macos_1014_release_patch_e1915fc89ba01f4f22f2a3ad1074978ff0fdf5b4_5f6145e1562343460ae4523e_20_09_15_22_53_41

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a FIXME/TODO in case this is expected to be fixed by an upcoming BUILD ticket?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I opened https://jira.mongodb.org/browse/PYTHON-2375 and https://jira.mongodb.org/browse/BUILD-11842. Since it's tracked in Jira I don't think we need to add a TODO in code.

if ! $PYTHON -m wheel version; then
createvirtualenv $PYTHON releasevenv
WHEELPYTHON=python
pip install --upgrade wheel
else
WHEELPYTHON=$PYTHON
fi

$WHEELPYTHON setup.py bdist_wheel
deactivate || true
rm -rf releasevenv

# Test that each wheel is installable.
for release in dist/*; do
testinstall $PYTHON $release
mv $release validdist/
done
done

mv validdist/* dist
rm -rf validdist
ls dist
45 changes: 31 additions & 14 deletions .evergreen/build-manylinux-internal.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
#!/bin/bash -ex
cd /pymongo
cd /src

# Get access to testinstall.
. .evergreen/utils.sh

# Create temp directory for validated files.
rm -rf validdist
mkdir -p validdist
mv dist/* validdist || true

# Compile wheels
for PYBIN in /opt/python/*/bin; do
for PYTHON in /opt/python/*/bin/python; do
# Skip Python 3.3 and 3.9.
if [[ "$PYBIN" == *"cp33"* || "$PYBIN" == *"cp39"* ]]; then
if [[ "$PYTHON" == *"cp33"* || "$PYTHON" == *"cp39"* ]]; then
continue
fi
# https://github.com/pypa/manylinux/issues/49
rm -rf build
${PYBIN}/python setup.py bdist_wheel
done
$PYTHON setup.py bdist_wheel
rm -rf build

# https://github.com/pypa/manylinux/issues/49
rm -rf build
# Audit wheels and write multilinux tag
for whl in dist/*.whl; do
# Skip already built manylinux1 wheels.
if [[ "$whl" != *"manylinux"* ]]; then
auditwheel repair $whl -w dist
rm $whl
fi
done

# Audit wheels and write multilinux1 tag
for whl in dist/*.whl; do
# Skip already built manylinux1 wheels.
if [[ "$whl" != *"manylinux"* ]]; then
auditwheel repair $whl -w dist
rm $whl
fi
# Test that each wheel is installable.
# Test without virtualenv because it's not present on manylinux containers.
for release in dist/*; do
testinstall $PYTHON $release "without-virtualenv"
mv $release validdist/
done
done

mv validdist/* dist
rm -rf validdist
ls dist
2 changes: 1 addition & 1 deletion .evergreen/build-manylinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ images=(quay.io/pypa/manylinux1_x86_64:2020-03-20-2fda31c \

for image in "${images[@]}"; do
docker pull $image
docker run --rm -v `pwd`:/pymongo $image /pymongo/.evergreen/build-manylinux-internal.sh
docker run --rm -v `pwd`:/src $image /src/.evergreen/build-manylinux-internal.sh
done

ls dist
Expand Down
36 changes: 25 additions & 11 deletions .evergreen/build-windows.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
#!/bin/bash -ex

# Get access to testinstall.
. .evergreen/utils.sh

# Create temp directory for validated files.
rm -rf validdist
mkdir -p validdist
mv dist/* validdist || true

for VERSION in 27 34 35 36 37 38; do
PYTHON=C:/Python/Python${VERSION}/python.exe
PYTHON32=C:/Python/32/Python${VERSION}/python.exe
if [[ $VERSION == "2.7" ]]; then
_pythons=(C:/Python/Python${VERSION}/python.exe \
C:/Python/32/Python${VERSION}/python.exe)
for PYTHON in "${_pythons[@]}"; do
if [[ $VERSION == "2.7" ]]; then
rm -rf build
$PYTHON setup.py bdist_egg
fi
rm -rf build
$PYTHON setup.py bdist_egg
rm -rf build
$PYTHON32 setup.py bdist_egg
fi
rm -rf build
$PYTHON setup.py bdist_wheel
rm -rf build
$PYTHON32 setup.py bdist_wheel
$PYTHON setup.py bdist_wheel

# Test that each wheel is installable.
for release in dist/*; do
testinstall $PYTHON $release
mv $release validdist/
done
done
done

mv validdist/* dist
rm -rf validdist
ls dist
55 changes: 55 additions & 0 deletions .evergreen/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash -ex

# Usage:
# createvirtualenv /path/to/python /output/path/for/venv
# * param1: Python binary to use for the virtualenv
# * param2: Path to the virtualenv to create
function createvirtualenv {
PYTHON=$1
VENVPATH=$2
if $PYTHON -m virtualenv --version; then
VIRTUALENV="$PYTHON -m virtualenv"
elif command -v virtualenv; then
VIRTUALENV="$(command -v virtualenv) -p $PYTHON"
else
echo "Cannot test without virtualenv"
exit 1
fi
$VIRTUALENV --system-site-packages --never-download $VENVPATH
if [ "Windows_NT" = "$OS" ]; then
. $VENVPATH/Scripts/activate
else
. $VENVPATH/bin/activate
fi
}

# Usage:
# testinstall /path/to/python /path/to/.whl/or/.egg ["no-virtualenv"]
# * param1: Python binary to test
# * param2: Path to the wheel or egg file to install
# * param3 (optional): If set to a non-empty string, don't create a virtualenv. Used in manylinux containers.
function testinstall {
PYTHON=$1
RELEASE=$2
NO_VIRTUALENV=$3

if [ -z "$NO_VIRTUALENV" ]; then
createvirtualenv $PYTHON venvtestinstall
PYTHON=python
fi

if [[ $RELEASE == *.egg ]]; then
$PYTHON -m easy_install $RELEASE
else
$PYTHON -m pip install --upgrade $RELEASE
fi
cd tools
$PYTHON fail_if_no_c.py
$PYTHON -m pip uninstall -y pymongo
cd ..

if [ -z "$NO_VIRTUALENV" ]; then
deactivate
rm -rf venvtestinstall
fi
}