lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.5k stars 157 forks source link

Missing ctypes module for bindc_11.py--sometimes #2486

Open rebcabin opened 7 months ago

rebcabin commented 7 months ago

Running standalone, the following all work in the directory integration_tests

lpython bindc_01.py
lpython bindc_02.py
lpython bindc_07.py
lpython bindc_08.py
lpython bindc_09.py
lpython bindc_09b.py
lpython bindc_10.py

However, bindc_11.py produces an error

(lp) ┌─(~/Documents/GitHub/lpython/integration_tests)─────(brian@MacBook-Pro:s001)─┐
└─(19:22:41 on vector-backend)──> lpython bindc_11.py                                                                                    ──(Mon,Feb05)─┘
semantic error: Could not find the module 'ctypes'. If an import path is available, please use the `-I` option to specify it
 --> bindc_11.py:1:1
  |
1 | import numpy, ctypes
  | ^^^^^^^^^^^^^^^^^^^^ 

The module ctypes is not in evidence in the directory tree:

(lp) ┌─(~/Documents/GitHub/lpython/integration_tests)─────(brian@MacBook-Pro:s001)─┐
└─(19:25:05 on vector-backend)──> find .. -name "ctypes.py"                                                                              ──(Mon,Feb05)─┘
(lp) ┌─(~/Documents/GitHub/lpython/integration_tests)

Nor in the lp environment:

(lp) ┌─(~/Documents/GitHub/lpython/integration_tests)─────(brian@MacBook-Pro:s001)─┐
└─(19:28:55 on vector-backend)──> find ~/miniforge3 -name ctypes.py                                                                
(lp) ┌─(~/Documents/GitHub/lpython/integration_tests)

So I have no idea how this could ever work under any circumstances, and no idea how to tell lpython via the -I option how to find ctypes. It's some kind of magical thing

HOWEVER, bindc_11 works under run_tests.py:

(lp) ┌─(~/Documents/GitHub/lpython/integration_tests)─────(brian@MacBook-Pro:s001)─┐
└─(19:24:32 on vector-backend)──> ./run_tests.py 2> /dev/null | grep bindc_11                                                      130 ↵ ──(Mon,Feb05)─┘
        Start  29: bindc_11
 39/323 Test  #29: bindc_11 .........................   Passed    0.09 sec

I have no idea how to find out what actual command that run_tests uses to launch bindc_11 or any other of its tests until I reverse engineer it.

To deepen the mystery, bindc_11 works in CPython:

(lp) ┌─(~/Documents/GitHub/lpython/integration_tests)──────(brian@MacBook-Pro:s001)─┐
└─(19:34:02 on vector-backend)──> PYTHONPATH=".:../src/runtime/lpython:.." LPYTHON_PY_MOD_NAME="" LPYTHON_PY_MOD_PATH="_lpython-tmp-test-cpython" python bindc_11.py
c_void_p(105553171916784)
5 4
rebcabin commented 7 months ago

marking severe because the workaround is nasty (reverse-engineering run_tests.py