Skip to content

CDRIVER-6042 Migrate Python scripts from Poetry to Astral UV #2039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions .evergreen/config_generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,22 @@
The scripts in this directory are used to generate the Evergreen configuration
files stored in `.evergreen/generated_configs/`.

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

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


## Setting Up

Before running, use Poetry to install a virtualenv containing the dependencies.
This can be done by using the `poetry.sh` (or `poetry.ps1`) script contained in
the `tools/` directory at the root of the `mongo-c-driver` repository:

```sh
./tools/poetry.sh install --with=dev
```

Or with PowerShell:

```pwsh
./tools/poetry.ps1 install --with=dev
```
`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`.


## Running the Generator

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

```sh
./tools/poetry.sh run mc-evg-generate
uv run --frozen mc-evg-generate
```

This command will ready the generation files and generate a new set of Evergreen
Expand Down
16 changes: 3 additions & 13 deletions .evergreen/config_generator/components/clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,24 @@
from shrub.v3.evg_task import EvgTask
from shrub.v3.evg_task import EvgTaskRef

from config_generator.etc.distros import find_large_distro
from config_generator.etc.distros import find_small_distro
from config_generator.etc.function import Function
from config_generator.etc.utils import bash_exec


TAG = "clang-format"

DISTROS = [
find_large_distro("ubuntu2204").name,
find_large_distro("ubuntu2004").name,
]


class ClangFormat(Function):
name = TAG
commands = [
bash_exec(
command_type=EvgCommandType.SETUP,
working_dir="mongoc",
script="./tools/poetry.sh install --with=dev"
),
bash_exec(
command_type=EvgCommandType.TEST,
working_dir="mongoc",
env={
"DRYRUN": "1",
},
script="./tools/poetry.sh run .evergreen/scripts/clang-format-all.sh",
script="uv run --frozen --only-group format .evergreen/scripts/clang-format-all.sh",
),
]

Expand All @@ -56,7 +46,7 @@ def variants():
BuildVariant(
name=TAG,
display_name=TAG,
run_on=DISTROS,
run_on=[find_small_distro("ubuntu2204").name],
tasks=[EvgTaskRef(name=f'.{TAG}')],
),
]
6 changes: 2 additions & 4 deletions .evergreen/config_generator/components/make_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ class MakeDocs(Function):
working_dir="mongoc",
include_expansions_in_env=["distro_id"],
script="""\
set -o errexit
./tools/poetry.sh install --with=docs
# See SphinxBuild.cmake for EVG_DOCS_BUILD reasoning
./tools/poetry.sh run env EVG_DOCS_BUILD=1 .evergreen/scripts/build-docs.sh
""",
uv run --frozen --only-group docs env EVG_DOCS_BUILD=1 .evergreen/scripts/build-docs.sh
""",
),
]

Expand Down
14 changes: 2 additions & 12 deletions .evergreen/generated_configs/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ functions:
- -c
- .evergreen/scripts/check-preludes.py .
clang-format:
- command: subprocess.exec
type: setup
params:
binary: bash
working_dir: mongoc
args:
- -c
- ./tools/poetry.sh install --with=dev
- command: subprocess.exec
type: test
params:
Expand All @@ -131,7 +123,7 @@ functions:
DRYRUN: "1"
args:
- -c
- ./tools/poetry.sh run .evergreen/scripts/clang-format-all.sh
- uv run --frozen --only-group format .evergreen/scripts/clang-format-all.sh
cse-sasl-cyrus-darwinssl-compile:
- command: expansions.update
params:
Expand Down Expand Up @@ -313,10 +305,8 @@ functions:
args:
- -c
- |
set -o errexit
./tools/poetry.sh install --with=docs
# See SphinxBuild.cmake for EVG_DOCS_BUILD reasoning
./tools/poetry.sh run env EVG_DOCS_BUILD=1 .evergreen/scripts/build-docs.sh
uv run --frozen --only-group docs env EVG_DOCS_BUILD=1 .evergreen/scripts/build-docs.sh
openssl-static-compile:
- command: subprocess.exec
type: test
Expand Down
3 changes: 1 addition & 2 deletions .evergreen/generated_configs/variants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ buildvariants:
- name: clang-format
display_name: clang-format
run_on:
- ubuntu2204-large
- ubuntu2004-large
- ubuntu2204-small
tasks:
- name: .clang-format
- name: cse-matrix-darwinssl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@
"An OrderedDict of YAML values"


try:
import yaml
import yamlordereddictloader # type: ignore
except ImportError:
sys.stderr.write("try 'poetry install --with=dev'\n")
raise
import yaml
import yamlloader


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


class _Dumper(yamlordereddictloader.Dumper):
class _Dumper(yamlloader.ordereddict.Dumper):
def __init__(self, *args: Value, **kwargs: Value):
super().__init__(*args, **kwargs) # type: ignore
self.add_representer(set, type(self).represent_set)
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/scripts/build-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CMAKE=$(find_cmake_latest)
grep "á" NEWS > /dev/null || (echo "NEWS file appears to have lost its UTF-8 encoding?" || exit 1)

build_dir=$MONGOC_DIR/_build/for-docs
"$CMAKE" -S "$MONGOC_DIR" -B "$build_dir" \
"$CMAKE" --fresh -S "$MONGOC_DIR" -B "$build_dir" \
-D ENABLE_MAN_PAGES=ON \
-D ENABLE_HTML_DOCS=ON \
-D ENABLE_ZLIB=BUNDLED
Expand Down
7 changes: 3 additions & 4 deletions .evergreen/scripts/clang-format-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
# clang-format-all.sh
#
# Usage:
# ./tools/poetry.sh install --with=dev
# ./tools/poetry.sh run .evergreen/scripts/clang-format-all.sh
# DRYRUN=1 ./tools/poetry.sh run .evergreen/scripts/clang-format-all.sh
# ./tools/poetry.sh run env DRYRUN=1 .evergreen/scripts/clang-format-all.sh
# uv run --frozen .evergreen/scripts/clang-format-all.sh
# DRYRUN=1 uv run --frozen .evergreen/scripts/clang-format-all.sh
# uv run --frozen env DRYRUN=1 .evergreen/scripts/clang-format-all.sh
#
# This script is meant to be run from the project root directory.

Expand Down
20 changes: 5 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,17 @@ a block comment like the following:
Public functions do not need these comment blocks, since they are documented in
the .rst files.

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

```sh
./tools/poetry.sh install --with=docs
```

Then, execute `sphinx-build` in the Python environment, using the paths to the
documentation to be generated:

```sh
./tools/poetry.sh run sphinx-build -WEn -bhtml src/libmongoc/doc/ src/libmongoc/doc/html
```bash
uv run --frozen sphinx-build -WEn -bhtml src/libmongoc/doc/ src/libmongoc/doc/html
```

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

```sh
./tools/poetry.sh run sphinx-autobuild -b html src/libmongoc/doc/ src/libmongoc/doc/html --re-ignore ".*.pickle" --re-ignore ".*.doctree" -j auto
```bash
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
```

### Testing
Expand Down
2 changes: 1 addition & 1 deletion build/sphinx/mongoc_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def generate_html_redirs(app: Sphinx, page: str, templatename: str, context: Dic
return
if page == "index" or page.endswith(".index"):
return
path = app.project.doc2path(page, absolute=True)
path = app.project.doc2path(page, True)
out_index_html = Path(builder.get_outfilename(page))
slug = out_index_html.parent.name
redirect_file = out_index_html.parent.parent / f"{slug}.html"
Expand Down
18 changes: 4 additions & 14 deletions docs/dev/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,16 @@ default: html
THIS_FILE := $(realpath $(lastword $(MAKEFILE_LIST)))
THIS_DIR := $(shell dirname $(THIS_FILE))
MONGOC_DIR := $(shell dirname $(shell dirname $(THIS_DIR)))
TOOLS_DIR := $(MONGOC_DIR)/tools


POETRY := bash $(TOOLS_DIR)/poetry.sh -C $(MONGOC_DIR)

BUILD_DIR := $(MONGOC_DIR)/_build
_poetry_stamp := $(BUILD_DIR)/.poetry-install.stamp
poetry-install: $(_poetry_stamp)
$(_poetry_stamp): $(MONGOC_DIR)/poetry.lock $(MONGOC_DIR)/pyproject.toml
$(POETRY) install --with=dev,docs
mkdir -p $(BUILD_DIR)
touch $@

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

DOCS_SRC := $(THIS_DIR)
DOCS_OUT := $(BUILD_DIR)/docs/dev/html
html: poetry-install
$(POETRY) run sphinx-build $(SPHINX_ARGS) $(DOCS_SRC) $(DOCS_OUT)
html:
uv run --frozen sphinx-build $(SPHINX_ARGS) $(DOCS_SRC) $(DOCS_OUT)

serve: poetry-install
$(POETRY) run sphinx-autobuild $(SPHINX_ARGS) $(DOCS_SRC) $(DOCS_OUT)
serve:
uv run --frozen --with sphinx-autobuild sphinx-autobuild $(SPHINX_ARGS) $(DOCS_SRC) $(DOCS_OUT)
Loading