Skip to content

Commit 60ef3df

Browse files
committed
PYTHON-5040 Use uv run with PEP 723 inline metadata in gen-certs.py
1 parent 0385fa2 commit 60ef3df

3 files changed

Lines changed: 19 additions & 20 deletions

File tree

test/certificates/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ These certificates are used by the PyMongo test suite for TLS/SSL integration te
77
Run the generation script from this directory:
88

99
```bash
10-
bash gen-certs.sh
10+
uv run gen-certs.py
1111
```
1212

13-
**Prerequisites:** Python 3 with the `cryptography` package (`pip install cryptography`).
13+
**Prerequisites:** Python 3 and [uv](https://docs.astral.sh/uv/). The script declares its own dependency on `cryptography` via PEP 723 inline metadata, so `uv` installs it automatically.
1414

1515
## Certificate details
1616

test/certificates/gen-certs.py

100755100644
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#!/usr/bin/env python3
1+
# /// script
2+
# requires-python = ">=3.8"
3+
# dependencies = ["cryptography"]
4+
# ///
25
"""Generate TLS test certificates for the PyMongo test suite.
36
47
Two classes of leaf cert are generated:
@@ -27,8 +30,7 @@
2730
(CSSMERR_TP_CERT_SUSPENDED) because the CA is not in the system keychain.
2831
2932
Usage:
30-
pip install cryptography
31-
python gen-certs.py # run from test/certificates/
33+
uv run gen-certs.py # run from test/certificates/
3234
3335
Password for password_protected.pem: qwerty
3436
"""
@@ -39,19 +41,16 @@
3941
import sys
4042
from pathlib import Path
4143

42-
try:
43-
from cryptography import x509
44-
from cryptography.hazmat.primitives import hashes, serialization
45-
from cryptography.hazmat.primitives.asymmetric import rsa
46-
from cryptography.hazmat.primitives.serialization import (
47-
BestAvailableEncryption,
48-
Encoding,
49-
NoEncryption,
50-
PrivateFormat,
51-
)
52-
from cryptography.x509.oid import ExtendedKeyUsageOID, NameOID
53-
except ImportError:
54-
sys.exit("cryptography package is required: pip install cryptography")
44+
from cryptography import x509
45+
from cryptography.hazmat.primitives import hashes, serialization
46+
from cryptography.hazmat.primitives.asymmetric import rsa
47+
from cryptography.hazmat.primitives.serialization import (
48+
BestAvailableEncryption,
49+
Encoding,
50+
NoEncryption,
51+
PrivateFormat,
52+
)
53+
from cryptography.x509.oid import ExtendedKeyUsageOID, NameOID
5554

5655
SCRIPT_DIR = Path(__file__).parent.resolve()
5756
DAYS = 7300 # ~20 years

test/certificates/gen-certs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# See gen-certs.py for full documentation on the cert design.
44
#
55
# Usage: bash gen-certs.sh (run from test/certificates/)
6-
# Requires: pip install cryptography
6+
# Requires: uv
77

88
set -euo pipefail
99
cd "$(dirname "${BASH_SOURCE[0]}")"
10-
python3 gen-certs.py
10+
uv run gen-certs.py

0 commit comments

Comments
 (0)