mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
moved code from pype_info to openpype_version and fixed few bugs
This commit is contained in:
parent
d7fb171f10
commit
7d283f5555
4 changed files with 118 additions and 92 deletions
|
|
@ -168,7 +168,7 @@ from .editorial import (
|
|||
make_sequence_collection
|
||||
)
|
||||
|
||||
from .pype_info import (
|
||||
from .openpype_version import (
|
||||
get_openpype_version,
|
||||
get_build_version,
|
||||
is_running_from_build,
|
||||
|
|
|
|||
|
|
@ -9,9 +9,69 @@ OpenPype version located in build but versions available in remote versions
|
|||
repository or locally available.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import openpype.version
|
||||
|
||||
from .python_module_tools import import_filepath
|
||||
|
||||
|
||||
# ----------------------------------------
|
||||
# Functions independent on OpenPypeVersion
|
||||
# ----------------------------------------
|
||||
def get_openpype_version():
|
||||
"""Version of pype that is currently used."""
|
||||
return openpype.version.__version__
|
||||
|
||||
|
||||
def get_build_version():
|
||||
"""OpenPype version of build."""
|
||||
# Return OpenPype version if is running from code
|
||||
if not is_running_from_build():
|
||||
return get_openpype_version()
|
||||
|
||||
# Import `version.py` from build directory
|
||||
version_filepath = os.path.join(
|
||||
os.environ["OPENPYPE_ROOT"],
|
||||
"openpype",
|
||||
"version.py"
|
||||
)
|
||||
if not os.path.exists(version_filepath):
|
||||
return None
|
||||
|
||||
module = import_filepath(version_filepath, "openpype_build_version")
|
||||
return getattr(module, "__version__", None)
|
||||
|
||||
|
||||
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["OPENPYPE_EXECUTABLE"]
|
||||
executable_filename = os.path.basename(executable_path)
|
||||
if "python" in executable_filename.lower():
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def is_running_staging():
|
||||
"""Currently used OpenPype is staging version.
|
||||
|
||||
Returns:
|
||||
bool: True if openpype version containt 'staging'.
|
||||
"""
|
||||
if "staging" in get_openpype_version():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
# ----------------------------------------
|
||||
# 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")
|
||||
|
|
@ -71,15 +131,66 @@ def get_remote_versions(*args, **kwargs):
|
|||
return None
|
||||
|
||||
|
||||
def get_latest_version(*args, **kwargs):
|
||||
def get_latest_version(staging=None, local=None, remote=None):
|
||||
"""Get latest version from repository path."""
|
||||
if staging is None:
|
||||
staging = is_running_staging()
|
||||
if op_version_control_available():
|
||||
return get_OpenPypeVersion().get_latest_version(*args, **kwargs)
|
||||
return get_OpenPypeVersion().get_latest_version(
|
||||
staging=staging,
|
||||
local=local,
|
||||
remote=remote
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
def get_expected_studio_version(staging=False):
|
||||
def get_expected_studio_version(staging=None):
|
||||
"""Expected production or staging version in studio."""
|
||||
if staging is None:
|
||||
staging = is_running_staging()
|
||||
if op_version_control_available():
|
||||
return get_OpenPypeVersion().get_expected_studio_version(staging)
|
||||
return None
|
||||
|
||||
|
||||
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
|
||||
if not is_running_from_build():
|
||||
return output
|
||||
|
||||
# Skip if build does not support version control
|
||||
if not op_version_control_available():
|
||||
return output
|
||||
|
||||
# Skip if path to folder with zip files is not accessible
|
||||
if 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())
|
||||
|
||||
staging = is_running_staging()
|
||||
# Get expected version (from settings)
|
||||
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(
|
||||
staging=staging,
|
||||
remote=True
|
||||
)
|
||||
# Check if current version is expected version
|
||||
return current_version == expected_version
|
||||
|
|
|
|||
|
|
@ -5,67 +5,15 @@ import platform
|
|||
import getpass
|
||||
import socket
|
||||
|
||||
import openpype.version
|
||||
from openpype.settings.lib import get_local_settings
|
||||
from .execute import get_openpype_execute_args
|
||||
from .local_settings import get_local_site_id
|
||||
from .python_module_tools import import_filepath
|
||||
from .openpype_version import (
|
||||
op_version_control_available,
|
||||
openpype_path_is_accessible,
|
||||
get_expected_studio_version,
|
||||
get_OpenPypeVersion
|
||||
is_running_from_build,
|
||||
get_openpype_version
|
||||
)
|
||||
|
||||
|
||||
def get_openpype_version():
|
||||
"""Version of pype that is currently used."""
|
||||
return openpype.version.__version__
|
||||
|
||||
|
||||
def get_build_version():
|
||||
"""OpenPype version of build."""
|
||||
# Return OpenPype version if is running from code
|
||||
if not is_running_from_build():
|
||||
return get_openpype_version()
|
||||
|
||||
# Import `version.py` from build directory
|
||||
version_filepath = os.path.join(
|
||||
os.environ["OPENPYPE_ROOT"],
|
||||
"openpype",
|
||||
"version.py"
|
||||
)
|
||||
if not os.path.exists(version_filepath):
|
||||
return None
|
||||
|
||||
module = import_filepath(version_filepath, "openpype_build_version")
|
||||
return getattr(module, "__version__", None)
|
||||
|
||||
|
||||
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["OPENPYPE_EXECUTABLE"]
|
||||
executable_filename = os.path.basename(executable_path)
|
||||
if "python" in executable_filename.lower():
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def is_running_staging():
|
||||
"""Currently used OpenPype is staging version.
|
||||
|
||||
Returns:
|
||||
bool: True if openpype version containt 'staging'.
|
||||
"""
|
||||
if "staging" in get_openpype_version():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_pype_info():
|
||||
"""Information about currently used Pype process."""
|
||||
executable_args = get_openpype_execute_args()
|
||||
|
|
@ -135,36 +83,3 @@ def extract_pype_info_to_file(dirpath):
|
|||
with open(filepath, "w") as file_stream:
|
||||
json.dump(data, file_stream, indent=4)
|
||||
return filepath
|
||||
|
||||
|
||||
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
|
||||
if not is_running_from_build():
|
||||
return output
|
||||
|
||||
# Skip if build does not support version control
|
||||
if not op_version_control_available():
|
||||
return output
|
||||
|
||||
# Skip if path to folder with zip files is not accessible
|
||||
if not openpype_path_is_accessible():
|
||||
return output
|
||||
|
||||
# Check if current version is expected version
|
||||
OpenPypeVersion = get_OpenPypeVersion()
|
||||
current_version = OpenPypeVersion(get_openpype_version())
|
||||
expected_version = get_expected_studio_version(is_running_staging())
|
||||
|
||||
return current_version == expected_version
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import os
|
||||
from openpype.lib.pype_info import is_running_staging
|
||||
from openpype.lib.openpype_version import is_running_staging
|
||||
|
||||
RESOURCES_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue