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 · 8 comments
Open

The import_module is not compatible with recent Python 3.12 #274

Jakuje opened this issue Apr 19, 2024 · 8 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

This comment was marked as off-topic.

@botihu
Copy link

botihu commented Aug 31, 2024

I found the same issue as @Jakuje described

The tarball from GitHub release virtualsmartcard-0.9 includes src/vpicc/py-compile script which comes from an older automake and has internal version tag scriptversion=2018-03-07.03; # UTC.
I deleted the py-compile, then autoreconf --verbose --install copied it from my system's automake package.

On my Ubuntu, the automake package version is 1:1.16.5-1.3ubuntu1 and it has a bit more recent py-compile with scriptversion=2021-02-27.01; # UTC which likely did not depend on imp module anymore.

Also the issue is not triggered if someone do git clone for getting the source.
But if they download the vsmartcard-0.9 release tgz bundle from GitHub which includes py-compile script from an older automake they will see the error at make install.

@italodeveloper
Copy link

I also have the same problem on Linux Mint and Ubuntu in the latest versions with Python 3.12, after managing to compile the project, I accessed the local folder on my machine and made a local call ./vicc within the project for example, but something definitely happens in the python 3.12 so the direct call to /bin breaks in some ways

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

5 participants