Main entry point for AYON command.
Bootstrapping process of AYON.
This script is responsible for setting up the environment and bootstrapping AYON. It is also responsible for updating AYON from AYON server.
Arguments that are always handled by AYON launcher
--verbose - set log level --debug - enable debug mode --skip-headers - skip printing headers --skip-bootstrap - skip bootstrap process - use only for bootstrap logic --use-staging - use staging server --use-dev - use dev server --bundle - specify bundle name to use --headless - enable headless mode - bootstrap won't show any UI
AYON launcher can be running in multiple different states. The top layer of states is 'production', 'staging' and 'dev'.
To start in dev mode use one of following options
- by passing '--use-dev' argument
- by setting 'AYON_USE_DEV' environment variable to '1'
- by passing '--bundle '
- by setting 'AYON_BUNDLE_NAME' environment variable to dev bundle name
- by passing '--studio-bundle '
- by setting 'AYON_STUDIO_BUNDLE_NAME' environment variable to dev bundle name
By using bundle name you can start any dev bundle, even if is not
assigned to current user.
To start in staging mode make sure none of develop options are used and then use one of following options: - by passing '--use-staging' argument - by setting 'AYON_USE_STAGING' environment variable to '1'
Staging mode must be defined explicitly cannot be determined by bundle name. In all other cases AYON launcher will start in 'production' mode.
Headless mode is not guaranteed after bootstrap process. It is possible that some addon won't handle headless mode and will try to use UIs.
After bootstrap process AYON launcher will start 'ayon_core' addon. This addon is responsible for handling all other addons and their logic.
Environment variables set during bootstrap
- AYON_VERSION - version of AYON launcher
- AYON_BUNDLE_NAME - name of bundle to use
- AYON_USE_STAGING - set to '1' if staging mode is enabled
- AYON_USE_DEV - set to '1' if dev mode is enabled
- AYON_DEBUG - set to '1' if debug mode is enabled
- AYON_HEADLESS_MODE - set to '1' if headless mode is enabled
- AYON_SERVER_URL - URL of AYON server
- AYON_API_KEY - API key for AYON server
- AYON_SERVER_TIMEOUT - timeout for AYON server
- AYON_SERVER_RETRIES - number of retries for AYON server
- AYON_EXECUTABLE - path to AYON executable
- AYON_ROOT - path to AYON root directory
- AYON_MENU_LABEL - label for AYON integrations menu
- AYON_LAUNCHER_STORAGE_DIR - dir where addons, dependency packages, shim etc. are stored
- AYON_LAUNCHER_LOCAL_DIR - dir where machine specific files are stored
- AYON_ADDONS_DIR - path to AYON addons directory
- AYON_DEPENDENCIES_DIR - path to AYON dependencies directory
Some of the environment variables are not in this script but in 'ayon_common' module. - Function 'create_global_connection' can change 'AYON_USE_DEV' and 'AYON_USE_STAGING'. - Bootstrap will set 'AYON_LAUNCHER_STORAGE_DIR' and 'AYON_LAUNCHER_LOCAL_DIR' if are not set yet. - Distribution logic can set 'AYON_ADDONS_DIR' and 'AYON_DEPENDENCIES_DIR' if are not set yet.
StartArgScript
Source code in start.py
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272 | class StartArgScript:
def __init__(self, argument, script_path):
self.argument = argument
self.script_path = script_path
@property
def is_valid(self):
return self.script_path is not None
@property
def is_dir(self):
if self.argument:
return os.path.isdir(self.argument)
return False
@classmethod
def from_args(cls, args):
"""Get path argument from args and check if they can be started.
Args:
args (Iterable[str]): Arguments passed to AYON.
Returns:
StartArgScript: Object containing argument and script path.
"""
if len(args) < 2:
return cls(None, None)
path = args[1]
if os.path.exists(path):
if os.path.isdir(path):
new_path = os.path.join(path, "__main__.py")
if os.path.exists(new_path):
return cls(path, new_path)
else:
path_ext = os.path.splitext(path)[1].lower()
if path_ext in (".py", ".pyd", ".pyw", ".pyc"):
return cls(path, path)
return cls(path, None)
|
from_args(args) classmethod
Get path argument from args and check if they can be started.
Parameters:
| Name | Type | Description | Default |
args | Iterable[str] | Arguments passed to AYON. | required |
Returns:
| Name | Type | Description |
StartArgScript | | Object containing argument and script path. |
Source code in start.py
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272 | @classmethod
def from_args(cls, args):
"""Get path argument from args and check if they can be started.
Args:
args (Iterable[str]): Arguments passed to AYON.
Returns:
StartArgScript: Object containing argument and script path.
"""
if len(args) < 2:
return cls(None, None)
path = args[1]
if os.path.exists(path):
if os.path.isdir(path):
new_path = os.path.join(path, "__main__.py")
if os.path.exists(new_path):
return cls(path, new_path)
else:
path_ext = os.path.splitext(path)[1].lower()
if path_ext in (".py", ".pyd", ".pyw", ".pyc"):
return cls(path, path)
return cls(path, None)
|
boot()
Bootstrap AYON launcher.
Source code in start.py
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970 | def boot():
"""Bootstrap AYON launcher."""
with log_span("launcher.init_executable"):
init_launcher_executable()
# Setup site id in environment variable for all possible subprocesses
if SITE_ID_ENV_KEY not in os.environ:
os.environ[SITE_ID_ENV_KEY] = get_local_site_id()
with log_span("launcher.connection"):
_connect_to_ayon_server()
with log_span("launcher.distribution"):
_start_distribution()
fill_pythonpath()
# Call launcher storage dir getters to make sure their
# env variables are set
get_launcher_local_dir()
get_launcher_storage_dir()
|
fill_pythonpath()
Fill 'sys.path' with paths from PYTHONPATH environment variable.
Source code in start.py
943
944
945
946
947
948
949 | def fill_pythonpath():
"""Fill 'sys.path' with paths from PYTHONPATH environment variable."""
lookup_set = set(sys.path)
for path in (os.getenv("PYTHONPATH") or "").split(os.pathsep):
if path not in lookup_set:
sys.path.append(path)
lookup_set.add(path)
|
get_info(use_staging=None, use_dev=None)
Print additional information to console.
Source code in start.py
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344 | def get_info(use_staging=None, use_dev=None) -> RuntimeInfo:
"""Print additional information to console."""
studio_bundle_name = os.getenv("AYON_STUDIO_BUNDLE_NAME")
project_bundle_name = os.getenv("AYON_BUNDLE_NAME")
variant = "production"
if use_dev:
variant = f"dev ({project_bundle_name})"
elif use_staging:
variant = "staging"
if project_bundle_name == studio_bundle_name:
project_bundle_name = None
return RuntimeInfo(
version=__version__,
root=AYON_ROOT,
variant=variant,
studio_bundle=studio_bundle_name,
project_bundle=project_bundle_name,
)
|
init_launcher_executable(ensure_protocol_is_registered=False)
Initialize AYON launcher executable.
Make sure current AYON launcher executable is stored to known executables and shim is deployed.
Source code in start.py
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940 | def init_launcher_executable(ensure_protocol_is_registered=False):
"""Initialize AYON launcher executable.
Make sure current AYON launcher executable is stored to known executables
and shim is deployed.
"""
create_desktop_icons = "--create-desktop-icons" in sys.argv
store_current_executable_info()
try:
deploy_ayon_launcher_shims(
ensure_protocol_is_registered=ensure_protocol_is_registered,
create_desktop_icons=create_desktop_icons,
)
except ShimDeploymentError as exc:
if not HEADLESS_MODE_ENABLED:
show_failed_shim_deployment(str(exc))
sys.exit(1)
except Exception:
logger.exception("Unexpected error during shim deployment.")
if not HEADLESS_MODE_ENABLED:
show_failed_shim_deployment()
sys.exit(1)
|
main_cli()
Main startup logic.
This is the main entry point for the AYON launcher. At this moment is fully dependent on 'ayon_core' addon. Which means it contains more logic than it should.
Source code in start.py
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231 | def main_cli():
"""Main startup logic.
This is the main entry point for the AYON launcher. At this
moment is fully dependent on 'ayon_core' addon. Which means it
contains more logic than it should.
"""
# print info when not running scripts defined in 'silent commands'
if not SKIP_HEADERS:
info = get_info(
use_staging=is_staging_enabled(),
use_dev=is_dev_mode_enabled()
)
logger.info("AYON launcher initialized", info=asdict(info))
_print(">>> AYON Launcher Runtime Info:")
_print(f" - version: {info.version}")
_print(f" - variant: {info.variant}")
_print(f" - studio bundle: {info.studio_bundle}")
_print(f" - project bundle: {info.project_bundle}")
# 'ayon_core' configures logging on import, launcher logging must be
# released before
_STARTUP_SPAN.set(mode="cli", command=_get_cli_command(sys.argv[1:]))
_STARTUP_SPAN.finish()
release_logging()
try:
import ayon_core # noqa F401
except ModuleNotFoundError:
_on_main_addon_missing()
try:
from ayon_core import cli
except ImportError as exc:
logger.exception("Failed to import the AYON core CLI.")
_on_main_addon_import_error(exc)
try:
cli.main()
except Exception:
logger.exception("AYON crashed")
sys.exit(1)
|
script_cli(start_arg=None)
Run and execute script.
Source code in start.py
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311 | def script_cli(start_arg=None):
"""Run and execute script."""
if start_arg is None:
start_arg = StartArgScript.from_args(sys.argv)
# Remove first argument from sys.argv
# - start.py when running from code
# - ayon executable when running from build
sys.argv.pop(0)
# Find '__main__.py' in directory
if not start_arg.is_valid:
if not start_arg.argument:
raise RuntimeError("No script to run")
if start_arg.is_dir:
raise RuntimeError(
f"Can't find '__main__' module in '{start_arg.argument}'")
raise RuntimeError(f"Can't find script to run '{start_arg.argument}'")
filepath = start_arg.script_path
# Add parent dir to sys path
sys.path.insert(0, os.path.dirname(filepath))
# Read content and execute
with open(filepath, "r") as stream:
content = stream.read()
# Script may use 'ayon_core' which configures logging for itself
_STARTUP_SPAN.set(mode="script")
_STARTUP_SPAN.finish()
release_logging()
script_globals = dict(globals())
script_globals["__file__"] = filepath
exec(compile(content, filepath, "exec"), script_globals) # noqa: S102
|