Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The import_module is not compatible with recent Python 3.12 #274

Open
Jakuje opened this issue Apr 19, 2024 · 6 comments
Open

The import_module is not compatible with recent Python 3.12 #274

Jakuje opened this issue Apr 19, 2024 · 6 comments

Comments

@Jakuje
Copy link
Contributor

Jakuje commented Apr 19, 2024

The Python 3.12 removes several parts of the importlib python/cpython#98040 causing a build failure of this package under this python version, I believe in the following code parts:

from importlib import import_module
from pathlib import Path
def onNth(tup,ind,func):
start = tup[0:ind] + (func(tup[ind]),)
return start if ind + 1 == 0 else start + tup[ind+1:]
def pathToModuleName(path):
return ".".join(onNth(Path(path).parts,-1,lambda fName : str(Path(fName).stem)))
mitmModule = import_module(pathToModuleName(path))

The build failures do not look self-explanatory though:

https://download.copr.fedorainfracloud.org/results/jjelen/vsmartcard/centos-stream-10-x86_64/07317358-virtualsmartcard/builder-live.log.gz

I would like to get this fixed, but I will not get to that in coming days so contributions, help, pointers always welcomed.

@frankmorgner
Copy link
Owner

Hmm, I don't see how the changes should affect the code. Also, this python version seems to work for me as expected...

@frankmorgner
Copy link
Owner

Here you find the fix for exactly the same error message (in python 3.12).

https://github.com/neovim/pynvim/pull/534/files#diff-30fa4df68b7ec17e985d7d0dd3536d8c469e0f118f262708e1449da29e33d479R29-R40

The fix is to use importlib.import_module instead of imp. However, vpicc already uses the former (i.e. NOT imp). I suspect, that some dependency uses the imp module, which is causing the problem.

You should be able to dig into the program using something like the following:

cd vsmartcard/virtualsmartcard/src
env PYTHONPATH=$PWD python3 -m pdb vicc.in --type=relay

@Jakuje
Copy link
Contributor Author

Jakuje commented Apr 25, 2024

Not sure if I do something wrong, but attempt to run vicc gives me the error that it can not find smartcard module:

[root@rhel-10-0-20240318-5 vpicc]# env PYTHONPATH=$PWD python3 vicc --type=relay
Traceback (most recent call last):
  File "/root/virtualsmartcard-0.9/src/vpicc/vicc", line 159, in <module>
    vicc = VirtualICC(args.datasetfile, args.type, hostname, args.port,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/virtualsmartcard-0.9/src/vpicc/virtualsmartcard/VirtualSmartcard.py", line 448, in __init__
    from virtualsmartcard.cards.Relay import RelayOS
  File "/root/virtualsmartcard-0.9/src/vpicc/virtualsmartcard/cards/Relay.py", line 22, in <module>
    import smartcard
ModuleNotFoundError: No module named 'smartcard'

Looking further into the steps what happen during the build, the error is raised while byte-compiling the python code. If I see right, this is done by invoking the py-compile binary, which is part of the tarball and does not get updated by the system-provided one.

So the workaround is to remove the py-compile from the tarball (can be done as part of the RPM build). The solution should be just to make sure the next release will have updated py-compile.

@frankmorgner
Copy link
Owner

Not sure how to update or avoid py-compile manually as it is automatically added, see https://www.gnu.org/software/automake/manual/html_node/Python.html. I guess, this directly depends on the version of autotools that are installed. I could try updating AC_PREREQ, but I'm not sure if that helps...

@Jakuje
Copy link
Contributor Author

Jakuje commented May 14, 2024

If it is automatically added, I think just rebuilding the tarball with updated automake should do that.

@ManiekGrob86
Copy link

for me env PYTHONPATH=$PWD python3 -m pdb vicc.in --type=relay
Error: vicc.in does not exist
???
Whats wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants