Skip to content
Draft
Changes from all commits
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
66 changes: 56 additions & 10 deletions tk_toolchain/cmd_line_tools/tk_build_qt_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"""

import argparse
import glob
import os
import re
import subprocess
Expand Down Expand Up @@ -60,7 +61,12 @@ def verify_compiler(compiler):

def build_qt(compiler, py_filename, py_built_path, import_text):
output_path = os.path.join(py_built_path, f"{py_filename}.py")
subprocess.run(compiler.split(" "), stdout=open(output_path, "w"), check=True)
compiler.extend([
"--output",
output_path,
])

subprocess.run(compiler, check=True)
content = open(output_path, "r").read()
content = re.sub(
r"^from PySide2.QtWidgets(\s.*)?$", "", content, flags=re.MULTILINE
Expand All @@ -80,7 +86,13 @@ def build_ui(
compiler, qt_ui_path, py_built_path, import_text, filename, py_filename=None
):
return {
"compiler": f"{compiler} -g python --from-imports {qt_ui_path}/{filename}.ui",
"compiler": [
compiler,
"-g",
"python",
"--from-imports",
f"{qt_ui_path}/{filename}.ui",
],
"py_filename": py_filename or filename,
"py_built_path": py_built_path,
"import_text": import_text,
Expand All @@ -91,7 +103,12 @@ def build_res(
compiler, qt_ui_path, py_built_path, import_text, filename, py_filename=None
):
return {
"compiler": f"{compiler} -g python {qt_ui_path}/{filename}.qrc",
"compiler": [
compiler,
"-g",
"python",
f"{qt_ui_path}/{filename}.qrc",
],
"py_filename": f"{py_filename or filename}_rc",
"py_built_path": py_built_path,
"import_text": import_text,
Expand Down Expand Up @@ -154,16 +171,32 @@ def run_yaml_commands(yaml_file, uic, rcc):
return 1


def scan_sgd_folder(path: str) -> tuple|None: # tuple[str,str]
for found_uic in glob.glob(f"{path}/Python*/lib/python*/site-packages/PySide2/uic"):
rrc_path = os.path.join(os.path.dirname(found_uic), "rcc")
if os.path.exists(rrc_path):
return(found_uic, rrc_path)


def main():
parser = argparse.ArgumentParser(description="Build UI and resource files")
parser.add_argument("-u", "--uic", help="The PySide uic compiler")
parser.add_argument("-r", "--rcc", help="The PySide rcc compiler")
parser = argparse.ArgumentParser(
description="Helper script to build the Qt UI and resource files for Toolkit components",
)
# parser.add_argument("-u", "--uic", help="The PySide uic compiler", default="pyside2-uic")
# parser.add_argument("-r", "--rcc", help="The PySide rcc compiler")
parser.add_argument(
"-p",
"--pyenv",
default=os.getenv("PYTHONPATH"),
default=os.getenv("PYENV_VIRTUAL_ENV", os.getenv("VIRTUAL_ENV")),
help="The Python environment path",
)
parser.add_argument(
"--python-from-desktop-app",
help="If set, use the FPTR desktop app installation folder for Python environment",
# Set to 1 or true to autodect
# or a path for another installation
# Take precedense on args.uic and args.rcc
)
parser.add_argument(
"-y",
"--yamlfile",
Expand All @@ -172,9 +205,22 @@ def main():
)
args = parser.parse_args()

if (not args.uic and not args.rcc) and args.pyenv:
args.uic = f"{args.pyenv}/pyside2-uic"
args.rcc = f"{args.pyenv}/pyside2-rcc"
if args.python_from_desktop_app:
if not os.path.exists(args.python_from_desktop_app):
if sys.platform == "linux":
args.python_from_desktop_app = "/opt/Shotgun"
elif sys.platform == "darwin":
args.python_from_desktop_app = "/Applications/Shotgun.app/Contents/MacOS"
elif sys.platform == "win32":
args.python_from_desktop_app = "C:\Program Files\Shotgun"
else:
raise NotImplementedError()

(args.uic, args.rcc) = scan_sgd_folder(args.python_from_desktop_app)

elif (not args.uic and not args.rcc) and args.pyenv:
args.uic = f"{args.pyenv}/bin/pyside2-uic"
args.rcc = f"{args.pyenv}/bin/pyside2-rcc"

if not args.rcc or not args.uic:
print(
Expand Down
Loading