Fix PCN include_builtin() when running under QRC
This commit is contained in:
parent
388cc0e218
commit
9a813ecaa8
@ -1,3 +1,4 @@
|
|||||||
|
import re
|
||||||
import textwrap
|
import textwrap
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from collections.abc import MutableMapping
|
from collections.abc import MutableMapping
|
||||||
@ -9,13 +10,16 @@ from typing import (
|
|||||||
Union,
|
Union,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
import pyotherside
|
||||||
import redbaron as red
|
import redbaron as red
|
||||||
|
|
||||||
from .globals_dict import GlobalsDict
|
from .globals_dict import GlobalsDict
|
||||||
from .property import Property, process_value
|
from .property import Property, process_value
|
||||||
|
|
||||||
# TODO: docstrings, error handling, support @property, non-section classes
|
# 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)
|
@dataclass(repr=False, eq=False)
|
||||||
@ -404,5 +408,12 @@ class Section(MutableMapping):
|
|||||||
def from_file(
|
def from_file(
|
||||||
cls, path: Union[str, Path], builtins: Union[str, Path] = BUILTINS_DIR,
|
cls, path: Union[str, Path], builtins: Union[str, Path] = BUILTINS_DIR,
|
||||||
) -> "Section":
|
) -> "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))
|
||||||
|
Loading…
Reference in New Issue
Block a user