Skip to content

fix: hooks not loading on python 3.13 - #759

Closed
sudoAlphaX wants to merge 2 commits into
z411:masterfrom
sudoAlphaX:master
Closed

sudoAlphaX wants to merge 2 commits into
z411:masterfrom
sudoAlphaX:master

Conversation

@sudoAlphaX

@sudoAlphaX sudoAlphaX commented Feb 22, 2025 •

Copy link
Copy Markdown

Hooks refuse to load on python version 3.13 because of the error
AttributeError: 'FileFinder' object has no attribute 'find_module'

This patch changes find_module to find_spec to fix this issue. I have
tested it using python version 3.8 and 3.13.

Here is the full trace before this patch:

Engine: Reading config files...
Data: Initializing...
libanilist: Initializing...
Data: Using libanilist (anime)
Engine: Parsing redirection file...
Engine: Scanning local library...
Engine: Importing user hooks...
Traceback (most recent call last):
  File "/usr/bin/trackma", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/usr/lib/python3.13/site-packages/trackma/ui/cli.py", line 1071, in main
    main_cmd.start()
    ~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/site-packages/trackma/ui/cli.py", line 180, in start
    self.engine.start()
    ~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/site-packages/trackma/engine.py", line 305, in start
    module = loader.find_module(name).load_module(name)
             ^^^^^^^^^^^^^^^^^^
AttributeError: 'FileFinder' object has no attribute 'find_module'

Fixes #736.
Duplicates and closes #746.

Comment thread trackma/engine.py Resolved
Hooks refuse to load on python version 3.13 because of the error
`AttributeError: 'FileFinder' object has no attribute 'find_module'`

This patch changes find_module to importlib.import_module() to fix this issue. I have
tested it using python version 3.8 and 3.13.

Here is the full trace before this patch:

```py
Engine: Reading config files...
Data: Initializing...
libanilist: Initializing...
Data: Using libanilist (anime)
Engine: Parsing redirection file...
Engine: Scanning local library...
Engine: Importing user hooks...
Traceback (most recent call last):
  File "/usr/bin/trackma", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/usr/lib/python3.13/site-packages/trackma/ui/cli.py", line 1071, in main
    main_cmd.start()
    ~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/site-packages/trackma/ui/cli.py", line 180, in start
    self.engine.start()
    ~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/site-packages/trackma/engine.py", line 305, in start
    module = loader.find_module(name).load_module(name)
             ^^^^^^^^^^^^^^^^^^
AttributeError: 'FileFinder' object has no attribute 'find_module'

```

Co-Authored-By: FichteFoll <fichtefoll2@googlemail.com>
@sudoAlphaX

Copy link
Copy Markdown
Author

@FichteFoll something like this would do?

@sudoAlphaX
sudoAlphaX marked this pull request as ready for review February 24, 2025 14:42
@FichteFoll

Copy link
Copy Markdown
Contributor

I'll have to look into this in more detail to evaluate whether it is worth abandoning the loader we get from pkgutil already.

@sudoAlphaX

Copy link
Copy Markdown
Author

Shall i instead abandon using pkgutil and use only importlib (and os.listdir)

@FichteFoll

Copy link
Copy Markdown
Contributor

After some research I am confident that #769 is the proper way to do this now, so I'm closing this PR as a duplicate. Thanks for taking a look.

@FichteFoll FichteFoll closed this Mar 29, 2025
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

Successfully merging this pull request may close these issues.

'FileFinder' object has no attribute 'find_module'

2 participants