raise OpenPypeVersionNotFound in run from code too

This commit is contained in:
iLLiCiTiT 2021-12-07 18:38:43 +01:00
parent 5d03abe627
commit 9b369de50c

View file

@ -769,45 +769,50 @@ def _bootstrap_from_code(use_version, use_staging):
# get current version of OpenPype # get current version of OpenPype
local_version = bootstrap.get_local_live_version() local_version = bootstrap.get_local_live_version()
version_to_use = None
openpype_versions = bootstrap.find_openpype( openpype_versions = bootstrap.find_openpype(
include_zips=True, staging=use_staging) include_zips=True, staging=use_staging)
if use_staging and not use_version: if use_staging and not use_version:
try: if not openpype_versions:
version_to_use = openpype_versions[-1] raise OpenPypeVersionNotFound(
except IndexError: "Didn't find any staging versions."
_print("!!! No staging versions are found.") )
list_versions(openpype_versions, local_version)
sys.exit(1) # Use last found staging version
version_to_use = openpype_versions[-1]
if version_to_use.path.is_file(): if version_to_use.path.is_file():
version_to_use.path = bootstrap.extract_openpype( version_to_use.path = bootstrap.extract_openpype(
version_to_use) version_to_use)
bootstrap.add_paths_from_directory(version_to_use.path) bootstrap.add_paths_from_directory(version_to_use.path)
os.environ["OPENPYPE_VERSION"] = str(version_to_use) os.environ["OPENPYPE_VERSION"] = str(version_to_use)
version_path = version_to_use.path version_path = version_to_use.path
os.environ["OPENPYPE_REPOS_ROOT"] = (version_path / "openpype").as_posix() # noqa: E501 os.environ["OPENPYPE_REPOS_ROOT"] = (
version_path / "openpype"
).as_posix()
_openpype_root = version_to_use.path.as_posix() _openpype_root = version_to_use.path.as_posix()
elif use_version and use_version != local_version: elif use_version and use_version != local_version:
v: OpenPypeVersion version_to_use = None
found = [v for v in openpype_versions if str(v) == use_version] for version in openpype_versions:
if found: if str(version) == use_version:
version_to_use = sorted(found)[-1] version_to_use = version
break
if version_to_use: if version_to_use is None:
# use specified raise OpenPypeVersionNotFound(
if version_to_use.path.is_file(): "Requested version \"{}\" was not found.".format(use_version)
version_to_use.path = bootstrap.extract_openpype( )
version_to_use)
bootstrap.add_paths_from_directory(version_to_use.path) # use specified
os.environ["OPENPYPE_VERSION"] = use_version if version_to_use.path.is_file():
version_path = version_to_use.path version_to_use.path = bootstrap.extract_openpype(
os.environ["OPENPYPE_REPOS_ROOT"] = (version_path / "openpype").as_posix() # noqa: E501 version_to_use)
_openpype_root = version_to_use.path.as_posix() bootstrap.add_paths_from_directory(version_to_use.path)
else: os.environ["OPENPYPE_VERSION"] = use_version
_print(f"!!! Requested version {use_version} was not found.") version_path = version_to_use.path
list_versions(openpype_versions, local_version) os.environ["OPENPYPE_REPOS_ROOT"] = (
sys.exit(1) version_path / "openpype"
).as_posix()
_openpype_root = version_to_use.path.as_posix()
else: else:
os.environ["OPENPYPE_VERSION"] = local_version os.environ["OPENPYPE_VERSION"] = local_version
version_path = Path(_openpype_root) version_path = Path(_openpype_root)