Instagram / LibCST

A concrete syntax tree parser and serializer library for Python that preserves many aspects of Python's abstract syntax tree
https://libcst.readthedocs.io/
Other
1.57k stars 192 forks source link

[support] running test suite doesn’t find libcst.native #1176

Open mcepl opened 4 months ago

mcepl commented 4 months ago

When packaging libCST for openSUSE, I fail to make running test suite. We build our packages in the network-isolated environment, and we want the simplest possible environment, so I am trying to run test suite (with installed libraries) just with (effectively):

export PATH=/home/abuild/rpmbuild/BUILD/libcst-1.4.0/build/flavorbin:/usr/local/bin:/usr/bin:/bin
export PYTHONPATH=/home/abuild/rpmbuild/BUILDROOT/python-libcst-test-1.4.0-0.x86_64/usr/lib/python3.10/site-packages
PYTHONDONTWRITEBYTECODE=1
python3.10 -m unittest discover -v libcst/tests

However, even with (hopefully) correctly set PATH and PYTHONPATH, 42 tests are not able to find libcst.native (even though the *.so is in the right place) and error, for example:

[  103s] test_leaky_codemod (test_e2e.ToolE2ETest) ... Executing codemod...
[  103s] Failed to determine module name for /tmp/tmp4wbthukg/example.py: '/tmp/tmp4wbthukg/example.py' is not in the subpath of '' OR one path is relative and the other is absolute.
[  103s] Codemodding /tmp/tmp4wbthukg/example.py
[  103s] Traceback (most recent call last):
[  103s]   File "/home/abuild/rpmbuild/BUILD/libcst-1.4.0/libcst/codemod/_cli.py", line 276, in _execute_transform
[  103s]     input_tree = parse_module(
[  103s]   File "/home/abuild/rpmbuild/BUILD/libcst-1.4.0/libcst/_parser/entrypoints.py", line 109, in parse_module
[  103s]     result = _parse(
[  103s]   File "/home/abuild/rpmbuild/BUILD/libcst-1.4.0/libcst/_parser/entrypoints.py", line 42, in _parse
[  103s]     from libcst.native import parse_expression, parse_module, parse_statement
[  103s] ModuleNotFoundError: No module named 'libcst.native'
[  103s] 
[  103s] Failed to codemod /tmp/tmp4wbthukg/example.py

It seems that the generated test script doesn’t follow PYTHONPATH?

Complete build log

zsol commented 4 months ago

I'm not really sure how to help here. The tests work just fine upstream, my only guess is the .so file is not actually in the right place or something else is hiding it - the test script isn't doing anything special with PYTHONPATH AFAICT

mcepl commented 4 months ago

The tests work just fine upstream, my only guess is the .so file is not actually in the right place or something else is hiding it - the test script isn't doing anything special with PYTHONPATH AFAICT

See the find command output in the beginning of the %check section:

[   83s] Executing(%check): /usr/bin/bash -e /var/tmp/rpm-tmp.jfAzzf
[   83s] + umask 022
[   83s] + cd /home/abuild/rpmbuild/BUILD
[   83s] + cd libcst-1.4.0
[   83s] ++ '[' -f _current_flavor ']'
[   83s] ++ cat _current_flavor
[   83s] + last_flavor=python311
[   83s] + '[' -z python311 ']'
[   83s] + '[' python311 '!=' python310 ']'
[   83s] + '[' -d build ']'
[   83s] + mv build _build.python311
[   83s] + '[' -d _build.python310 ']'
[   83s] + mv _build.python310 build
[   83s] + echo python310
[   83s] + python_flavor=python310
[   83s] + find /home/abuild/rpmbuild/BUILDROOT/python-libcst-test-1.4.0-0.x86_64/usr/lib64/python3.10/site-packages -name '*.so*'
[   83s] /home/abuild/rpmbuild/BUILDROOT/python-libcst-test-1.4.0-0.x86_64/usr/lib64/python3.10/site-packages/libcst/native.cpython-310-x86_64-linux-gnu.so
[   83s] ++ '[' -f _current_flavor ']'
[   83s] ++ cat _current_flavor
[   83s] + last_flavor=python310
[   83s] + '[' -z python310 ']'
[   83s] + '[' python310 '!=' python312 ']'
[   83s] + '[' -d build ']'
[   83s] + mv build _build.python310
[   83s] + '[' -d _build.python312 ']'
[   83s] + mv _build.python312 build
[   83s] + echo python312
[   83s] + python_flavor=python312
[   83s] + find /home/abuild/rpmbuild/BUILDROOT/python-libcst-test-1.4.0-0.x86_64/usr/lib64/python3.12/site-packages -name '*.so*'
[   83s] /home/abuild/rpmbuild/BUILDROOT/python-libcst-test-1.4.0-0.x86_64/usr/lib64/python3.12/site-packages/libcst/native.cpython-312-x86_64-linux-gnu.so
[   83s] ++ '[' -f _current_flavor ']'
[   83s] ++ cat _current_flavor
[   83s] + last_flavor=python312
[   83s] + '[' -z python312 ']'
[   83s] + '[' python312 '!=' python311 ']'
[   83s] + '[' -d build ']'
[   83s] + mv build _build.python312
[   83s] + '[' -d _build.python311 ']'
[   83s] + mv _build.python311 build
[   83s] + echo python311
[   83s] + python_flavor=python311
[   83s] + find /home/abuild/rpmbuild/BUILDROOT/python-libcst-test-1.4.0-0.x86_64/usr/lib64/python3.11/site-packages -name '*.so*'
[   83s] /home/abuild/rpmbuild/BUILDROOT/python-libcst-test-1.4.0-0.x86_64/usr/lib64/python3.11/site-packages/libcst/native.cpython-311-x86_64-linux-gnu.so
[   83s] 

The library is obviously where it is supposed to be, isn’t it?

Full log