From 9a813ecaa8a52b9ca286d41bcb4afd5169b5a9c3 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 15 Nov 2020 17:44:45 -0400 Subject: [PATCH] Fix PCN include_builtin() when running under QRC --- src/backend/pcn/section.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/backend/pcn/section.py b/src/backend/pcn/section.py index dda10b4f..94da29e6 100644 --- a/src/backend/pcn/section.py +++ b/src/backend/pcn/section.py @@ -1,3 +1,4 @@ +import re import textwrap from collections import OrderedDict from collections.abc import MutableMapping @@ -9,13 +10,16 @@ from typing import ( Union, ) +import pyotherside import redbaron as red from .globals_dict import GlobalsDict from .property import Property, process_value # TODO: docstrings, error handling, support @property, non-section classes -BUILTINS_DIR: Path = Path(__file__).parent.parent.parent.resolve() # src dir +BUILTINS_DIR: Path = Path(__file__).parent.parent.parent + +assert BUILTINS_DIR.name == "src" @dataclass(repr=False, eq=False) @@ -404,5 +408,12 @@ class Section(MutableMapping): def from_file( cls, path: Union[str, Path], builtins: Union[str, Path] = BUILTINS_DIR, ) -> "Section": - path = Path(path) - return Section.from_source_code(path.read_text(), path, Path(builtins)) + + path = Path(re.sub(r"^qrc:/", "", str(path))) + + try: + content = pyotherside.qrc_get_file_contents(str(path)).decode() + except ValueError: # App was compiled without QRC + content = path.read_text() + + return Section.from_source_code(content, path, Path(builtins))