Skip to content

Commit f8c8952

Browse files
committed
Refactor lint workflow to use editable installs and update type references, fix outdated import in tests/test_typeinfo.py: replace gaussdb.postgres.types with gaussdb.gaussdb_.types
1 parent 94b93af commit f8c8952

3 files changed

Lines changed: 33 additions & 70 deletions

File tree

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ jobs:
2828

2929
- name: install packages to tests
3030
run: |
31-
pip install ./tools/isort-gaussdb/
32-
pip install ./gaussdb[dev,test]
33-
pip install ./gaussdb_pool
31+
pip install -e ./tools/isort-gaussdb/
32+
pip install -e ./gaussdb[dev,test]
33+
pip install -e ./gaussdb_pool
3434
pip install types-polib
3535
pip install pre-commit
3636

tests/test_typeinfo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,18 @@ def test_registry_invalid_oid(oid, aoid):
190190

191191

192192
def test_registry_copy():
193-
r = gaussdb.types.TypesRegistry(gaussdb.postgres.types)
193+
r = gaussdb.types.TypesRegistry(gaussdb.gaussdb_.types)
194194
assert r.get("text") is r["text"] is r[25]
195195
assert r["text"].oid == 25
196196

197197

198198
def test_registry_isolated():
199-
orig = gaussdb.postgres.types
199+
orig = gaussdb.gaussdb_.types
200+
print(f"orig._registry={orig._registry}")
200201
tinfo = orig["text"]
201202
r = gaussdb.types.TypesRegistry(orig)
202203
tdummy = gaussdb.types.TypeInfo("dummy", tinfo.oid, tinfo.array_oid)
203204
r.add(tdummy)
205+
print(f"orig={orig},tinfo={tinfo},r={r},tdummy={tdummy}")
204206
assert r[25] is r["dummy"] is tdummy
205207
assert orig[25] is r["text"] is tinfo

tools/update_oids.py

Lines changed: 26 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
88
Hint: use docker to upgrade types from a new version in isolation. Run:
99
10-
docker run --rm -p 11111:5432 --name pg -e POSTGRES_PASSWORD=password postgres:TAG
10+
docker run --rm -p 11111:5432 --name pg -e GAUSSDB_PASSWORD=password gaussdb:TAG
1111
1212
with a specified version tag, and then query it using:
1313
14-
%(prog)s "host=localhost port=11111 user=postgres password=password"
14+
%(prog)s "host=localhost port=11111 user=root password=password"
1515
"""
1616

1717
from __future__ import annotations
@@ -42,17 +42,15 @@ def main() -> None:
4242
else:
4343
update_python_oids(conn)
4444
update_python_types(conn)
45-
update_cython_oids(conn)
4645

4746

4847
def update_python_types(conn: Connection) -> None:
49-
fn = ROOT / "gaussdb/gaussdb/postgres.py"
48+
fn = ROOT / "gaussdb/gaussdb/gaussdb.py"
5049

5150
lines = []
5251
lines.extend(get_version_comment(conn))
5352
lines.extend(get_py_types(conn))
5453
lines.extend(get_py_ranges(conn))
55-
lines.extend(get_py_multiranges(conn))
5654

5755
update_file(fn, lines)
5856
sp.check_call(["black", "-q", fn])
@@ -69,16 +67,6 @@ def update_python_oids(conn: Connection) -> None:
6967
sp.check_call(["black", "-q", fn])
7068

7169

72-
def update_cython_oids(conn: Connection) -> None:
73-
fn = ROOT / "gaussdb_c/gaussdb_c/_gaussdb/oids.pxd"
74-
75-
lines = []
76-
lines.extend(get_version_comment(conn))
77-
lines.extend(get_cython_oids(conn))
78-
79-
update_file(fn, lines)
80-
81-
8270
def update_crdb_python_oids(conn: Connection) -> None:
8371
fn = ROOT / "gaussdb/gaussdb/crdb/_types.py"
8472

@@ -92,7 +80,22 @@ def update_crdb_python_oids(conn: Connection) -> None:
9280

9381
def get_version_comment(conn: Connection) -> list[str]:
9482
if conn.info.vendor == "PostgreSQL":
95-
version = version_pretty(conn.info.server_version)
83+
# version = version_pretty(conn.info.server_version)
84+
raw_version = conn.info.server_version
85+
86+
if isinstance(raw_version, str):
87+
# such as '505.2.0' → [505, 2, 0]
88+
parts = [int(x) for x in re.findall(r"\d+", raw_version)]
89+
if len(parts) >= 2:
90+
major, minor = parts[0], parts[1]
91+
patch = parts[2] if len(parts) >= 3 else 0
92+
version_int = major * 10000 + minor * 100 + patch
93+
else:
94+
version_int = 0 # fallback
95+
else:
96+
version_int = raw_version
97+
98+
version = version_pretty(version_int)
9699
elif conn.info.vendor == "CockroachDB":
97100
assert isinstance(conn, CrdbConnection)
98101
version = version_pretty(conn.info.server_version)
@@ -143,7 +146,7 @@ def get_py_types(conn: Connection) -> list[str]:
143146
"""
144147
select typname, oid, typarray,
145148
-- CRDB might have quotes in the regtype representation
146-
replace(typname::regtype::text, '''', '') as regtype,
149+
replace(CAST(typname AS TEXT), '''', '') as regtype,
147150
typdelim
148151
from pg_type t
149152
where
@@ -156,7 +159,7 @@ def get_py_types(conn: Connection) -> list[str]:
156159
):
157160
typemod = typemods.get(typname)
158161

159-
# Weird legacy type in postgres catalog
162+
# Weird legacy type in gaussdb catalog
160163
if typname == "char":
161164
typname = regtype = '"char"'
162165

@@ -180,14 +183,14 @@ def get_py_ranges(conn: Connection) -> list[str]:
180183
lines = []
181184
for typname, oid, typarray, rngsubtype in conn.execute(
182185
"""
183-
select typname, oid, typarray, rngsubtype
186+
select t.typname, t.oid, t.typarray, r.rngsubtype
184187
from
185188
pg_type t
186-
join pg_range r on t.oid = rngtypid
189+
join pg_range r on t.oid = r.rngtypid
187190
where
188-
oid < 10000
189-
and typtype = 'r'
190-
order by typname
191+
t.oid < 10000
192+
and t.typtype = 'r'
193+
order by t.typname
191194
"""
192195
):
193196
params = [f"{typname!r}, {oid}, {typarray}, subtype_oid={rngsubtype}"]
@@ -196,48 +199,6 @@ def get_py_ranges(conn: Connection) -> list[str]:
196199
return lines
197200

198201

199-
def get_py_multiranges(conn: Connection) -> list[str]:
200-
lines = []
201-
for typname, oid, typarray, rngtypid, rngsubtype in conn.execute(
202-
"""
203-
select typname, oid, typarray, rngtypid, rngsubtype
204-
from
205-
pg_type t
206-
join pg_range r on t.oid = rngmultitypid
207-
where
208-
oid < 10000
209-
and typtype = 'm'
210-
order by typname
211-
"""
212-
):
213-
params = [
214-
f"{typname!r}, {oid}, {typarray},"
215-
f" range_oid={rngtypid}, subtype_oid={rngsubtype}"
216-
]
217-
lines.append(f"MultirangeInfo({','.join(params)}),")
218-
219-
return lines
220-
221-
222-
def get_cython_oids(conn: Connection) -> list[str]:
223-
lines = []
224-
for typname, oid in conn.execute(
225-
"""
226-
select typname, oid
227-
from pg_type
228-
where
229-
oid < 10000
230-
and (typtype = any('{b,r,m}') or typname = 'record')
231-
and (typname !~ '^(_|pg_)' or typname = 'pg_lsn')
232-
order by typname
233-
"""
234-
):
235-
const_name = typname.upper() + "_OID"
236-
lines.append(f" {const_name} = {oid}")
237-
238-
return lines
239-
240-
241202
def update_file(fn: Path, new: list[str]) -> None:
242203
with fn.open("r") as f:
243204
lines = f.read().splitlines()

0 commit comments

Comments
 (0)