Skip to content

Commit

Permalink
Merge branch 'main' into pythonTestWorkaround
Browse files Browse the repository at this point in the history
  • Loading branch information
mattelser authored Jul 24, 2023
2 parents 7202728 + 5417eda commit f3abe7d
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 64 deletions.
4 changes: 2 additions & 2 deletions exts/cesium.omniverse/cesium/omniverse/extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .bindings import acquire_cesium_omniverse_interface, release_cesium_omniverse_interface, Viewport
from .install import perform_vendor_install
from .utils import wait_n_frames, dock_window_async
from .ui.asset_window import CesiumOmniverseAssetWindow
from .ui.debug_window import CesiumOmniverseDebugWindow
Expand All @@ -22,7 +23,6 @@
import os
from typing import List, Optional, Callable
from .ui.credits_viewport_controller import CreditsViewportController
from .install.install_lxml import install_lxml

cesium_extension_location = os.path.join(os.path.dirname(__file__), "../../")

Expand Down Expand Up @@ -58,7 +58,7 @@ def __init__(self) -> None:
self._menu = None
self._num_credits_viewport_frames: int = 0

install_lxml(cesium_extension_location)
perform_vendor_install()

def on_startup(self):
# The ability to show up the window if the system requires it. We use it in QuickLayout.
Expand Down
3 changes: 2 additions & 1 deletion exts/cesium.omniverse/cesium/omniverse/install/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .install_lxml import * # noqa: F401 F403
from .wheel_installer import WheelInfo, WheelInstaller # noqa: F401 F403
from .vendor_install import perform_vendor_install # noqa: F401 F403
54 changes: 0 additions & 54 deletions exts/cesium.omniverse/cesium/omniverse/install/install_lxml.py

This file was deleted.

28 changes: 28 additions & 0 deletions exts/cesium.omniverse/cesium/omniverse/install/vendor_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import logging
from typing import List
from .wheel_installer import WheelInfo, WheelInstaller


def perform_vendor_install():
logger = logging.getLogger(__name__)

# Only vendor wheels for the main Cesium Omniverse extension should be placed here.
# This action needs to be mirrored for each extension.
vendor_wheels: List[WheelInfo] = [
WheelInfo(
module="lxml",
windows_whl="lxml-4.9.2-cp310-cp310-win_amd64.whl",
linux_x64_whl=(
"lxml-4.9.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl"
),
linux_aarch_whl=(
"lxml-4.9.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl"
),
)
]

for w in vendor_wheels:
installer = WheelInstaller(w)

if not installer.install():
logger.error(f"Could not install wheel for {w.module}")
83 changes: 83 additions & 0 deletions exts/cesium.omniverse/cesium/omniverse/install/wheel_installer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from dataclasses import dataclass
import logging
from pathlib import Path
import platform
import omni.kit.app as app
import omni.kit.pipapi
from ..utils.utils import str_is_empty_or_none


@dataclass
class WheelInfo:
"""
Data class containing the module and wheel file names for each platform.
"""

module: str
windows_whl: str
linux_x64_whl: str
linux_aarch_whl: str


class WheelInstaller:
"""
Class for installing wheel files bundled with the extension.
"""

def __init__(self, info: WheelInfo, extension_module="cesium.omniverse"):
"""
Creates a new instance of a wheel installer for installing a python package.
:param info: A WheelInfo data class containing the information for wheel installation.
:param extension_module: The full module for the extension, if a different extension is using this class.
:raises ValueError: If any arguments are null or empty strings.
"""
self._logger = logging.getLogger(__name__)

if (
str_is_empty_or_none(info.windows_whl)
or str_is_empty_or_none(info.linux_x64_whl)
or str_is_empty_or_none(info.linux_aarch_whl)
):
raise ValueError(f"One or more wheels is missing for {info.module}.")

self._info = info

manager = app.get_app().get_extension_manager()
ext_id = manager.get_extension_id_by_module(extension_module)
self._vendor_directory_path = Path(manager.get_extension_path(ext_id)).joinpath("vendor")

def install(self) -> bool:
"""
Installs the correct wheel for the current platform.
:return: ``True`` if the installation was successful.
"""

if platform.system() == "Windows":
return self._perform_install(self._info.windows_whl)
else:
machine = platform.machine()
if machine.startswith("arm") or machine.startswith("aarch"):
return self._perform_install(self._info.linux_aarch_whl)
return self._perform_install(self._info.linux_x64_whl)

def _perform_install(self, wheel_file_name: str) -> bool:
"""
Performs the actual installation of the wheel file.
:param wheel_file_name: The file name of the wheel to install.
:return: ``True`` if the installation was successful.
"""

path = self._vendor_directory_path.joinpath(wheel_file_name)

return omni.kit.pipapi.install(
package=str(path),
module=self._info.module,
use_online_index=False,
ignore_cache=True,
ignore_import_check=False,
)
10 changes: 10 additions & 0 deletions exts/cesium.omniverse/cesium/omniverse/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ async def dock_window_async(
stage_window = ui.Workspace.get_window(target)
window.dock_in(stage_window, position, 1)
window.focus()


def str_is_empty_or_none(s: Optional[str]):
if s is None:
return True

if s == "":
return True

return False
21 changes: 20 additions & 1 deletion exts/cesium.powertools/cesium/powertools/extension.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from functools import partial
import asyncio
from typing import Optional
from typing import Optional, List
import logging
import omni.ext
import omni.ui as ui
import omni.kit.ui
from .powertools_window import CesiumPowertoolsWindow
from cesium.omniverse.utils import wait_n_frames, dock_window_async
from cesium.omniverse.install import WheelInfo, WheelInstaller


class CesiumPowertoolsExtension(omni.ext.IExt):
Expand All @@ -17,6 +18,8 @@ def __init__(self):

self._powertools_window: Optional[CesiumPowertoolsWindow] = None

self._install_py_dependencies()

def on_startup(self):
self._logger.info("Starting Cesium Power Tools...")

Expand Down Expand Up @@ -70,3 +73,19 @@ def _show_powertools_window(self, _menu, value):
)
elif self._powertools_window is not None:
self._powertools_window.visible = False

def _install_py_dependencies(self):
vendor_wheels: List[WheelInfo] = [
WheelInfo(
module="pyproj",
windows_whl="pyproj-3.6.0-cp310-cp310-win_amd64.whl",
linux_x64_whl="pyproj-3.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
linux_aarch_whl="pyproj-3.6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
)
]

for w in vendor_wheels:
installer = WheelInstaller(w, extension_module="cesium.powertools")

if not installer.install():
self._logger.error(f"Could not install wheel for {w.module}")
6 changes: 0 additions & 6 deletions exts/cesium.powertools/cesium/powertools/georefhelper/proj.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import omni.kit.pipapi

# Install dependencies for this module
omni.kit.pipapi.install("pyproj==3.2.1")


ECEF_EPSG = 4978
WGS84_EPSG = 4979

Expand Down
3 changes: 3 additions & 0 deletions exts/cesium.powertools/config/extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ icon = "doc/resources/icon.png"

[[python.module]]
name = "cesium.powertools"

[python.pipapi]
archiveDirs = ["vendor"]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit f3abe7d

Please sign in to comment.