Skip to content

Commit 3adeef5

Browse files
authored
CDRIVER-6042 Migrate Python scripts from Poetry to Astral UV (#2039)
1 parent 504cba9 commit 3adeef5

File tree

19 files changed

+862
-1410
lines changed

19 files changed

+862
-1410
lines changed

.evergreen/config_generator/README.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,22 @@
33
The scripts in this directory are used to generate the Evergreen configuration
44
files stored in `.evergreen/generated_configs/`.
55

6-
The easiest way to execute these scripts is using the Poetry to install the
7-
dependencies and then run the scripts.
6+
The easiest way to execute these scripts is to use [uv](https://docs.astral.sh/uv/) to run the scripts.
87

98
**Note**: These scripts require Python 3.10 or newer.
109

1110

1211
## Setting Up
1312

14-
Before running, use Poetry to install a virtualenv containing the dependencies.
15-
This can be done by using the `poetry.sh` (or `poetry.ps1`) script contained in
16-
the `tools/` directory at the root of the `mongo-c-driver` repository:
17-
18-
```sh
19-
./tools/poetry.sh install --with=dev
20-
```
21-
22-
Or with PowerShell:
23-
24-
```pwsh
25-
./tools/poetry.ps1 install --with=dev
26-
```
13+
`uv` is required to run Python scripts. See ["Installing uv"](https://docs.astral.sh/uv/getting-started/installation/) for instructions on how to obtain `uv`.
2714

2815

2916
## Running the Generator
3017

31-
The package defines a program `mc-evg-generate`, which can be run within the
32-
virtualenv. This can be done via Poetry as well, following the setup:
18+
The package provides the `mc-evg-generate` [entry point](https://packaging.python.org/en/latest/specifications/entry-points):
3319

3420
```sh
35-
./tools/poetry.sh run mc-evg-generate
21+
uv run --frozen mc-evg-generate
3622
```
3723

3824
This command will ready the generation files and generate a new set of Evergreen

.evergreen/config_generator/components/clang_format.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,24 @@
33
from shrub.v3.evg_task import EvgTask
44
from shrub.v3.evg_task import EvgTaskRef
55

6-
from config_generator.etc.distros import find_large_distro
6+
from config_generator.etc.distros import find_small_distro
77
from config_generator.etc.function import Function
88
from config_generator.etc.utils import bash_exec
99

1010

1111
TAG = "clang-format"
1212

13-
DISTROS = [
14-
find_large_distro("ubuntu2204").name,
15-
find_large_distro("ubuntu2004").name,
16-
]
17-
1813

1914
class ClangFormat(Function):
2015
name = TAG
2116
commands = [
22-
bash_exec(
23-
command_type=EvgCommandType.SETUP,
24-
working_dir="mongoc",
25-
script="./tools/poetry.sh install --with=dev"
26-
),
2717
bash_exec(
2818
command_type=EvgCommandType.TEST,
2919
working_dir="mongoc",
3020
env={
3121
"DRYRUN": "1",
3222
},
33-
script="./tools/poetry.sh run .evergreen/scripts/clang-format-all.sh",
23+
script="uv run --frozen --only-group format .evergreen/scripts/clang-format-all.sh",
3424
),
3525
]
3626

@@ -56,7 +46,7 @@ def variants():
5646
BuildVariant(
5747
name=TAG,
5848
display_name=TAG,
59-
run_on=DISTROS,
49+
run_on=[find_small_distro("ubuntu2204").name],
6050
tasks=[EvgTaskRef(name=f'.{TAG}')],
6151
),
6252
]

.evergreen/config_generator/components/make_docs.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ class MakeDocs(Function):
1717
working_dir="mongoc",
1818
include_expansions_in_env=["distro_id"],
1919
script="""\
20-
set -o errexit
21-
./tools/poetry.sh install --with=docs
2220
# See SphinxBuild.cmake for EVG_DOCS_BUILD reasoning
23-
./tools/poetry.sh run env EVG_DOCS_BUILD=1 .evergreen/scripts/build-docs.sh
24-
""",
21+
uv run --frozen --only-group docs env EVG_DOCS_BUILD=1 .evergreen/scripts/build-docs.sh
22+
""",
2523
),
2624
]
2725

.evergreen/generated_configs/functions.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,6 @@ functions:
114114
- -c
115115
- .evergreen/scripts/check-preludes.py .
116116
clang-format:
117-
- command: subprocess.exec
118-
type: setup
119-
params:
120-
binary: bash
121-
working_dir: mongoc
122-
args:
123-
- -c
124-
- ./tools/poetry.sh install --with=dev
125117
- command: subprocess.exec
126118
type: test
127119
params:
@@ -131,7 +123,7 @@ functions:
131123
DRYRUN: "1"
132124
args:
133125
- -c
134-
- ./tools/poetry.sh run .evergreen/scripts/clang-format-all.sh
126+
- uv run --frozen --only-group format .evergreen/scripts/clang-format-all.sh
135127
cse-sasl-cyrus-darwinssl-compile:
136128
- command: expansions.update
137129
params:
@@ -313,10 +305,8 @@ functions:
313305
args:
314306
- -c
315307
- |
316-
set -o errexit
317-
./tools/poetry.sh install --with=docs
318308
# See SphinxBuild.cmake for EVG_DOCS_BUILD reasoning
319-
./tools/poetry.sh run env EVG_DOCS_BUILD=1 .evergreen/scripts/build-docs.sh
309+
uv run --frozen --only-group docs env EVG_DOCS_BUILD=1 .evergreen/scripts/build-docs.sh
320310
openssl-static-compile:
321311
- command: subprocess.exec
322312
type: test

.evergreen/generated_configs/variants.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ buildvariants:
8686
- name: clang-format
8787
display_name: clang-format
8888
run_on:
89-
- ubuntu2204-large
90-
- ubuntu2004-large
89+
- ubuntu2204-small
9190
tasks:
9291
- name: .clang-format
9392
- name: cse-matrix-darwinssl

.evergreen/legacy_config_generator/evergreen_config_generator/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@
3636
"An OrderedDict of YAML values"
3737

3838

39-
try:
40-
import yaml
41-
import yamlordereddictloader # type: ignore
42-
except ImportError:
43-
sys.stderr.write("try 'poetry install --with=dev'\n")
44-
raise
39+
import yaml
40+
import yamlloader
4541

4642

4743
class ConfigObject(object):
@@ -68,7 +64,7 @@ def to_dict(self) -> Value:
6864
# tag sets as lists.
6965

7066

71-
class _Dumper(yamlordereddictloader.Dumper):
67+
class _Dumper(yamlloader.ordereddict.Dumper):
7268
def __init__(self, *args: Value, **kwargs: Value):
7369
super().__init__(*args, **kwargs) # type: ignore
7470
self.add_representer(set, type(self).represent_set)

.evergreen/scripts/build-docs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CMAKE=$(find_cmake_latest)
1010
grep "á" NEWS > /dev/null || (echo "NEWS file appears to have lost its UTF-8 encoding?" || exit 1)
1111

1212
build_dir=$MONGOC_DIR/_build/for-docs
13-
"$CMAKE" -S "$MONGOC_DIR" -B "$build_dir" \
13+
"$CMAKE" --fresh -S "$MONGOC_DIR" -B "$build_dir" \
1414
-D ENABLE_MAN_PAGES=ON \
1515
-D ENABLE_HTML_DOCS=ON \
1616
-D ENABLE_ZLIB=BUNDLED

.evergreen/scripts/clang-format-all.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
# clang-format-all.sh
44
#
55
# Usage:
6-
# ./tools/poetry.sh install --with=dev
7-
# ./tools/poetry.sh run .evergreen/scripts/clang-format-all.sh
8-
# DRYRUN=1 ./tools/poetry.sh run .evergreen/scripts/clang-format-all.sh
9-
# ./tools/poetry.sh run env DRYRUN=1 .evergreen/scripts/clang-format-all.sh
6+
# uv run --frozen .evergreen/scripts/clang-format-all.sh
7+
# DRYRUN=1 uv run --frozen .evergreen/scripts/clang-format-all.sh
8+
# uv run --frozen env DRYRUN=1 .evergreen/scripts/clang-format-all.sh
109
#
1110
# This script is meant to be run from the project root directory.
1211

CONTRIBUTING.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,27 +111,17 @@ a block comment like the following:
111111
Public functions do not need these comment blocks, since they are documented in
112112
the .rst files.
113113

114-
To build the documentation, it is recommended to use the Poetry-managed Python
115-
project to ensure that the exact tooling versions match. If you do not have
116-
Poetry installed, you can use the `poetry.sh` or `poetry.ps1` scripts in the
117-
`tools/` directory. First, install dependencies:
114+
To build the documentation, it is recommended to run Sphinx commands through `uv`:
118115

119-
```sh
120-
./tools/poetry.sh install --with=docs
121-
```
122-
123-
Then, execute `sphinx-build` in the Python environment, using the paths to the
124-
documentation to be generated:
125-
126-
```sh
127-
./tools/poetry.sh run sphinx-build -WEn -bhtml src/libmongoc/doc/ src/libmongoc/doc/html
116+
```bash
117+
uv run --frozen sphinx-build -WEn -bhtml src/libmongoc/doc/ src/libmongoc/doc/html
128118
```
129119

130120
`sphinx-autobuild` can be used to serve docs locally. This can be convenient when editing. Files are rebuilt
131121
when changes are detected:
132122

133-
```sh
134-
./tools/poetry.sh run sphinx-autobuild -b html src/libmongoc/doc/ src/libmongoc/doc/html --re-ignore ".*.pickle" --re-ignore ".*.doctree" -j auto
123+
```bash
124+
uv run --frozen --with 'sphinx-autobuild' sphinx-autobuild -b html src/libmongoc/doc/ src/libmongoc/doc/html --re-ignore ".*.pickle" --re-ignore ".*.doctree" -j auto
135125
```
136126

137127
### Testing

build/sphinx/mongoc_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def generate_html_redirs(app: Sphinx, page: str, templatename: str, context: Dic
146146
return
147147
if page == "index" or page.endswith(".index"):
148148
return
149-
path = app.project.doc2path(page, absolute=True)
149+
path = app.project.doc2path(page, True)
150150
out_index_html = Path(builder.get_outfilename(page))
151151
slug = out_index_html.parent.name
152152
redirect_file = out_index_html.parent.parent / f"{slug}.html"

docs/dev/Makefile

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,16 @@ default: html
77
THIS_FILE := $(realpath $(lastword $(MAKEFILE_LIST)))
88
THIS_DIR := $(shell dirname $(THIS_FILE))
99
MONGOC_DIR := $(shell dirname $(shell dirname $(THIS_DIR)))
10-
TOOLS_DIR := $(MONGOC_DIR)/tools
11-
12-
13-
POETRY := bash $(TOOLS_DIR)/poetry.sh -C $(MONGOC_DIR)
1410

1511
BUILD_DIR := $(MONGOC_DIR)/_build
16-
_poetry_stamp := $(BUILD_DIR)/.poetry-install.stamp
17-
poetry-install: $(_poetry_stamp)
18-
$(_poetry_stamp): $(MONGOC_DIR)/poetry.lock $(MONGOC_DIR)/pyproject.toml
19-
$(POETRY) install --with=dev,docs
20-
mkdir -p $(BUILD_DIR)
21-
touch $@
2212

2313
SPHINX_JOBS ?= auto
2414
SPHINX_ARGS := -W -n -j "$(SPHINX_JOBS)" -a -b dirhtml
2515

2616
DOCS_SRC := $(THIS_DIR)
2717
DOCS_OUT := $(BUILD_DIR)/docs/dev/html
28-
html: poetry-install
29-
$(POETRY) run sphinx-build $(SPHINX_ARGS) $(DOCS_SRC) $(DOCS_OUT)
18+
html:
19+
uv run --frozen sphinx-build $(SPHINX_ARGS) $(DOCS_SRC) $(DOCS_OUT)
3020

31-
serve: poetry-install
32-
$(POETRY) run sphinx-autobuild $(SPHINX_ARGS) $(DOCS_SRC) $(DOCS_OUT)
21+
serve:
22+
uv run --frozen --with sphinx-autobuild sphinx-autobuild $(SPHINX_ARGS) $(DOCS_SRC) $(DOCS_OUT)

0 commit comments

Comments
 (0)