Skip to content

Commit 5b63135

Browse files
committed
TOOLS-4102 Use mise to manage our Python install
This also adds a `requirements.txt` file with the Python packages we need.
1 parent 4f2e904 commit 5b63135

6 files changed

Lines changed: 81 additions & 47 deletions

File tree

CONTRIBUTING.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,67 @@ If you're interested in contributing, we have a list of some suggested tickets t
1212
to get started on
1313
[here](https://jira.mongodb.org/issues/?jql=project%20%3D%20TOOLS%20AND%20labels%20%3D%20community%20and%20status%20%3D%20open)
1414

15+
## Dev Tools (mise)
16+
17+
We use [`mise`](https://mise.jdx.dev/) to manage dev tools (Go, Node, Python, linters, formatters,
18+
etc.), ensuring every developer and CI run uses the same versions.
19+
20+
### Installing mise
21+
22+
To install mise, run this command:
23+
24+
```
25+
MISE_VERSION=$( cat ./scripts/mise-version.txt ) sh scripts/mise.run.sh
26+
```
27+
28+
Then run:
29+
30+
```
31+
# Enable the Go backend
32+
mise settings experimental=true
33+
# Trust the config in this repo
34+
mise trust
35+
# Install all dev tools (Go, Node, Python, linters, etc.)
36+
mise install
37+
# Install Node packages needed by eslint, prettier, etc.
38+
npm install
39+
```
40+
41+
After `mise install`, all tools (including `go`) are available directly in your shell when you're in
42+
this repo's directory. See [the mise docs](https://mise.jdx.dev/) for details on shell integration.
43+
44+
### Adding a new tool
45+
46+
Run `mise use github:some-org/some-tool@1.2.3`. We use the `github` backend for tools that provide
47+
binary releases. For Go tools without binary releases, use `go:some/package@vX.Y.Z`.
48+
49+
## Using Mise
50+
51+
You can integrate `mise` with your shell so that dev tools are automatically added to your `PATH`
52+
when your working directory is in the Mongosync repo. See [the `mise` docs](https://mise.jdx.dev/)
53+
for more details on this.
54+
55+
If you _don't_ want to use that integration, you can instead use
56+
`mise exec <list of tools> -- some-tool` to run the tools managed by `mise`, so something like
57+
`mise exec go -- go version`. It's important to list the tools that `mise exec` needs. Without that
58+
list, it will attempt to install _all_ the tools in our `mise.toml` when you run `mise exec`. This
59+
is generally fine locally, but can cause problems in CI, where many of the tools we use cannot be
60+
installed on some of the platforms we use.
61+
62+
### In CI
63+
64+
We do not set up the shell integration when installing `mise` in CI. That means that anything in CI
65+
which needs to run Go or another dev tool should use `mise exec go -- go ...` or a similar
66+
invocation.
67+
68+
### Writing Code that Runs Dev Tools
69+
70+
You may want to write code that uses these tools, either as a script for use in CI or some other
71+
case.
72+
73+
All programmatic tool invocations should use `mise exec <tool>`. This will work in CI as well as
74+
locally.
75+
1576
## Getting Started
1677

1778
1. Create a [MongoDB JIRA account](https://jira.mongodb.org/secure/Signup!default.jspa).

common.yml

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -491,28 +491,9 @@ functions:
491491
# The aws_e2e_assume_role script requires python3 with boto3.
492492
# Set up or use an existing python virtualenv for boto3.
493493
venv='venv'
494-
venvNonWindows () { . "$venv"/bin/activate; python3 -m pip install boto3; }
495-
venvWindows () { . "$venv"/Scripts/activate; pip install boto3; }
496-
497-
# default to python3 inside mongodbtoolchain
498-
PATH=/opt/mongodbtoolchain/v3/bin/:$PATH
499-
500-
if [ -f "$venv"/bin/activate ]; then
501-
echo 'activating existing virtualenv'
502-
venvNonWindows
503-
elif [ -f "$venv"/Scripts/activate ]; then
504-
echo 'activating existing virtualenv'
505-
venvWindows
506-
elif virtualenv "$venv" || python -m virtualenv "$venv"; then
507-
echo 'creating new virtualenv'
508-
if [ -f "$venv"/bin/activate ]; then
509-
echo 'activating new virtualenv'
510-
venvNonWindows
511-
elif [ -f "$venv"/Scripts/activate ]; then
512-
echo 'activating new virtualenv'
513-
venvWindows
514-
fi
515-
fi
494+
mise exec python -- python3 -m venv "$venv"
495+
. "$venv"/bin/activate
496+
pip install boto3
516497
517498
pip list
518499
@@ -528,8 +509,9 @@ functions:
528509
set -v
529510
set -e
530511
512+
# There's no need to use mise here, since this will work with any version of Python.
531513
jsonkey () { python -c "import sys, json; sys.stdout.write(json.load(sys.stdin)['$1'])" < creds.json; }
532-
urlencode () { python -c "import sys, urllib as ul; sys.stdout.write(ul.quote_plus('$1'))"; }
514+
urlencode () { python -c "import sys, urllib.parse as ul; sys.stdout.write(ul.quote_plus('$1'))"; }
533515
534516
USER=$(jsonkey AccessKeyId)
535517
USER=$(urlencode $USER)
@@ -655,8 +637,6 @@ pre:
655637
- command: expansions.update
656638
params:
657639
updates:
658-
- key: python
659-
value: "/opt/mongodbtoolchain/v4/bin/python3"
660640
- key: resmoke_dir
661641
value: "src/resmoke"
662642
- key: resmoke_venv_dir

mise.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ node = "22.22.0"
1919
"npm:prettier" = "3.4.2"
2020
"npm:github-codeowners" = "0.2.1"
2121

22+
# Python
23+
python = "3.12.9"
24+
2225
[settings.node]
2326
# We turn off GPG verification for node because it has been flaky in CI, and also requires a local
2427
# GPG public key.

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
boto3
2+
pymongo==3.12.1
3+
pywin32; sys_platform == "win32"
4+
pyyaml

scripts/run_native_cert_ssl.sh

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
1515
sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain jstests/libs/trusted-ca.pem
1616
fi
1717

18-
PATH=/opt/mongodbtoolchain/v3/bin/:$PATH
19-
python="python3"
20-
if [ "Windows_NT" = "$OS" ]; then
21-
python="py.exe -3"
22-
fi
23-
$python -m venv venv
24-
pip3 install pymongo==3.12.1 pyyaml
25-
if [ "Windows_NT" = "$OS" ]; then
26-
pip3 install pywin32
27-
fi
28-
$python buildscripts/resmoke.py --suite=native_cert_ssl --continueOnFailure --log=buildlogger --reportFile=../../report.json ${resmoke_args} --excludeWithAnyTags="${excludes}"
18+
mise exec python -- python3 -m venv venv
19+
. venv/bin/activate
20+
pip install -r ../../requirements.txt
21+
python3 buildscripts/resmoke.py --suite=native_cert_ssl --continueOnFailure --log=buildlogger --reportFile=../../report.json ${resmoke_args} --excludeWithAnyTags="${excludes}"

scripts/run_qa.sh

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ mv bin/* test/qa-tests/
99
cd test/qa-tests
1010
chmod 400 jstests/libs/key*
1111

12-
PATH=/opt/mongodbtoolchain/v3/bin/:$PATH
13-
python="python3"
14-
if [ "Windows_NT" = "$OS" ]; then
15-
python="py.exe -3"
16-
fi
17-
$python -m venv venv
18-
pip3 install pymongo==3.12.1 pyyaml
19-
if [ "Windows_NT" = "$OS" ]; then
20-
pip3 install pywin32
21-
fi
22-
$python buildscripts/resmoke.py --suite=${resmoke_suite} --continueOnFailure --log=buildlogger --reportFile=../../report.json ${resmoke_args} --excludeWithAnyTags="${excludes}"
12+
mise exec python -- python3 -m venv venv
13+
. venv/bin/activate
14+
pip install -r ../../requirements.txt
15+
python3 buildscripts/resmoke.py --suite=${resmoke_suite} --continueOnFailure --log=buildlogger --reportFile=../../report.json ${resmoke_args} --excludeWithAnyTags="${excludes}"

0 commit comments

Comments
 (0)