Only construct info when needed + optimize "silent commands" lookup

- Lookup in "silent commands" as `set`
- Do "silent commands" lookup only once instead of in the for loop
- Move imports closer to where they are needed (e.g. don't import terminal if we don't use it)
This commit is contained in:
Roy Nieterau 2022-01-29 14:39:00 +01:00
parent 50d1f8c4be
commit b088e952e6

View file

@ -86,7 +86,7 @@ Todo:
Move or remove bootstrapping environments out of the code. Move or remove bootstrapping environments out of the code.
Attributes: Attributes:
silent_commands (list): list of commands for which we won't print OpenPype silent_commands (set): list of commands for which we won't print OpenPype
logo and info header. logo and info header.
.. _MongoDB: .. _MongoDB:
@ -202,8 +202,8 @@ from igniter.tools import (
from igniter.bootstrap_repos import OpenPypeVersion # noqa: E402 from igniter.bootstrap_repos import OpenPypeVersion # noqa: E402
bootstrap = BootstrapRepos() bootstrap = BootstrapRepos()
silent_commands = ["run", "igniter", "standalonepublisher", silent_commands = {"run", "igniter", "standalonepublisher",
"extractenvironments"] "extractenvironments"}
def list_versions(openpype_versions: list, local_version=None) -> None: def list_versions(openpype_versions: list, local_version=None) -> None:
@ -1057,29 +1057,30 @@ def boot():
_print(" - for modules ...") _print(" - for modules ...")
set_modules_environments() set_modules_environments()
from openpype import cli
from openpype.lib import terminal as t
from openpype.version import __version__
assert version_path, "Version path not defined." assert version_path, "Version path not defined."
info = get_info(use_staging)
info.insert(0, f">>> Using OpenPype from [ {version_path} ]")
t_width = 20 # print info when not running scripts defined in 'silent commands'
try: if all(arg not in silent_commands for arg in sys.argv):
t_width = os.get_terminal_size().columns - 2 from openpype.lib import terminal as t
except (ValueError, OSError): from openpype.version import __version__
# running without terminal
pass
_header = f"*** OpenPype [{__version__}] " info = get_info(use_staging)
info.insert(0, f">>> Using OpenPype from [ {version_path} ]")
info.insert(0, _header + "-" * (t_width - len(_header))) t_width = 20
for i in info: try:
# don't show for running scripts t_width = os.get_terminal_size().columns - 2
if all(item not in sys.argv for item in silent_commands): except (ValueError, OSError):
# running without terminal
pass
_header = f"*** OpenPype [{__version__}] "
info.insert(0, _header + "-" * (t_width - len(_header)))
for i in info:
t.echo(i) t.echo(i)
from openpype import cli
try: try:
cli.main(obj={}, prog_name="openpype") cli.main(obj={}, prog_name="openpype")
except Exception: # noqa except Exception: # noqa