removed 'openpype_version.py' from lib

This commit is contained in:
Jakub Trllo 2024-02-06 14:17:35 +01:00
parent 929dbec710
commit eef157363e
15 changed files with 104 additions and 352 deletions

View file

@ -1,6 +1,6 @@
import os
from ayon_core.lib import get_openpype_execute_args
from ayon_core.lib import get_ayon_launcher_args
from ayon_core.lib.applications import (
get_non_python_host_kwargs,
PreLaunchHook,
@ -37,7 +37,7 @@ class NonPythonHostHook(PreLaunchHook):
"non_python_host_launch.py"
)
new_launch_args = get_openpype_execute_args(
new_launch_args = get_ayon_launcher_args(
"run", script_path, executable_path
)
# Add workfile path if exists

View file

@ -2,7 +2,7 @@ import os
import shutil
import winreg
import subprocess
from ayon_core.lib import get_openpype_execute_args
from ayon_core.lib import get_ayon_launcher_args
from ayon_core.lib.applications import PreLaunchHook, LaunchTypes
from ayon_core.hosts.celaction import CELACTION_ROOT_DIR
@ -38,7 +38,7 @@ class CelactionPrelaunchHook(PreLaunchHook):
path_to_cli = os.path.join(
CELACTION_ROOT_DIR, "scripts", "publish_cli.py"
)
subprocess_args = get_openpype_execute_args("run", path_to_cli)
subprocess_args = get_ayon_launcher_args("run", path_to_cli)
openpype_executable = subprocess_args.pop(0)
workfile_settings = self.get_workfile_settings()

View file

@ -1,6 +1,6 @@
import os
from ayon_core.lib import get_openpype_execute_args
from ayon_core.lib import get_ayon_launcher_args
from ayon_core.lib.execute import run_detached_process
from ayon_core.modules import (
click_wrap,
@ -35,7 +35,7 @@ class TrayPublishAddon(OpenPypeModule, IHostAddon, ITrayAction):
self.publish_paths.extend(publish_paths)
def run_traypublisher(self):
args = get_openpype_execute_args(
args = get_ayon_launcher_args(
"module", self.name, "launch"
)
run_detached_process(args)

View file

@ -1,4 +1,4 @@
from ayon_core.lib import get_openpype_execute_args
from ayon_core.lib import get_ayon_launcher_args
from ayon_core.lib.applications import PreLaunchHook, LaunchTypes
@ -23,7 +23,7 @@ class TvpaintPrelaunchHook(PreLaunchHook):
while self.launch_context.launch_args:
remainders.append(self.launch_context.launch_args.pop(0))
new_launch_args = get_openpype_execute_args(
new_launch_args = get_ayon_launcher_args(
"run", self.launch_script_path(), executable_path
)

View file

@ -153,15 +153,9 @@ from .path_tools import (
get_last_version_from_path,
)
from .openpype_version import (
op_version_control_available,
get_openpype_version,
get_build_version,
get_expected_version,
from .ayon_info import (
is_running_from_build,
is_running_staging,
is_current_version_studio_latest,
is_current_version_higher_than_expected
is_staging_enabled,
)
@ -278,13 +272,8 @@ __all__ = [
"Logger",
"op_version_control_available",
"get_openpype_version",
"get_build_version",
"get_expected_version",
"is_running_from_build",
"is_running_staging",
"is_current_version_studio_latest",
"is_staging_enabled",
"requests_get",
"requests_post"

View file

@ -6,23 +6,46 @@ import getpass
import socket
from ayon_core.settings.lib import get_local_settings
from .execute import get_openpype_execute_args
from .execute import get_ayon_launcher_args
from .local_settings import get_local_site_id
from .openpype_version import (
is_running_from_build,
get_openpype_version,
get_build_version
)
def get_ayon_launcher_version():
version_filepath = os.path.join(os.environ["AYON_ROOT"], "version.py")
if not os.path.exists(version_filepath):
return None
content = {}
with open(version_filepath, "r") as stream:
exec(stream.read(), content)
return content["__version__"]
def is_running_from_build():
"""Determine if current process is running from build or code.
Returns:
bool: True if running from build.
"""
executable_path = os.environ["AYON_EXECUTABLE"]
executable_filename = os.path.basename(executable_path)
if "python" in executable_filename.lower():
return False
return True
def is_staging_enabled():
return os.getenv("AYON_USE_STAGING") == "1"
def get_ayon_info():
executable_args = get_openpype_execute_args()
executable_args = get_ayon_launcher_args()
if is_running_from_build():
version_type = "build"
else:
version_type = "code"
return {
"build_verison": get_build_version(),
"ayon_launcher_version": get_ayon_launcher_version(),
"version_type": version_type,
"executable": executable_args[-1],
"ayon_root": os.environ["AYON_ROOT"],
@ -40,7 +63,7 @@ def get_workstation_info():
return {
"hostname": host_name,
"hostip": host_ip,
"host_ip": host_ip,
"username": getpass.getuser(),
"system_name": platform.system(),
"local_id": get_local_site_id()
@ -50,32 +73,32 @@ def get_workstation_info():
def get_all_current_info():
"""All information about current process in one dictionary."""
output = {
return {
"workstation": get_workstation_info(),
"env": os.environ.copy(),
"local_settings": get_local_settings(),
"ayon": get_ayon_info(),
}
return output
def extract_pype_info_to_file(dirpath):
def extract_ayon_info_to_file(dirpath, filename=None):
"""Extract all current info to a file.
It is possible to define onpy directory path. Filename is concatenated with
It is possible to define only directory path. Filename is concatenated with
pype version, workstation site id and timestamp.
Args:
dirpath (str): Path to directory where file will be stored.
filename (Optional[str]): Filename. If not defined, it is generated.
Returns:
filepath (str): Full path to file where data were extracted.
"""
filename = "{}_{}_{}.json".format(
get_openpype_version(),
get_local_site_id(),
datetime.datetime.now().strftime("%y%m%d%H%M%S")
)
if not filename:
filename = "{}_{}.json".format(
get_local_site_id(),
datetime.datetime.now().strftime("%y%m%d%H%M%S")
)
filepath = os.path.join(dirpath, filename)
data = get_all_current_info()
if not os.path.exists(dirpath):

View file

@ -8,17 +8,11 @@ import tempfile
from .log import Logger
from .vendor_bin_utils import find_executable
from .openpype_version import is_running_from_build
# MSDN process creation flag (Windows only)
CREATE_NO_WINDOW = 0x08000000
def execute(args,
silent=False,
cwd=None,
env=None,
shell=None):
def execute(args, silent=False, cwd=None, env=None, shell=None):
"""Execute command as process.
This will execute given command as process, monitor its output
@ -39,9 +33,9 @@ def execute(args,
int: return code of process
"""
log_levels = ['DEBUG:', 'INFO:', 'ERROR:', 'WARNING:', 'CRITICAL:']
log_levels = ["DEBUG:", "INFO:", "ERROR:", "WARNING:", "CRITICAL:"]
log = Logger.get_logger('execute')
log = Logger.get_logger("execute")
log.info("Executing ({})".format(" ".join(args)))
popen = subprocess.Popen(
args,
@ -57,7 +51,7 @@ def execute(args,
# Blocks until finished
while True:
line = popen.stdout.readline()
if line == '':
if line == "":
break
if silent:
continue
@ -97,6 +91,7 @@ def run_subprocess(*args, **kwargs):
Raises:
RuntimeError: Exception is raised if process finished with nonzero
return code.
"""
# Modify creation flags on windows to hide console window if in UI mode
if (
@ -171,6 +166,7 @@ def clean_envs_for_ayon_process(env=None):
Returns:
dict[str, str]: Environment variables for ayon process.
"""
if env is None:
env = os.environ
@ -183,15 +179,6 @@ def clean_envs_for_ayon_process(env=None):
return env
def clean_envs_for_openpype_process(env=None):
"""Modify environments that may affect OpenPype process.
Main reason to implement this function is to pop PYTHONPATH which may be
affected by in-host environments.
"""
return clean_envs_for_ayon_process(env=env)
def run_ayon_launcher_process(*args, **kwargs):
"""Execute OpenPype process with passed arguments and wait.
@ -212,6 +199,7 @@ def run_ayon_launcher_process(*args, **kwargs):
Returns:
str: Full output of subprocess concatenated stdout and stderr.
"""
args = get_ayon_launcher_args(*args)
env = kwargs.pop("env", None)
@ -221,10 +209,6 @@ def run_ayon_launcher_process(*args, **kwargs):
# - fill more if you find more
env = clean_envs_for_ayon_process(os.environ)
# Only keep OpenPype version if we are running from build.
if not is_running_from_build():
env.pop("OPENPYPE_VERSION", None)
return run_subprocess(args, env=env, **kwargs)
@ -243,6 +227,7 @@ def run_openpype_process(*args, **kwargs):
Args:
*args (tuple): OpenPype cli arguments.
**kwargs (dict): Keyword arguments for subprocess.Popen.
"""
return run_ayon_launcher_process(*args, **kwargs)
@ -261,6 +246,7 @@ def run_detached_process(args, **kwargs):
Returns:
subprocess.Popen: Pointer to launched process but it is possible that
launched process is already killed (on linux).
"""
env = kwargs.pop("env", None)
# Keep env untouched if are passed and not empty
@ -321,6 +307,12 @@ def path_to_subprocess_arg(path):
"""Prepare path for subprocess arguments.
Returned path can be wrapped with quotes or kept as is.
Args:
path (str): Path to be converted.
Returns:
str: Converted path.
"""
return subprocess.list2cmdline([path])
@ -357,24 +349,6 @@ def get_ayon_launcher_args(*args):
return launch_args
def get_openpype_execute_args(*args):
"""Arguments to run pype command.
Arguments for subprocess when need to spawn new pype process. Which may be
needed when new python process for pype scripts must be executed in build
pype.
## Why is this needed?
Pype executed from code has different executable set to virtual env python
and must have path to script as first argument which is not needed for
build pype.
It is possible to pass any arguments that will be added after pype
executables.
"""
return get_ayon_launcher_args(*args)
def get_linux_launcher_args(*args):
"""Path to application mid process executable.
@ -417,3 +391,21 @@ def get_linux_launcher_args(*args):
launch_args.extend(args)
return launch_args
def get_openpype_execute_args(*args):
"""Arguments to run pype command.
Arguments for subprocess when need to spawn new pype process. Which may be
needed when new python process for pype scripts must be executed in build
pype.
## Why is this needed?
Pype executed from code has different executable set to virtual env python
and must have path to script as first argument which is not needed for
build pype.
It is possible to pass any arguments that will be added after pype
executables.
"""
return get_ayon_launcher_args(*args)

View file

@ -1,243 +0,0 @@
"""Lib access to OpenPypeVersion from igniter.
Access to logic from igniter is available only for OpenPype processes.
Is meant to be able check OpenPype versions for studio. The logic is dependent
on igniter's inner logic of versions.
Keep in mind that all functions except 'get_installed_version' does not return
OpenPype version located in build but versions available in remote versions
repository or locally available.
"""
import os
import sys
import ayon_core.version
# ----------------------------------------
# Functions independent on OpenPypeVersion
# ----------------------------------------
def get_openpype_version():
"""Version of pype that is currently used."""
return ayon_core.version.__version__
def get_ayon_launcher_version():
version_filepath = os.path.join(os.environ["AYON_ROOT"], "version.py")
if not os.path.exists(version_filepath):
return None
content = {}
with open(version_filepath, "r") as stream:
exec(stream.read(), content)
return content["__version__"]
def get_build_version():
"""OpenPype version of build."""
return get_ayon_launcher_version()
def is_running_from_build():
"""Determine if current process is running from build or code.
Returns:
bool: True if running from build.
"""
executable_path = os.environ["AYON_EXECUTABLE"]
executable_filename = os.path.basename(executable_path)
if "python" in executable_filename.lower():
return False
return True
def is_staging_enabled():
return os.getenv("AYON_USE_STAGING") == "1"
def is_running_staging():
"""Currently used OpenPype is staging version.
This function is not 100% proper check of staging version. It is possible
to have enabled to use staging version but be in different one.
The function is based on 4 factors:
- env 'OPENPYPE_IS_STAGING' is set
- current production version
- current staging version
- use staging is enabled
First checks for 'OPENPYPE_IS_STAGING' environment which can be set to '1'.
The value should be set only when a process without access to
OpenPypeVersion is launched (e.g. in DCCs). If current version is same
as production version it is expected that it is not staging, and it
doesn't matter what would 'is_staging_enabled' return. If current version
is same as staging version it is expected we're in staging. In all other
cases 'is_staging_enabled' is used as source of outpu value.
The function is used to decide which icon is used. To check e.g. updates
the output should be combined with other functions from this file.
Returns:
bool: Using staging version or not.
"""
return is_staging_enabled()
# ----------------------------------------
# Functions dependent on OpenPypeVersion
# - Make sense to call only in OpenPype process
# ----------------------------------------
def get_OpenPypeVersion():
"""Access to OpenPypeVersion class stored in sys modules."""
return sys.modules.get("OpenPypeVersion")
def op_version_control_available():
"""Check if current process has access to OpenPypeVersion."""
if get_OpenPypeVersion() is None:
return False
return True
def get_installed_version():
"""Get OpenPype version inside build.
This version is not returned by any other functions here.
"""
if op_version_control_available():
return get_OpenPypeVersion().get_installed_version()
return None
def get_available_versions(*args, **kwargs):
"""Get list of available versions."""
if op_version_control_available():
return get_OpenPypeVersion().get_available_versions(
*args, **kwargs
)
return None
def openpype_path_is_set():
"""OpenPype repository path is set in settings."""
if op_version_control_available():
return get_OpenPypeVersion().openpype_path_is_set()
return None
def openpype_path_is_accessible():
"""OpenPype version repository path can be accessed."""
if op_version_control_available():
return get_OpenPypeVersion().openpype_path_is_accessible()
return None
def get_local_versions(*args, **kwargs):
"""OpenPype versions available on this workstation."""
if op_version_control_available():
return get_OpenPypeVersion().get_local_versions(*args, **kwargs)
return None
def get_remote_versions(*args, **kwargs):
"""OpenPype versions in repository path."""
if op_version_control_available():
return get_OpenPypeVersion().get_remote_versions(*args, **kwargs)
return None
def get_latest_version(local=None, remote=None):
"""Get latest version from repository path."""
if op_version_control_available():
return get_OpenPypeVersion().get_latest_version(
local=local,
remote=remote
)
return None
def get_expected_studio_version(staging=None):
"""Expected production or staging version in studio."""
if op_version_control_available():
if staging is None:
staging = is_staging_enabled()
return get_OpenPypeVersion().get_expected_studio_version(staging)
return None
def get_expected_version(staging=None):
expected_version = get_expected_studio_version(staging)
if expected_version is None:
# Look for latest if expected version is not set in settings
expected_version = get_latest_version(
local=False,
remote=True
)
return expected_version
def is_current_version_studio_latest():
"""Is currently running OpenPype version which is defined by studio.
It is not recommended to ask in each process as there may be situations
when older OpenPype should be used. For example on farm. But it does make
sense in processes that can run for a long time.
Returns:
None: Can't determine. e.g. when running from code or the build is
too old.
bool: True when is using studio
"""
output = None
# Skip if is not running from build or build does not support version
# control or path to folder with zip files is not accessible
if (
not is_running_from_build()
or not op_version_control_available()
or not openpype_path_is_accessible()
):
return output
# Get OpenPypeVersion class
OpenPypeVersion = get_OpenPypeVersion()
# Convert current version to OpenPypeVersion object
current_version = OpenPypeVersion(version=get_openpype_version())
# Get expected version (from settings)
expected_version = get_expected_version()
# Check if current version is expected version
return current_version == expected_version
def is_current_version_higher_than_expected():
"""Is current OpenPype version higher than version defined by studio.
Returns:
None: Can't determine. e.g. when running from code or the build is
too old.
bool: True when is higher than studio version.
"""
output = None
# Skip if is not running from build or build does not support version
# control or path to folder with zip files is not accessible
if (
not is_running_from_build()
or not op_version_control_available()
or not openpype_path_is_accessible()
):
return output
# Get OpenPypeVersion class
OpenPypeVersion = get_OpenPypeVersion()
# Convert current version to OpenPypeVersion object
current_version = OpenPypeVersion(version=get_openpype_version())
# Get expected version (from settings)
expected_version = get_expected_version()
# Check if current version is expected version
return current_version > expected_version

View file

@ -11,7 +11,7 @@ from datetime import datetime
import pyblish.api
from ayon_core.lib import BoolDef, NumberDef, is_running_from_build
from ayon_core.lib.execute import run_openpype_process
from ayon_core.lib.execute import run_ayon_launcher_process
from ayon_core.modules.royalrender.api import Api as rrApi
from ayon_core.modules.royalrender.rr_job import (
CustomAttribute,
@ -364,7 +364,7 @@ class BaseCreateRoyalRenderJob(pyblish.api.InstancePlugin,
for key, value in add_kwargs.items():
args.extend([f"--{key}", value])
self.log.debug("Executing: {}".format(" ".join(args)))
run_openpype_process(*args, logger=self.log)
run_ayon_launcher_process(*args, logger=self.log)
self.log.debug("Loading file ...")
with open(export_url) as fp:

View file

@ -12,7 +12,7 @@ from ayon_core import AYON_CORE_ROOT
from ayon_core.settings import get_project_settings
from ayon_core.lib import (
StringTemplate,
run_openpype_process,
run_ayon_launcher_process,
Logger
)
from ayon_core.pipeline import Anatomy
@ -448,7 +448,7 @@ def _get_wrapped_with_subprocess(command_group, command, **kwargs):
log.info("Executing: {}".format(" ".join(args)))
run_openpype_process(*args, logger=log)
run_ayon_launcher_process(*args, logger=log)
# return all colorspaces
with open(tmp_json_path, "r") as f_:
@ -1187,7 +1187,7 @@ def get_display_view_colorspace_subprocess(config_path, display, view):
]
log.debug("Executing: {}".format(" ".join(args)))
run_openpype_process(*args, logger=log)
run_ayon_launcher_process(*args, logger=log)
# return default view colorspace name
with open(tmp_json_path, "r") as f:

View file

@ -1,7 +1,7 @@
import os
import json
from ayon_core.lib import Logger, filter_profiles
from ayon_core.lib.pype_info import get_workstation_info
from ayon_core.lib.ayon_info import get_workstation_info
from ayon_core.settings import get_project_settings
from ayon_core.pipeline import get_process_id

View file

@ -1,7 +1,7 @@
import os
from ayon_core import AYON_CORE_ROOT
from ayon_core.lib import get_openpype_execute_args, run_detached_process
from ayon_core.lib import get_ayon_launcher_args, run_detached_process
from ayon_core.pipeline import load
from ayon_core.pipeline.load import LoadError
@ -45,7 +45,7 @@ class PushToLibraryProject(load.SubsetLoaderPlugin):
project_name = project_doc["name"]
version_id = str(version_doc["_id"])
args = get_openpype_execute_args(
args = get_ayon_launcher_args(
"run",
push_tool_script_path,
"--project", project_name,

View file

@ -12,7 +12,7 @@ import pyblish.api
from ayon_core import resources, AYON_CORE_ROOT
from ayon_core.pipeline import publish
from ayon_core.lib import (
run_openpype_process,
run_ayon_launcher_process,
get_transcode_temp_directory,
convert_input_paths_for_ffmpeg,
@ -351,7 +351,7 @@ class ExtractBurnin(publish.Extractor):
"logger": self.log
}
run_openpype_process(*args, **process_kwargs)
run_ayon_launcher_process(*args, **process_kwargs)
# Remove the temporary json
os.remove(temporary_json_filepath)

View file

@ -8,11 +8,11 @@ from qtpy import QtCore, QtGui, QtWidgets
from ayon_core import style
import ayon_core.version
from ayon_core import resources
from ayon_core.lib import get_openpype_execute_args
from ayon_core.lib.pype_info import (
from ayon_core.lib import get_ayon_launcher_args
from ayon_core.lib.ayon_info import (
get_all_current_info,
get_workstation_info,
extract_pype_info_to_file
extract_ayon_info_to_file,
)
IS_MAIN_ROLE = QtCore.Qt.UserRole
@ -292,7 +292,7 @@ class PypeInfoWidget(QtWidgets.QWidget):
if not dst_dir_path or not os.path.exists(dst_dir_path):
return
filepath = extract_pype_info_to_file(dst_dir_path)
filepath = extract_ayon_info_to_file(dst_dir_path)
title = "Extraction done"
message = "Extraction is done. Destination filepath is \"{}\"".format(
filepath.replace("\\", "/")
@ -411,7 +411,7 @@ class PypeInfoSubWidget(QtWidgets.QWidget):
def _create_openpype_info_widget(self):
"""Create widget with information about OpenPype application."""
executable_args = get_openpype_execute_args()
executable_args = get_ayon_launcher_args()
username = "N/A"
user_info = ayon_api.get_user()
if user_info:

View file

@ -10,13 +10,10 @@ from qtpy import QtCore, QtGui, QtWidgets
from ayon_core import resources, style
from ayon_core.lib import (
Logger,
get_openpype_execute_args,
get_ayon_launcher_args,
run_detached_process,
)
from ayon_core.lib.openpype_version import (
get_expected_version,
is_running_from_build,
)
from ayon_core.lib import is_running_from_build
from ayon_core.addon import (
ITrayAction,
ITrayService,
@ -254,7 +251,7 @@ class TrayManager:
reset_version(bool): OpenPype version is cleaned up so igniters
logic will decide which version will be used.
"""
args = get_openpype_execute_args()
args = get_ayon_launcher_args()
envs = dict(os.environ.items())
# Create a copy of sys.argv
@ -267,13 +264,7 @@ class TrayManager:
cleanup_additional_args = False
if use_expected_version:
cleanup_additional_args = True
expected_version = get_expected_version()
if expected_version is not None:
reset_version = False
envs["OPENPYPE_VERSION"] = str(expected_version)
else:
# Trigger reset of version if expected version was not found
reset_version = True
reset_version = True
# Pop OPENPYPE_VERSION
if reset_version: