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

Implement Python 3.12 compatible loader. Fixes #130. #131

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/qrc_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,33 @@
#

import sys
from importlib import abc
from importlib.util import spec_from_loader

import pyotherside

from importlib import abc

class PyOtherSideQtRCLoader(abc.Loader):
def __init__(self, filepath):
self.filepath = filepath

def create_module(self, spec):
return

def exec_module(self, module):
Copy link
Contributor Author

@apollo13 apollo13 Mar 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know Python's import System well enough. Maybe https://docs.python.org/3.11/library/importlib.html#importlib.abc.SourceLoader could be used instead of having to manually exec stuff?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have managed to rewrite it back to the SourceLoader, let me know what you think.

data = pyotherside.qrc_get_file_contents(self.filepath[len('qrc:') :])
code = compile(data, self.filepath, 'exec')
exec(code, module.__dict__)


class PyOtherSideQtRCImporter(abc.MetaPathFinder, abc.SourceLoader):
def find_spec(self, fullname, path, target=None):
if path is None:
fname = self.get_filename(fullname)
if fname:
return spec_from_loader(fullname, PyOtherSideQtRCLoader(fname))
return

def find_module(self, fullname, path):
if path is None or all(x.startswith('qrc:') for x in path):
if self.get_filename(fullname):
Expand Down
Loading