Skip to content

Commit 3651496

Browse files
committed
Simplify justfile usage
1 parent ed041ae commit 3651496

File tree

10 files changed

+117
-94
lines changed

10 files changed

+117
-94
lines changed

.evergreen/hatch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22
set -eu
33

4-
. .evergreen/scripts/ensure-hatch.sh
4+
. .evergreen/scripts/setup-dev-env.sh
55
hatch run "$@"

.evergreen/scripts/configure-env.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ fi
1414
PROJECT_DIRECTORY="$(pwd)"
1515
DRIVERS_TOOLS="$(dirname $PROJECT_DIRECTORY)/drivers-tools"
1616
CARGO_HOME=${CARGO_HOME:-${DRIVERS_TOOLS}/.cargo}
17+
HATCH_CONFIG=$PROJECT_DIRECTORY/hatch_config.toml
1718

1819
# Python has cygwin path problems on Windows. Detect prospective mongo-orchestration home directory
1920
if [ "Windows_NT" = "${OS:-}" ]; then # Magic variable in cygwin
2021
DRIVERS_TOOLS=$(cygpath -m $DRIVERS_TOOLS)
2122
PROJECT_DIRECTORY=$(cygpath -m $PROJECT_DIRECTORY)
2223
CARGO_HOME=$(cygpath -m $CARGO_HOME)
24+
HATCH_CONFIG=$(cygpath -m "$HATCH_CONFIG")
2325
fi
2426

2527
SCRIPT_DIR="$PROJECT_DIRECTORY/.evergreen/scripts"
@@ -34,7 +36,6 @@ export MONGO_ORCHESTRATION_HOME="$DRIVERS_TOOLS/.evergreen/orchestration"
3436
export MONGODB_BINARIES="$DRIVERS_TOOLS/mongodb/bin"
3537

3638
cat <<EOT > "$SCRIPT_DIR"/env.sh
37-
set -o errexit
3839
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
3940
export CURRENT_VERSION="$CURRENT_VERSION"
4041
export SKIP_LEGACY_SHELL=1
@@ -59,6 +60,7 @@ export skip_ECS_auth_test="${skip_ECS_auth_test:-}"
5960
6061
export CARGO_HOME="$CARGO_HOME"
6162
export TMPDIR="$MONGO_ORCHESTRATION_HOME/db"
63+
export HATCH_CONFIG="$HATCH_CONFIG"
6264
export PATH="$MONGODB_BINARIES:$PATH"
6365
# shellcheck disable=SC2154
6466
export PROJECT="${project:-mongo-python-driver}"

.evergreen/scripts/ensure-hatch.sh

Lines changed: 0 additions & 63 deletions
This file was deleted.

.evergreen/scripts/setup-dev-env.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
HERE=$(dirname ${BASH_SOURCE:-$0})
6+
pushd "$(dirname "$(dirname $HERE)")" > /dev/null
7+
8+
# Source the env file to pick up common variables.
9+
if [ -f $HERE/scripts/env.sh ]; then
10+
source $HERE/scripts/env.sh
11+
fi
12+
13+
# Set the location of the python bin dir.
14+
if [ "Windows_NT" = "${OS:-}" ]; then
15+
BIN_DIR=.venv/Scripts
16+
else
17+
BIN_DIR=.venv/bin
18+
fi
19+
20+
# Ensure there is a python venv.
21+
if [ ! -d $BIN_DIR ]; then
22+
. .evergreen/utils.sh
23+
24+
if [ -z "${PYTHON_BINARY:-}" ]; then
25+
PYTHON_BINARY=$(find_python3)
26+
fi
27+
28+
echo "Creating virtual environment..."
29+
createvirtualenv "$PYTHON_BINARY" .venv
30+
echo "Creating virtual environment... done."
31+
fi
32+
33+
# Activate the virtual env.
34+
. $BIN_DIR/activate
35+
36+
# Ensure there is a local hatch.
37+
if [ ! -f $BIN_DIR/hatch ]; then
38+
echo "Installing hatch..."
39+
python -m pip install hatch || {
40+
# CARGO_HOME is defined in configure-env.sh
41+
export CARGO_HOME=${CARGO_HOME:-$HOME/.cargo/}
42+
export RUSTUP_HOME="${CARGO_HOME}/.rustup"
43+
${DRIVERS_TOOLS}/.evergreen/install-rust.sh
44+
source "${CARGO_HOME}/env"
45+
python -m pip install hatch
46+
}
47+
echo "Installing hatch... done."
48+
fi
49+
50+
# Ensure hatch does not write to user or global locations.
51+
HATCH_CONFIG=${HATCH_CONFIG:-hatch_config.toml}
52+
if [ ! -f ${HATCH_CONFIG} ]; then
53+
touch hatch_config.toml
54+
hatch config restore
55+
hatch config set dirs.data "$(pwd)/.hatch/data"
56+
hatch config set dirs.cache "$(pwd)/.hatch/cache"
57+
fi
58+
59+
# Ensure there is a local pre-commit.
60+
if [ ! -f $BIN_DIR/pre-commit ]; then
61+
python -m pip install pre-commit
62+
fi
63+
64+
# Ensure the pre-commit hook is installed.
65+
if [ ! -f .git/hooks/pre-commit ]; then
66+
pre-commit install
67+
fi
68+
69+
# Install pymongo and its test deps.
70+
python -m pip install ".[test]"

.evergreen/setup-spawn-host.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ rsync -az -e ssh --exclude '.git' --filter=':- .gitignore' -r . $target:$remote_
1616
echo "Copying files to $target... done"
1717

1818
ssh $target $remote_dir/.evergreen/scripts/setup-system.sh
19-
ssh $target "PYTHON_BINARY=${PYTHON_BINARY:-} $remote_dir/.evergreen/scripts/ensure-hatch.sh"
19+
ssh $target "PYTHON_BINARY=${PYTHON_BINARY:-} $remote_dir/.evergreen/scripts/setup-dev-env.sh"

.evergreen/utils.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/bin/bash -ex
1+
#!/bin/bash
22

3-
set -o xtrace
3+
set -eu
44

55
find_python3() {
66
PYTHON=""

.github/workflows/test-python.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ jobs:
2727
python-version: "3.9"
2828
cache: 'pip'
2929
cache-dependency-path: 'pyproject.toml'
30+
- name: Install just
31+
uses: extractions/setup-just@v2
3032
- name: Install Python dependencies
3133
run: |
32-
python -m pip install -U pip hatch rust-just pre-commit
34+
just install
3335
- name: Run linters
3436
run: |
3537
just lint-manual
@@ -73,18 +75,16 @@ jobs:
7375
cache: 'pip'
7476
cache-dependency-path: 'pyproject.toml'
7577
allow-prereleases: true
78+
- name: Install just
79+
uses: extractions/setup-just@v2
7680
- name: Install dependencies
7781
run: |
78-
pip install -U pip rust-just
79-
if [[ "${{ matrix.python-version }}" == "3.13" ]]; then
80-
pip install --pre cffi setuptools
81-
pip install --no-build-isolation hatch
82-
elif [[ "${{ matrix.python-version }}" == "3.13t" ]]; then
82+
if [[ "${{ matrix.python-version }}" == "3.13t" ]]; then
8383
# Hatch can't be installed on 3.13t, use pytest directly.
8484
pip install .
8585
pip install -r requirements/test.txt
8686
else
87-
pip install hatch
87+
just install
8888
fi
8989
- name: Start MongoDB
9090
uses: supercharge/[email protected]
@@ -111,9 +111,8 @@ jobs:
111111
python-version: "3.9"
112112
cache: 'pip'
113113
cache-dependency-path: 'pyproject.toml'
114-
- name: Install dependencies
115-
run: |
116-
pip install -U hatch pip rust-just
114+
- name: Install just
115+
uses: extractions/setup-just@v2
117116
- name: Start MongoDB
118117
uses: supercharge/[email protected]
119118
with:
@@ -135,9 +134,11 @@ jobs:
135134
cache-dependency-path: 'pyproject.toml'
136135
# Build docs on lowest supported Python for furo
137136
python-version: '3.9'
137+
- name: Install just
138+
uses: extractions/setup-just@v2
138139
- name: Install dependencies
139140
run: |
140-
pip install -U pip hatch rust-just
141+
just install
141142
- name: Build docs
142143
run: |
143144
just docs
@@ -155,9 +156,11 @@ jobs:
155156
cache-dependency-path: 'pyproject.toml'
156157
# Build docs on lowest supported Python for furo
157158
python-version: '3.9'
159+
- name: Install just
160+
uses: extractions/setup-just@v2
158161
- name: Install dependencies
159162
run: |
160-
pip install -U pip hatch rust-just
163+
just install
161164
- name: Build docs
162165
run: |
163166
just docs-linkcheck
@@ -177,9 +180,11 @@ jobs:
177180
python-version: "${{matrix.python}}"
178181
cache: 'pip'
179182
cache-dependency-path: 'pyproject.toml'
183+
- name: Install just
184+
uses: extractions/setup-just@v2
180185
- name: Install dependencies
181186
run: |
182-
pip install -U pip hatch rust-just
187+
just install
183188
- name: Run typecheck
184189
run: |
185190
just typing

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ libmongocrypt/
2525
libmongocrypt_git/
2626
hatch_config.toml
2727
.venv
28+
expansion.yml
29+
.evergreen/scripts/env.sh
2830

2931
# Lambda temp files
3032
test/lambda/.aws-sam

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ pre-commit run --all-files --hook-stage manual ruff
158158
Typically we use `just` to run the linters, e.g.
159159

160160
```bash
161+
just install # this will install a venv with pre-commit installed, and install the pre-commit hook.
161162
just typing-mypy
162163
just run lint-manual
163164
```
@@ -194,7 +195,8 @@ the pages will re-render and the browser will automatically refresh.
194195

195196
- Ensure you have started the appropriate Mongo Server(s).
196197
- Run `just install` to set up `hatch` in a local virtual environment, or you can manually
197-
create a virtual environment and run `pytest` directly.
198+
create a virtual environment and run `pytest` directly. If you want to use a specific
199+
version of Python, remove the `.venv` folder and set `PYTHON_BINARY` before running `just install`.
198200
- Run `just test` or `pytest` to run all of the tests.
199201
- Append `test/<mod_name>.py::<class_name>::<test_name>` to run
200202
specific tests. You can omit the `<test_name>` to test a full class

justfile

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,62 @@ set shell := ["bash", "-c"]
33
set dotenv-load
44
set dotenv-filename := "./.evergreen/scripts/env.sh"
55

6+
# Handle cross-platform paths to local python cli tools.
7+
python_bin_dir := if os_family() == "windows" { "./.venv/Scripts" } else { "./.venv/bin" }
8+
hatch_bin := python_bin_dir + "/hatch"
9+
pre_commit_bin := python_bin_dir + "/pre-commit"
10+
611
# Make the default recipe private so it doesn't show up in the list.
712
[private]
813
default:
914
@just --list
1015

1116
install:
12-
bash .evergreen/scripts/ensure-hatch.sh
17+
bash .evergreen/scripts/setup-dev-env.sh
1318

1419
[group('docs')]
1520
docs:
16-
source .evergreen/scripts/ensure-hatch.sh && hatch run doc:build
21+
{{hatch_bin}} run doc:build
1722

1823
[group('docs')]
1924
docs-serve:
20-
source .evergreen/scripts/ensure-hatch.sh && hatch run doc:serve
25+
{{hatch_bin}} run doc:serve
2126

2227
[group('docs')]
2328
docs-linkcheck:
24-
hatch run doc:linkcheck
29+
{{hatch_bin}} run doc:linkcheck
2530

2631
[group('docs')]
2732
docs-test:
28-
source .evergreen/scripts/ensure-hatch.sh && hatch run doctest:test
33+
{{hatch_bin}} run doctest:test
2934

3035
[group('typing')]
3136
typing:
32-
source .evergreen/scripts/ensure-hatch.sh && hatch run typing:check
37+
{{hatch_bin}} run typing:check
3338

3439
[group('typing')]
3540
typing-mypy:
36-
source .evergreen/scripts/ensure-hatch.sh && hatch run typing:mypy
41+
{{hatch_bin}} run typing:mypy
3742

3843
[group('lint')]
3944
lint:
40-
pre-commit run --all-files
45+
{{pre_commit_bin}} run --all-files
4146

4247
[group('lint')]
4348
lint-manual:
44-
pre-commit run --all-files --hook-stage manual
49+
{{pre_commit_bin}} run --all-files --hook-stage manual
4550

4651
[group('test')]
4752
test *args:
48-
source .evergreen/scripts/ensure-hatch.sh && hatch run test:test {{args}}
53+
{{hatch_bin}} run test:test {{args}}
4954

5055
[group('test')]
5156
test-mockupdb:
52-
source .evergreen/scripts/ensure-hatch.sh && hatch run test:test-mockupdb
57+
{{hatch_bin}} run test:test-mockupdb
5358

5459
[group('test')]
5560
test-eg *args:
56-
source .evergreen/scripts/ensure-hatch.sh && hatch run test:test-eg {{args}}
61+
{{hatch_bin}} run test:test-eg {{args}}
5762

5863
[group('encryption')]
5964
setup-encryption:

0 commit comments

Comments
 (0)