Skip to content

Commit 1f8bb31

Browse files
committed
chore: port build tooling to uv
This commit replaces the existing build-tooling with uv. In addition, all CI operations are captured in scripts to make it easier to run linting, formatting, unit tests, and system tests locally without having to remember the exact set of commands. Fixes #443.
1 parent 327e773 commit 1f8bb31

17 files changed

Lines changed: 179 additions & 193 deletions

File tree

.github/workflows/coverage.yaml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,14 @@ jobs:
3333
with:
3434
python-version: "3.14"
3535

36-
- run: pip install nox coverage
36+
- name: Install uv
37+
uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
3738

3839
- name: Checkout PR branch
3940
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4041
with:
4142
ref: ${{ github.event.pull_request.head.sha }}
4243
repository: ${{ github.event.pull_request.head.repo.full_name }}
4344

44-
- name: Calculate PR code coverage
45-
run: |
46-
nox --sessions unit-3.14
47-
coverage report --show-missing
48-
export PR_COVER=$(coverage report | awk '$1 == "TOTAL" {print $NF+0}')
49-
echo "PR_COVER=$PR_COVER" >> $GITHUB_ENV
50-
coverage erase
51-
52-
- name: Verify code coverage. If your reading this and the step has failed, please add tests to cover your changes.
53-
run: |
54-
echo "PULL REQUEST CODE COVERAGE is ${{ env.PR_COVER }}%"
55-
if [ "${{ env.PR_COVER }}" -lt "90" ]; then
56-
exit 1;
57-
fi
45+
- name: Verify code coverage
46+
run: ./scripts/coverage.sh

.github/workflows/lint.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ jobs:
3434
with:
3535
python-version: "3.14"
3636

37-
- name: Install nox
38-
run: pip install nox
37+
- name: Install uv
38+
uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
3939

4040
- name: Checkout code
4141
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4242
with:
4343
ref: ${{ github.event.pull_request.head.sha }}
4444
repository: ${{ github.event.pull_request.head.repo.full_name }}
4545

46-
- name: Run nox lint session
47-
run: nox -s lint
46+
- name: Run lint
47+
run: ./scripts/lint.sh

.github/workflows/tests.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ jobs:
5252
with:
5353
python-version: ${{ matrix.python-version }}
5454

55-
- name: Install nox
56-
run: pip install nox
55+
- name: Install uv
56+
uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
5757

5858
- id: 'auth'
5959
name: Authenticate to Google Cloud
@@ -66,7 +66,8 @@ jobs:
6666
access_token_lifetime: 600s
6767

6868
- name: Run tests
69-
run: nox -s unit-${{ matrix.python-version }}
69+
shell: bash
70+
run: ./scripts/test_unit.sh
7071

7172
- name: FlakyBot (Linux)
7273
# only run flakybot on periodic (schedule) and continuous (push) events
@@ -118,8 +119,8 @@ jobs:
118119
with:
119120
python-version: ${{ matrix.python-version }}
120121

121-
- name: Install nox
122-
run: pip install nox
122+
- name: Install uv
123+
uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
123124

124125
- id: 'auth'
125126
name: 'Authenticate to Google Cloud'
@@ -149,7 +150,7 @@ jobs:
149150
ALLOYDB_INSTANCE_IP: '${{ steps.secrets.outputs.ALLOYDB_INSTANCE_IP }}'
150151
ALLOYDB_INSTANCE_URI: '${{ steps.secrets.outputs.ALLOYDB_INSTANCE_URI }}'
151152
ALLOYDB_PSC_INSTANCE_URI: '${{ steps.secrets.outputs.ALLOYDB_PSC_INSTANCE_URI }}'
152-
run: nox -s system-${{ matrix.python-version }}
153+
run: ./scripts/test_system.sh
153154

154155
- name: FlakyBot (Linux)
155156
# only run flakybot on periodic (schedule) and continuous (push) events

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ docs.metadata
5050

5151
# Virtual environment
5252
env/
53+
.venv
54+
55+
# uv lock file (library — consumers resolve their own deps)
56+
uv.lock
5357

5458
# Test logs
5559
coverage.xml

google/cloud/alloydbconnector/async_connector.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,17 @@ def __init__(
119119

120120
# check if AsyncConnector is being initialized with event loop running
121121
# Otherwise we will lazy init keys
122+
self._keys: Optional[asyncio.Task] = None
122123
try:
123-
self._keys: Optional[asyncio.Task] = asyncio.create_task(generate_keys())
124+
# Try to get the running loop before creating a task. The call here
125+
# will raise a RuntimeError if no loop is running. Without calling
126+
# get_running_loop, a direct call to create_task would also raise
127+
# an exception but it would leak the generate_keys coroutine. To
128+
# avoid leaking the coroutine, we call get_running_loop first.
129+
asyncio.get_running_loop()
130+
self._keys = asyncio.create_task(generate_keys())
124131
except RuntimeError:
125-
self._keys = None
132+
pass
126133
self._client: Optional[AlloyDBClient] = None
127134
self._closed = False
128135

google/cloud/alloydbconnector/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import logging
1919
from typing import TYPE_CHECKING
2020
from typing import Optional
21+
from typing import Union
2122

2223
from cryptography import x509
2324

@@ -95,7 +96,7 @@ def __init__(
9596
# API, even from multiple threads, need to be made to a single-event
9697
# loop. See https://github.com/GoogleCloudPlatform/alloydb-python-connector/issues/435
9798
# for more details.
98-
self._is_sync = False
99+
self._client: Union[v1beta.AlloyDBAdminClient, v1beta.AlloyDBAdminAsyncClient]
99100
if client:
100101
self._client = client
101102
elif driver == "pg8000" or driver == "psycopg":
@@ -110,7 +111,6 @@ def __init__(
110111
user_agent=user_agent,
111112
),
112113
)
113-
self._is_sync = True
114114
else:
115115
self._client = v1beta.AlloyDBAdminAsyncClient(
116116
credentials=credentials,
@@ -163,7 +163,7 @@ async def _get_metadata(
163163
)
164164

165165
req = v1beta.GetConnectionInfoRequest(parent=parent)
166-
if self._is_sync:
166+
if isinstance(self._client, v1beta.AlloyDBAdminClient):
167167
resp = self._client.get_connection_info(request=req)
168168
else:
169169
resp = await self._client.get_connection_info(request=req)
@@ -213,11 +213,11 @@ async def _get_client_certificate(
213213
public_key=pub_key,
214214
use_metadata_exchange=self._use_metadata,
215215
)
216-
if self._is_sync:
216+
if isinstance(self._client, v1beta.AlloyDBAdminClient):
217217
resp = self._client.generate_client_certificate(request=req)
218218
else:
219219
resp = await self._client.generate_client_certificate(request=req)
220-
return (resp.ca_cert, resp.pem_certificate_chain)
220+
return (resp.ca_cert, list(resp.pem_certificate_chain))
221221

222222
async def get_connection_info(
223223
self,

noxfile.py

Lines changed: 0 additions & 135 deletions
This file was deleted.

pyproject.toml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,31 @@ pg8000 = ["pg8000>=1.31.1"]
6262
asyncpg = ["asyncpg>=0.31.0"]
6363
psycopg = ["psycopg>=3.1.0"]
6464

65+
[dependency-groups]
66+
test = [
67+
"asyncpg>=0.31.0",
68+
"mock>=5.2.0",
69+
"pg8000>=1.31.5",
70+
"psycopg2-binary>=2.9.11",
71+
"psycopg>=3.3.3",
72+
"psycopg-binary>=3.3.3",
73+
"pytest>=9.0.2",
74+
"pytest-asyncio>=1.3.0",
75+
"pytest-cov>=7.0.0",
76+
"SQLAlchemy[asyncio]>=2.0.48",
77+
"aioresponses>=0.7.8",
78+
"coverage",
79+
]
80+
lint = [
81+
"ruff==0.11.2",
82+
"mypy",
83+
"types-aiofiles",
84+
"types-requests",
85+
"build",
86+
"twine",
87+
{include-group = "test"},
88+
]
89+
6590
[tool.setuptools.dynamic]
6691
version = { attr = "google.cloud.alloydbconnector.version.__version__" }
6792

@@ -98,7 +123,6 @@ ignore = [
98123
]
99124

100125
[tool.ruff.lint.per-file-ignores]
101-
"noxfile.py" = ["ANN"]
102126
"tests/*" = ["ANN"]
103127

104128
[tool.ruff.lint.isort]

requirements-test.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

requirements.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)