Skip to content

Commit ce1c49a

Browse files
authored
PYTHON-4646 Improve usage of hatch in evergreen (#2025)
1 parent fdcbe2e commit ce1c49a

File tree

11 files changed

+74
-64
lines changed

11 files changed

+74
-64
lines changed

.evergreen/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ functions:
4242
# Make an evergreen expansion file with dynamic values
4343
- command: subprocess.exec
4444
params:
45-
include_expansions_in_env: ["is_patch", "project", "version_id", "AUTH", "SSL", "test_encryption", "test_encryption_pyopenssl", "test_crypt_shared", "test_pyopenssl", "SETDEFAULTENCODING", "test_loadbalancer", "test_serverless", "SKIP_CSOT_TESTS", "MONGODB_STARTED", "DISABLE_TEST_COMMANDS", "GREEN_FRAMEWORK", "NO_EXT", "COVERAGE", "COMPRESSORS", "TEST_SUITES", "MONGODB_API_VERSION", "SKIP_HATCH", "skip_crypt_shared", "VERSION", "TOPOLOGY", "STORAGE_ENGINE", "ORCHESTRATION_FILE", "REQUIRE_API_VERSION", "LOAD_BALANCER", "skip_web_identity_auth_test", "skip_ECS_auth_test"]
45+
include_expansions_in_env: ["is_patch", "project", "version_id", "AUTH", "SSL", "test_encryption", "test_encryption_pyopenssl", "test_crypt_shared", "test_pyopenssl", "SETDEFAULTENCODING", "test_loadbalancer", "test_serverless", "SKIP_CSOT_TESTS", "MONGODB_STARTED", "DISABLE_TEST_COMMANDS", "GREEN_FRAMEWORK", "NO_EXT", "COVERAGE", "COMPRESSORS", "TEST_SUITES", "MONGODB_API_VERSION", "skip_crypt_shared", "VERSION", "TOPOLOGY", "STORAGE_ENGINE", "ORCHESTRATION_FILE", "REQUIRE_API_VERSION", "LOAD_BALANCER", "skip_web_identity_auth_test", "skip_ECS_auth_test"]
4646
binary: bash
4747
working_dir: "src"
4848
args:

.evergreen/generated_configs/variants.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ buildvariants:
88
- rhel79-small
99
batchtime: 10080
1010
expansions:
11-
SKIP_HATCH: "true"
1211
PYTHON_BINARY: /opt/python/3.9/bin/python3
1312
- name: other-hosts-rhel9-fips
1413
tasks:
@@ -17,35 +16,27 @@ buildvariants:
1716
run_on:
1817
- rhel92-fips
1918
batchtime: 10080
20-
expansions:
21-
SKIP_HATCH: "true"
2219
- name: other-hosts-rhel8-zseries
2320
tasks:
2421
- name: .6.0 .standalone !.sync_async
2522
display_name: Other hosts RHEL8-zseries
2623
run_on:
2724
- rhel8-zseries-small
2825
batchtime: 10080
29-
expansions:
30-
SKIP_HATCH: "true"
3126
- name: other-hosts-rhel8-power8
3227
tasks:
3328
- name: .6.0 .standalone !.sync_async
3429
display_name: Other hosts RHEL8-POWER8
3530
run_on:
3631
- rhel8-power-small
3732
batchtime: 10080
38-
expansions:
39-
SKIP_HATCH: "true"
4033
- name: other-hosts-rhel8-arm64
4134
tasks:
4235
- name: .6.0 .standalone !.sync_async
4336
display_name: Other hosts RHEL8-arm64
4437
run_on:
4538
- rhel82-arm64-small
4639
batchtime: 10080
47-
expansions:
48-
SKIP_HATCH: "true"
4940

5041
# Atlas connect tests
5142
- name: atlas-connect-rhel8-python3.9

.evergreen/hatch.sh

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,5 @@
11
#!/bin/bash
2-
set -o errexit # Exit the script with error if any of the commands fail
3-
set -x
2+
set -eu
43

5-
. .evergreen/utils.sh
6-
7-
if [ -z "$PYTHON_BINARY" ]; then
8-
PYTHON_BINARY=$(find_python3)
9-
fi
10-
11-
# Check if we should skip hatch and run the tests directly.
12-
if [ -n "$SKIP_HATCH" ]; then
13-
ENV_NAME=testenv-$RANDOM
14-
createvirtualenv "$PYTHON_BINARY" $ENV_NAME
15-
# shellcheck disable=SC2064
16-
trap "deactivate; rm -rf $ENV_NAME" EXIT HUP
17-
python -m pip install -e ".[test]"
18-
run_hatch() {
19-
bash ./.evergreen/run-tests.sh
20-
}
21-
else # Set up virtualenv before installing hatch
22-
# Use a random venv name because the encryption tasks run this script multiple times in the same run.
23-
ENV_NAME=hatchenv-$RANDOM
24-
createvirtualenv "$PYTHON_BINARY" $ENV_NAME
25-
# shellcheck disable=SC2064
26-
trap "deactivate; rm -rf $ENV_NAME" EXIT HUP
27-
python -m pip install -q hatch
28-
29-
# Ensure hatch does not write to user or global locations.
30-
touch hatch_config.toml
31-
HATCH_CONFIG=$(pwd)/hatch_config.toml
32-
if [ "Windows_NT" = "${OS:-}" ]; then # Magic variable in cygwin
33-
HATCH_CONFIG=$(cygpath -m "$HATCH_CONFIG")
34-
fi
35-
export HATCH_CONFIG
36-
hatch config restore
37-
hatch config set dirs.data "$(pwd)/.hatch/data"
38-
hatch config set dirs.cache "$(pwd)/.hatch/cache"
39-
40-
run_hatch() {
41-
python -m hatch run "$@"
42-
}
43-
fi
44-
45-
run_hatch "${@:1}"
4+
. .evergreen/scripts/ensure-hatch.sh
5+
hatch run "$@"

.evergreen/install-dependencies.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ cp ${PROJECT_DIRECTORY}/test/certificates/* ${DRIVERS_TOOLS}/.evergreen/x509gen/
88
# Replace MongoOrchestration's client certificate.
99
cp ${PROJECT_DIRECTORY}/test/certificates/client.pem ${MONGO_ORCHESTRATION_HOME}/lib/client.pem
1010

11+
# Ensure hatch is installed.
12+
bash ${PROJECT_DIRECTORY}/scripts/ensure-hatch.sh
13+
1114
if [ -w /etc/hosts ]; then
1215
SUDO=""
1316
else

.evergreen/run-mongodb-aws-ecs-test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ set -o xtrace
2222

2323
# Install python with pip.
2424
PYTHON_VER="python3.9"
25-
apt-get update
26-
apt-get install $PYTHON_VER python3-pip build-essential $PYTHON_VER-dev -y
25+
apt-get -qq update < /dev/null > /dev/null
26+
apt-get -qq install $PYTHON_VER $PYTHON_VER-venv build-essential $PYTHON_VER-dev -y < /dev/null > /dev/null
2727

2828
export PYTHON_BINARY=$PYTHON_VER
2929
export TEST_AUTH_AWS=1
3030
export AUTH="auth"
3131
export SET_XTRACE_ON=1
3232
cd src
33-
$PYTHON_BINARY -m pip install -q --user hatch
33+
rm -rf .venv
3434
bash .evergreen/hatch.sh test:test-eg

.evergreen/scripts/configure-env.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ fi
1111

1212
PROJECT_DIRECTORY="$(pwd)"
1313
DRIVERS_TOOLS="$(dirname $PROJECT_DIRECTORY)/drivers-tools"
14+
CARGO_HOME=${CARGO_HOME:-${DRIVERS_TOOLS}/.cargo}
1415

1516
# Python has cygwin path problems on Windows. Detect prospective mongo-orchestration home directory
1617
if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
1718
DRIVERS_TOOLS=$(cygpath -m $DRIVERS_TOOLS)
1819
PROJECT_DIRECTORY=$(cygpath -m $PROJECT_DIRECTORY)
20+
CARGO_HOME=$(cygpath -m $CARGO_HOME)
1921
fi
2022

2123
SCRIPT_DIR="$PROJECT_DIRECTORY/.evergreen/scripts"
@@ -47,13 +49,13 @@ export NO_EXT="${NO_EXT:-}"
4749
export COVERAGE="${COVERAGE:-}"
4850
export COMPRESSORS="${COMPRESSORS:-}"
4951
export MONGODB_API_VERSION="${MONGODB_API_VERSION:-}"
50-
export SKIP_HATCH="${SKIP_HATCH:-}"
5152
export skip_crypt_shared="${skip_crypt_shared:-}"
5253
export STORAGE_ENGINE="${STORAGE_ENGINE:-}"
5354
export REQUIRE_API_VERSION="${REQUIRE_API_VERSION:-}"
5455
export skip_web_identity_auth_test="${skip_web_identity_auth_test:-}"
5556
export skip_ECS_auth_test="${skip_ECS_auth_test:-}"
5657
58+
export CARGO_HOME="$CARGO_HOME"
5759
export TMPDIR="$MONGO_ORCHESTRATION_HOME/db"
5860
export PATH="$MONGODB_BINARIES:$PATH"
5961
# shellcheck disable=SC2154

.evergreen/scripts/ensure-hatch.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
# Ensure hatch is available.
6+
if [ ! -x "$(command -v hatch)" ]; then
7+
# Install a virtual env with "hatch"
8+
# Ensure there is a python venv.
9+
. .evergreen/utils.sh
10+
11+
if [ -z "${PYTHON_BINARY:-}" ]; then
12+
PYTHON_BINARY=$(find_python3)
13+
fi
14+
VENV_DIR=.venv
15+
if [ ! -d $VENV_DIR ]; then
16+
echo "Creating virtual environment..."
17+
createvirtualenv "$PYTHON_BINARY" .venv
18+
echo "Creating virtual environment... done."
19+
fi
20+
if [ -f $VENV_DIR/Scripts/activate ]; then
21+
. $VENV_DIR/Scripts/activate
22+
else
23+
. $VENV_DIR/bin/activate
24+
fi
25+
26+
python --version
27+
28+
echo "Installing hatch..."
29+
python -m pip install -U pip
30+
python -m pip install hatch || {
31+
# Install rust and try again.
32+
CARGO_HOME=${CARGO_HOME:-${DRIVERS_TOOLS}/.cargo}
33+
# Handle paths on Windows.
34+
if [ "Windows_NT" = "${OS:-}" ]; then # Magic variable in cygwin
35+
CARGO_HOME=$(cygpath -m $CARGO_HOME)
36+
fi
37+
export RUSTUP_HOME="${CARGO_HOME}/.rustup"
38+
${DRIVERS_TOOLS}/.evergreen/install-rust.sh
39+
source "${CARGO_HOME}/env"
40+
python -m pip install hatch
41+
}
42+
# Ensure hatch does not write to user or global locations.
43+
touch hatch_config.toml
44+
HATCH_CONFIG=$(pwd)/hatch_config.toml
45+
if [ "Windows_NT" = "${OS:-}" ]; then # Magic variable in cygwin
46+
HATCH_CONFIG=$(cygpath -m "$HATCH_CONFIG")
47+
fi
48+
export HATCH_CONFIG
49+
hatch config restore
50+
hatch config set dirs.data "$(pwd)/.hatch/data"
51+
hatch config set dirs.cache "$(pwd)/.hatch/cache"
52+
53+
echo "Installing hatch... done."
54+
fi
55+
hatch --version

.evergreen/scripts/generate_config.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,19 +744,17 @@ def create_aws_auth_variants():
744744

745745

746746
def create_alternative_hosts_variants():
747-
expansions = dict(SKIP_HATCH="true")
748747
batchtime = BATCHTIME_WEEK
749748
variants = []
750749

751750
host = HOSTS["rhel7"]
752751
variants.append(
753752
create_variant(
754753
[".5.0 .standalone !.sync_async"],
755-
get_display_name("OpenSSL 1.0.2", host, python=CPYTHONS[0], **expansions),
754+
get_display_name("OpenSSL 1.0.2", host, python=CPYTHONS[0]),
756755
host=host,
757756
python=CPYTHONS[0],
758757
batchtime=batchtime,
759-
expansions=expansions,
760758
)
761759
)
762760

@@ -765,8 +763,7 @@ def create_alternative_hosts_variants():
765763
variants.append(
766764
create_variant(
767765
[".6.0 .standalone !.sync_async"],
768-
display_name=get_display_name("Other hosts", host, **expansions),
769-
expansions=expansions,
766+
display_name=get_display_name("Other hosts", host),
770767
batchtime=batchtime,
771768
host=host,
772769
)

.evergreen/scripts/run-enterprise-auth-tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
# Disable xtrace for security reasons (just in case it was accidentally set).
44
set +x
5-
bash "${DRIVERS_TOOLS}"/.evergreen/auth_aws/setup_secrets.sh drivers/enterprise_auth
5+
# Use the default python to bootstrap secrets.
6+
PYTHON_BINARY="" bash "${DRIVERS_TOOLS}"/.evergreen/auth_aws/setup_secrets.sh drivers/enterprise_auth
67
TEST_ENTERPRISE_AUTH=1 AUTH=auth bash "${PROJECT_DIRECTORY}"/.evergreen/hatch.sh test:test-eg

.evergreen/scripts/run-tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,4 @@ GREEN_FRAMEWORK=${GREEN_FRAMEWORK} \
5151
TEST_DATA_LAKE=${TEST_DATA_LAKE:-} \
5252
TEST_SUITES=${TEST_SUITES:-} \
5353
MONGODB_API_VERSION=${MONGODB_API_VERSION} \
54-
SKIP_HATCH=${SKIP_HATCH} \
5554
bash "${PROJECT_DIRECTORY}"/.evergreen/hatch.sh test:test-eg

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ secrets-export.sh
2323
libmongocrypt.tar.gz
2424
libmongocrypt/
2525
libmongocrypt_git/
26+
hatch_config.toml
27+
.venv
2628

2729
# Lambda temp files
2830
test/lambda/.aws-sam

0 commit comments

Comments
 (0)