-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2623 from alicevision/dev/qmlDebuggerSetup
Add support for QML debugging/profiling
- Loading branch information
Showing
2 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
Meshroom environment variable management. | ||
""" | ||
|
||
__all__ = [ | ||
"EnvVar", | ||
"EnvVarHelpAction", | ||
] | ||
|
||
import argparse | ||
import os | ||
from dataclasses import dataclass | ||
from enum import Enum | ||
import sys | ||
from typing import Any, Type | ||
|
||
|
||
@dataclass | ||
class VarDefinition: | ||
"""Environment variable definition.""" | ||
|
||
# The type to cast the value to. | ||
valueType: Type | ||
# Default value if the variable is not set in the environment. | ||
default: str | ||
# Description of the purpose of the variable. | ||
description: str = "" | ||
|
||
def __str__(self) -> str: | ||
return f"{self.description} ({self.valueType.__name__}, default: '{self.default}')" | ||
|
||
|
||
class EnvVar(Enum): | ||
"""Meshroom environment variables catalog.""" | ||
|
||
# UI - Debug | ||
MESHROOM_QML_DEBUG = VarDefinition(bool, "False", "Enable QML debugging") | ||
MESHROOM_QML_DEBUG_PARAMS = VarDefinition( | ||
str, "port:3768", "QML debugging params as expected by -qmljsdebugger" | ||
) | ||
|
||
@staticmethod | ||
def get(envVar: "EnvVar") -> Any: | ||
"""Get the value of `envVar`, cast to the variable type.""" | ||
value = os.environ.get(envVar.name, envVar.value.default) | ||
return EnvVar._cast(value, envVar.value.valueType) | ||
|
||
@staticmethod | ||
def _cast(value: str, valueType: Type) -> Any: | ||
if valueType is str: | ||
return value | ||
elif valueType is bool: | ||
return value.lower() in {"true", "1", "on"} | ||
return valueType(value) | ||
|
||
@classmethod | ||
def help(cls) -> str: | ||
"""Return a formatted string with the details of each environment variables.""" | ||
return "\n".join([f"{var.name}: {var.value}" for var in cls]) | ||
|
||
|
||
class EnvVarHelpAction(argparse.Action): | ||
"""Argparse action for printing Meshroom environment variables help and exit.""" | ||
|
||
DEFAULT_HELP = "Print Meshroom environment variables help and exit." | ||
|
||
def __call__(self, parser, namespace, value, option_string=None): | ||
print("Meshroom environment variables:") | ||
print(EnvVar.help()) | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters