Skip to content

Commit

Permalink
Implement Python 3.12 compatible loader. Fixes #130.
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 committed Mar 11, 2024
1 parent 45c6cee commit 465064a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/qrc_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
Expand All @@ -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):
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

0 comments on commit 465064a

Please sign in to comment.