pglast icon indicating copy to clipboard operation
pglast copied to clipboard

Python 3.9: ImportError: cannot import name 'ast' from 'pglast' (unknown location)

Open df7cb opened this issue 2 weeks ago • 3 comments

Thanks for the new pglast release!

On Debian bullseye and Ubuntu jammy (the old ones), the testsuite complains about this:

11:50:43 ============================= test session starts ==============================
11:50:43 platform linux -- Python 3.9.2, pytest-6.0.2, py-1.10.0, pluggy-0.13.0
11:50:43 rootdir: /build/reproducible-path/pglast-7.11
11:50:43 plugins: cov-2.10.1
11:50:43 collected 0 items / 8 errors
11:50:43 
11:50:43 ==================================== ERRORS ====================================
11:50:43 ____ ERROR collecting .pybuild/cpython3_3.9_pglast/build/tests/test_ast.py _____
11:50:43 ImportError while importing test module '/build/reproducible-path/pglast-7.11/.pybuild/cpython3_3.9_pglast/build/tests/test_ast.py'.
11:50:43 Hint: make sure your test modules/packages have valid Python names.
11:50:43 Traceback:
11:50:43 /usr/lib/python3.9/importlib/__init__.py:127: in import_module
11:50:43     return _bootstrap._gcd_import(name[level:], package, level)
11:50:43 tests/test_ast.py:11: in <module>
11:50:43     from pglast import ast, enums, parse_sql
11:50:43 E   ImportError: cannot import name 'ast' from 'pglast' (unknown location)
11:50:43 ____ ERROR collecting .pybuild/cpython3_3.9_pglast/build/tests/test_cli.py _____

Full build log: https://jengus.postgresql.org/job/pglast-binaries/53/architecture=amd64,distribution=bullseye/console

If that's an intended change, that's fine, we can simply disable building pglast for these distro releases.

FYI, I also had to remove the "license" line from pyproject.toml because setuptools on bookworm and noble (and older) didn't like it:

configuration error: `project.license` must be valid exactly by one definition (2 matches found)

Log for that one: https://jengus.postgresql.org/job/pglast-binaries/52/architecture=amd64,distribution=bookworm/console

df7cb avatar Dec 15 '25 11:12 df7cb

That's strange, I cannot say what's going wrong there, the job on GH CI went ok: https://github.com/lelit/pglast/actions/runs/20226117949/job/58065409256#step:5:383

I will try to investigate as time permits!

lelit avatar Dec 15 '25 12:12 lelit

Fwiw, our debian/rules file has this:

execute_before_dh_auto_build:
	# force a cython run
	cython3 pglast/parser.pyx

Possibly that violates assumptions about prebuilt files.

df7cb avatar Dec 15 '25 12:12 df7cb

The CI tests are running on Ubuntu noble (24.04), which has a newer python than jammy (22.04).

df7cb avatar Dec 15 '25 12:12 df7cb

I'm afraid I'm not able to reproduce the problem, even if I see some issues with the some dev requirements and Python 3.9 (sphinx 9.x and coverage 7.13.x mainly).

I cloned v7 into /tmp/pglast and quickly relaxed some of those requirements, then inside a docker run -ti debian:bullseye -v /tmp/pglast:/tmp/pglast, after an apt update && apt install python3-dev python3-venv gcc make git ed, a cd /tmp/pglast; make; source env/bin/activate; make check ran without issues, and eventually

(pglast) root@f4dbc7672bc7:/tmp/pglast# head -4 /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
(pglast) root@f4dbc7672bc7:/tmp/pglast# python3 --version
Python 3.9.2
(pglast) root@f4dbc7672bc7:/tmp/pglast# pgpp --version
pgpp 7.11, with PostgreSQL 17.7 parser
(pglast) root@f4dbc7672bc7:/tmp/pglast# pgpp -S "select foo from bar"
SELECT foo
FROM bar

so it's definitely working as expected. Dunno what I can do more, and honestly, I doubt it's worth the hassle, but if you have further suggestions, you're welcome!

lelit avatar Dec 20 '25 18:12 lelit