added ability to define qtbinding per platform

This commit is contained in:
Jakub Trllo 2022-12-21 15:21:19 +01:00
parent c849c83da4
commit 1fdf261ab7
2 changed files with 157 additions and 124 deletions

View file

@ -109,12 +109,20 @@ requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[openpype]
[openpype.pyside2]
# note: in here we can use pip version specifiers as this is installed with pip until
# Poetry will support custom location (-t flag for pip)
# https://pip.pypa.io/en/stable/cli/pip_install/#requirement-specifiers
version = "==5.15.2"
[openpype.qtbinding.windows]
package = "PySide2"
version = "5.15.2"
[openpype.qtbinding.darwin]
package = "PySide2"
version = "5.15.2"
[openpype.qtbinding.linux]
package = "PySide2"
version = "5.15.2"
# TODO: we will need to handle different linux flavours here and
# also different macos versions too.

View file

@ -64,54 +64,66 @@ def _print(msg: str, message_type: int = 0) -> None:
else:
header = term.darkolivegreen3("--- ")
print("{}{}".format(header, msg))
print(f"{header}{msg}")
start_time = time.time_ns()
openpype_root = Path(os.path.dirname(__file__)).parent
pyproject = toml.load(openpype_root / "pyproject.toml")
_print("Handling PySide2 Qt framework ...")
pyside2_version = None
try:
pyside2_version = pyproject["openpype"]["pyside2"]["version"]
_print("We'll install PySide2{}".format(pyside2_version))
except AttributeError:
_print("No PySide2 version was specified, using latest available.", 2)
pyside2_arg = "PySide2" if not pyside2_version else "PySide2{}".format(pyside2_version) # noqa: E501
python_vendor_dir = openpype_root / "vendor" / "python"
try:
def install_qtbinding(pyproject, openpype_root, platform_name):
_print("Handling Qt binding framework ...")
qtbinding_def = pyproject["openpype"]["qtbinding"][platform_name]
package = qtbinding_def["package"]
version = qtbinding_def.get("version")
qtbinding_arg = None
if package and version:
qtbinding_arg = f"{package}=={version}"
elif package:
qtbinding_arg = package
if not qtbinding_arg:
_print("Didn't find Qt binding to install")
sys.exit(1)
_print(f"We'll install {qtbinding_arg}")
python_vendor_dir = openpype_root / "vendor" / "python"
try:
subprocess.run(
[sys.executable, "-m", "pip", "install", "--upgrade",
pyside2_arg, "-t", str(python_vendor_dir)],
check=True, stdout=subprocess.DEVNULL)
except subprocess.CalledProcessError as e:
[
sys.executable,
"-m", "pip", "install", "--upgrade", qtbinding_arg,
"-t", str(python_vendor_dir)
],
check=True,
stdout=subprocess.DEVNULL
)
except subprocess.CalledProcessError as e:
_print("Error during PySide2 installation.", 1)
_print(str(e), 1)
sys.exit(1)
# Remove libraries for QtSql which don't have available libraries
# by default and Postgre library would require to modify rpath of dependency
platform_name = platform.system().lower()
if platform_name == "darwin":
pyside2_sqldrivers_dir = (
python_vendor_dir / "PySide2" / "Qt" / "plugins" / "sqldrivers"
# Remove libraries for QtSql which don't have available libraries
# by default and Postgre library would require to modify rpath of
# dependency
if platform_name == "darwin":
sqldrivers_dir = (
python_vendor_dir / package / "Qt" / "plugins" / "sqldrivers"
)
for filepath in pyside2_sqldrivers_dir.iterdir():
for filepath in sqldrivers_dir.iterdir():
os.remove(str(filepath))
_print("Processing third-party dependencies ...")
try:
def install_thirdparty(pyproject, openpype_root, platform_name):
_print("Processing third-party dependencies ...")
try:
thirdparty = pyproject["openpype"]["thirdparty"]
except AttributeError:
except AttributeError:
_print("No third-party libraries specified in pyproject.toml", 1)
sys.exit(1)
for k, v in thirdparty.items():
for k, v in thirdparty.items():
_print(f"processing {k}")
destination_path = openpype_root / "vendor" / "bin" / k
if not v.get(platform_name):
_print(("missing definition for current "
f"platform [ {platform_name} ]"), 2)
@ -143,8 +155,9 @@ for k, v in thirdparty.items():
r = requests.get(url, stream=True)
content_len = int(r.headers.get('Content-Length', '0')) or None
with manager.counter(color='green',
total=content_len and math.ceil(content_len / 2 ** 20), # noqa: E501
with manager.counter(
color='green',
total=content_len and math.ceil(content_len / 2 ** 20),
unit='MiB', leave=False) as counter:
with open(temp_file, 'wb', buffering=2 ** 24) as file_handle:
for chunk in r.iter_content(chunk_size=2 ** 20):
@ -197,6 +210,18 @@ for k, v in thirdparty.items():
tar_file.close()
_print("Extraction OK", 3)
end_time = time.time_ns()
total_time = (end_time - start_time) / 1000000000
_print(f"Downloading and extracting took {total_time} secs.")
def main():
start_time = time.time_ns()
openpype_root = Path(os.path.dirname(__file__)).parent
pyproject = toml.load(openpype_root / "pyproject.toml")
platform_name = platform.system().lower()
install_qtbinding(pyproject, openpype_root, platform_name)
install_thirdparty(pyproject, openpype_root, platform_name)
end_time = time.time_ns()
total_time = (end_time - start_time) / 1000000000
_print(f"Downloading and extracting took {total_time} secs.")
if __name__ == "__main__":
main()