Skip to content

Commit 19eef18

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 19eef18

17 files changed

Lines changed: 174 additions & 188 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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,12 @@ 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+
asyncio.get_running_loop()
125+
self._keys = asyncio.create_task(generate_keys())
124126
except RuntimeError:
125-
self._keys = None
127+
pass
126128
self._client: Optional[AlloyDBClient] = None
127129
self._closed = False
128130

google/cloud/alloydbconnector/client.py

Lines changed: 5 additions & 3 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

@@ -96,6 +97,7 @@ def __init__(
9697
# loop. See https://github.com/GoogleCloudPlatform/alloydb-python-connector/issues/435
9798
# for more details.
9899
self._is_sync = False
100+
self._client: Union[v1beta.AlloyDBAdminClient, v1beta.AlloyDBAdminAsyncClient]
99101
if client:
100102
self._client = client
101103
elif driver == "pg8000" or driver == "psycopg":
@@ -163,7 +165,7 @@ async def _get_metadata(
163165
)
164166

165167
req = v1beta.GetConnectionInfoRequest(parent=parent)
166-
if self._is_sync:
168+
if isinstance(self._client, v1beta.AlloyDBAdminClient):
167169
resp = self._client.get_connection_info(request=req)
168170
else:
169171
resp = await self._client.get_connection_info(request=req)
@@ -213,11 +215,11 @@ async def _get_client_certificate(
213215
public_key=pub_key,
214216
use_metadata_exchange=self._use_metadata,
215217
)
216-
if self._is_sync:
218+
if isinstance(self._client, v1beta.AlloyDBAdminClient):
217219
resp = self._client.generate_client_certificate(request=req)
218220
else:
219221
resp = await self._client.generate_client_certificate(request=req)
220-
return (resp.ca_cert, resp.pem_certificate_chain)
222+
return (resp.ca_cert, list(resp.pem_certificate_chain))
221223

222224
async def get_connection_info(
223225
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)