Skip to content

Commit cbc2db8

Browse files
committed
PYTHON-4975 Use justfile as the task runner
1 parent 6c9a20a commit cbc2db8

File tree

5 files changed

+144
-90
lines changed

5 files changed

+144
-90
lines changed

.evergreen/scripts/ensure-hatch.sh

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,57 @@ set -eu
55
HERE=$(dirname ${BASH_SOURCE:-$0})
66
pushd "$(dirname "$(dirname $HERE)")" > /dev/null
77

8-
# Ensure hatch is available.
9-
if [ ! -x "$(command -v hatch)" ]; then
10-
# Install a virtual env with "hatch"
11-
# Ensure there is a python venv.
12-
. .evergreen/utils.sh
13-
14-
if [ -z "${PYTHON_BINARY:-}" ]; then
15-
PYTHON_BINARY=$(find_python3)
16-
fi
17-
VENV_DIR=.venv
18-
if [ ! -d $VENV_DIR ]; then
19-
echo "Creating virtual environment..."
20-
createvirtualenv "$PYTHON_BINARY" .venv
21-
echo "Creating virtual environment... done."
22-
fi
23-
if [ -f $VENV_DIR/Scripts/activate ]; then
24-
. $VENV_DIR/Scripts/activate
25-
else
26-
. $VENV_DIR/bin/activate
27-
fi
8+
# Ensure hatch is available locally.
9+
VENV_DIR=.venv
10+
if [ -f $VENV_DIR/Scripts/hatch ]; then
11+
return 0
12+
fi
13+
if [ -f $VENV_DIR/bin/hatch ]; then
14+
return 0
15+
fi
16+
17+
# Install a virtual env with "hatch"
18+
# Ensure there is a python venv.
19+
. .evergreen/utils.sh
2820

29-
python --version
30-
31-
echo "Installing hatch..."
32-
python -m pip install -U pip
33-
python -m pip install hatch || {
34-
# Install rust and try again.
35-
CARGO_HOME=${CARGO_HOME:-${DRIVERS_TOOLS}/.cargo}
36-
# Handle paths on Windows.
37-
if [ "Windows_NT" = "${OS:-}" ]; then # Magic variable in cygwin
38-
CARGO_HOME=$(cygpath -m $CARGO_HOME)
39-
fi
40-
export RUSTUP_HOME="${CARGO_HOME}/.rustup"
41-
${DRIVERS_TOOLS}/.evergreen/install-rust.sh
42-
source "${CARGO_HOME}/env"
43-
python -m pip install hatch
44-
}
45-
# Ensure hatch does not write to user or global locations.
46-
touch hatch_config.toml
47-
HATCH_CONFIG=$(pwd)/hatch_config.toml
21+
if [ -z "${PYTHON_BINARY:-}" ]; then
22+
PYTHON_BINARY=$(find_python3)
23+
fi
24+
25+
if [ ! -d $VENV_DIR ]; then
26+
echo "Creating virtual environment..."
27+
createvirtualenv "$PYTHON_BINARY" .venv
28+
echo "Creating virtual environment... done."
29+
fi
30+
if [ -f $VENV_DIR/Scripts/activate ]; then
31+
. $VENV_DIR/Scripts/activate
32+
else
33+
. $VENV_DIR/bin/activate
34+
fi
35+
36+
echo "Installing hatch..."
37+
python -m pip install -U pip
38+
python -m pip install hatch || {
39+
# Install rust and try again.
40+
CARGO_HOME=${CARGO_HOME:-${DRIVERS_TOOLS}/.cargo}
41+
# Handle paths on Windows.
4842
if [ "Windows_NT" = "${OS:-}" ]; then # Magic variable in cygwin
49-
HATCH_CONFIG=$(cygpath -m "$HATCH_CONFIG")
43+
CARGO_HOME=$(cygpath -m $CARGO_HOME)
5044
fi
51-
export HATCH_CONFIG
52-
hatch config restore
53-
hatch config set dirs.data "$(pwd)/.hatch/data"
54-
hatch config set dirs.cache "$(pwd)/.hatch/cache"
55-
56-
echo "Installing hatch... done."
45+
export RUSTUP_HOME="${CARGO_HOME}/.rustup"
46+
${DRIVERS_TOOLS}/.evergreen/install-rust.sh
47+
source "${CARGO_HOME}/env"
48+
python -m pip install hatch
49+
}
50+
# Ensure hatch does not write to user or global locations.
51+
touch hatch_config.toml
52+
HATCH_CONFIG=$(pwd)/hatch_config.toml
53+
if [ "Windows_NT" = "${OS:-}" ]; then # Magic variable in cygwin
54+
HATCH_CONFIG=$(cygpath -m "$HATCH_CONFIG")
5755
fi
58-
hatch --version
59-
popd > /dev/null
56+
export HATCH_CONFIG
57+
hatch config restore
58+
hatch config set dirs.data "$(pwd)/.hatch/data"
59+
hatch config set dirs.cache "$(pwd)/.hatch/cache"
60+
61+
echo "Installing hatch... done."

.github/workflows/test-python.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ jobs:
2929
cache-dependency-path: 'pyproject.toml'
3030
- name: Install Python dependencies
3131
run: |
32-
python -m pip install -U pip hatch
32+
python -m pip install -U pip hatch rust-just
3333
- name: Run linters
3434
run: |
35-
hatch run lint:run-manual
35+
just-manual
3636
- name: Run compilation
3737
run: |
3838
export PYMONGO_C_EXT_MUST_BUILD=1
3939
pip install -v -e .
4040
python tools/fail_if_no_c.py
4141
- name: Run typecheck
4242
run: |
43-
hatch run typing:check
43+
just typing
4444
- run: |
4545
sudo apt-get install -y cppcheck
4646
- run: |
@@ -75,7 +75,7 @@ jobs:
7575
allow-prereleases: true
7676
- name: Install dependencies
7777
run: |
78-
pip install -U pip
78+
pip install -U pip rust-just
7979
if [[ "${{ matrix.python-version }}" == "3.13" ]]; then
8080
pip install --pre cffi setuptools
8181
pip install --no-build-isolation hatch
@@ -95,7 +95,7 @@ jobs:
9595
if [[ "${{ matrix.python-version }}" == "3.13t" ]]; then
9696
pytest -v --durations=5 --maxfail=10
9797
else
98-
hatch run test:test
98+
just test
9999
fi
100100
101101
doctest:
@@ -113,14 +113,14 @@ jobs:
113113
cache-dependency-path: 'pyproject.toml'
114114
- name: Install dependencies
115115
run: |
116-
pip install -U hatch pip
116+
pip install -U hatch pip rust-just
117117
- name: Start MongoDB
118118
uses: supercharge/[email protected]
119119
with:
120120
mongodb-version: '8.0.0-rc4'
121121
- name: Run tests
122122
run: |
123-
hatch run doctest:test
123+
just doctest
124124
125125
docs:
126126
name: Docs Checks
@@ -137,10 +137,10 @@ jobs:
137137
python-version: '3.9'
138138
- name: Install dependencies
139139
run: |
140-
pip install -U pip hatch
140+
pip install -U pip hatch rust-just
141141
- name: Build docs
142142
run: |
143-
hatch run doc:build
143+
just docs
144144
145145
linkcheck:
146146
name: Link Check
@@ -160,7 +160,7 @@ jobs:
160160
pip install -U pip hatch
161161
- name: Build docs
162162
run: |
163-
hatch run doc:linkcheck
163+
just docs-linkcheck
164164
165165
typing:
166166
name: Typing Tests
@@ -179,10 +179,10 @@ jobs:
179179
cache-dependency-path: 'pyproject.toml'
180180
- name: Install dependencies
181181
run: |
182-
pip install -U pip hatch
182+
pip install -U pip hatch rust-just
183183
- name: Run typecheck
184184
run: |
185-
hatch run typing:check
185+
just typing
186186
187187
make_sdist:
188188
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ including 4 space indents and 79 character line limits.
2828

2929
- Avoid backward breaking changes if at all possible.
3030
- Write inline documentation for new classes and methods.
31-
- We use [hatch](https://hatch.pypa.io/dev/) for our script runner and packaging tool.
31+
- We use [hatch](https://hatch.pypa.io/dev/) for python environment management and packaging.
32+
- We use [just](https://just.systems/man/en/) as our task runner.
3233
- Write tests and make sure they pass (make sure you have a mongod
33-
running on the default port, then execute `hatch run test:test` from the cmd
34+
running on the default port, then execute `just test` from the cmd
3435
line to run the test suite).
3536
- Add yourself to doc/contributors.rst `:)`
3637

@@ -148,17 +149,17 @@ To run `pre-commit` manually, run:
148149
pre-commit run --all-files
149150
```
150151

151-
To run a manual hook like `mypy` manually, run:
152+
To run a manual hook like `ruff` manually, run:
152153

153154
```bash
154-
pre-commit run --all-files --hook-stage manual mypy
155+
pre-commit run --all-files --hook-stage manual ruff
155156
```
156157

157-
Typically we use `hatch` to run the linters, e.g.
158+
Typically we use `just` to run the linters, e.g.
158159

159160
```bash
160-
hatch run typing:check-mypy
161-
hatch run lint:build-manual
161+
just typing-mypy
162+
just run lint-manual
162163
```
163164

164165
## Documentation
@@ -176,13 +177,13 @@ documentation including narrative docs, and the [Sphinx docstring format](https:
176177
You can build the documentation locally by running:
177178

178179
```bash
179-
hatch run doc:build
180+
just docs-build
180181
```
181182

182183
When updating docs, it can be helpful to run the live docs server as:
183184

184185
```bash
185-
hatch run doc:serve
186+
just docs-serve
186187
```
187188

188189
Browse to the link provided, and then as you make changes to docstrings or narrative docs,
@@ -192,13 +193,13 @@ the pages will re-render and the browser will automatically refresh.
192193
## Running Tests Locally
193194

194195
- Ensure you have started the appropriate Mongo Server(s).
195-
- Run `pip install hatch` to use `hatch` for testing or run
196-
`pip install -e ".[test]"` to run `pytest` directly.
197-
- Run `hatch run test:test` or `pytest` to run all of the tests.
196+
- 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+
- Run `just test` or `pytest` to run all of the tests.
198199
- Append `test/<mod_name>.py::<class_name>::<test_name>` to run
199200
specific tests. You can omit the `<test_name>` to test a full class
200201
and the `<class_name>` to test a full module. For example:
201-
`hatch run test:test -- test/test_change_stream.py::TestUnifiedChangeStreamsErrors::test_change_stream_errors_on_ElectionInProgress`.
202+
`just test test/test_change_stream.py::TestUnifiedChangeStreamsErrors::test_change_stream_errors_on_ElectionInProgress`.
202203
- Use the `-k` argument to select tests by pattern.
203204

204205
## Running Load Balancer Tests Locally
@@ -211,15 +212,15 @@ the pages will re-render and the browser will automatically refresh.
211212
- Start the load balancer using:
212213
`MONGODB_URI='mongodb://localhost:27017,localhost:27018/' $PWD/drivers-evergreen-tools/.evergreen/run-load-balancer.sh start`.
213214
- Run the tests from the `pymongo` checkout directory using:
214-
`TEST_LOADBALANCER=1 hatch run test:test-eg`.
215+
`TEST_LOADBALANCER=1 just test-eg`.
215216

216217
## Running Encryption Tests Locally
217218
- Clone `drivers-evergreen-tools`:
218219
`git clone [email protected]:mongodb-labs/drivers-evergreen-tools.git`.
219220
- Run `export DRIVERS_TOOLS=$PWD/drivers-evergreen-tools`
220-
- Run `AWS_PROFILE=<profile> hatch run encryption:setup` after setting up your AWS profile with `aws configure sso`.
221-
- Run the tests with `TEST_ENCRYPTION=1 hatch run test:test-eg`.
222-
- When done, run `hatch run encryption:teardown` to clean up.
221+
- Run `AWS_PROFILE=<profile> just setup-encryption` after setting up your AWS profile with `aws configure sso`.
222+
- Run the tests with `TEST_ENCRYPTION=1 just test-eg`.
223+
- When done, run `just teardown-encryption` to clean up.
223224

224225
## Re-sync Spec Tests
225226

hatch.toml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,10 @@ check-strict-pyright = [
3030
]
3131
check = ["check-mypy", "check-pyright", "check-strict-pyright"]
3232

33-
[envs.lint]
34-
skip-install = true
35-
dependencies = ["pre-commit"]
36-
[envs.lint.scripts]
37-
run = "pre-commit run --all-files"
38-
run-manual = "pre-commit run --all-files --hook-stage manual"
39-
4033
[envs.test]
4134
features = ["test"]
4235
[envs.test.scripts]
4336
test = "pytest -v --durations=5 --maxfail=10 {args}"
4437
test-eg = "bash ./.evergreen/run-tests.sh {args}"
4538
test-async = "pytest -v --durations=5 --maxfail=10 -m default_async {args}"
4639
test-mockupdb = ["pip install -U git+https://github.com/mongodb-labs/mongo-mockup-db@master", "test -m mockupdb"]
47-
48-
[envs.encryption]
49-
skip-install = true
50-
[envs.encryption.scripts]
51-
setup = "bash .evergreen/setup-encryption.sh"
52-
teardown = "bash .evergreen/teardown-encryption.sh"

justfile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# See https://just.systems/man/en/ for instructions
2+
set shell := ["bash", "-c"]
3+
set dotenv-load
4+
set dotenv-filename := "./.evergreen/scripts/env.sh"
5+
6+
# Make the default recipe private so it doesn't show up in the list.
7+
[private]
8+
default:
9+
@just --list
10+
11+
install:
12+
bash .evergreen/scripts/ensure-hatch.sh
13+
14+
[group('docs')]
15+
docs-build:
16+
source .evergreen/scripts/ensure-hatch.sh && hatch run doc:build
17+
18+
[group('docs')]
19+
docs-serve:
20+
source .evergreen/scripts/ensure-hatch.sh && hatch run doc:serve
21+
22+
[group('docs')]
23+
docs-linkcheck:
24+
hatch run doc:linkcheck
25+
26+
[group('docs')]
27+
docs-test:
28+
source .evergreen/scripts/ensure-hatch.sh && hatch run doctest:test
29+
30+
[group('typing')]
31+
typing:
32+
source .evergreen/scripts/ensure-hatch.sh && hatch run typing:check
33+
34+
[group('typing')]
35+
typing-mypy:
36+
source .evergreen/scripts/ensure-hatch.sh && hatch run typing:mypy
37+
38+
[group('lint')]
39+
lint:
40+
pre-commit run --all-files
41+
42+
[group('lint')]
43+
lint-manual:
44+
pre-commit run --all-files --hook-stage manual
45+
46+
[group('test')]
47+
test *args:
48+
source .evergreen/scripts/ensure-hatch.sh && hatch run test:test {{args}}
49+
50+
[group('test')]
51+
test-mockupdb:
52+
source .evergreen/scripts/ensure-hatch.sh && hatch run test:test-mockupdb
53+
54+
[group('test')]
55+
test-eg *args:
56+
source .evergreen/scripts/ensure-hatch.sh && hatch run test:test-eg {{args}}
57+
58+
[group('encryption')]
59+
setup-encryption:
60+
bash .evergreen/setup-encryption.sh
61+
62+
[group('encryption')]
63+
teardown-encryption:
64+
bash .evergreen/teardown-encryption.sh

0 commit comments

Comments
 (0)