MCPcopy
hub / github.com/flet-dev/flet / __get_assets_dir_path

Function __get_assets_dir_path

sdk/python/packages/flet/src/flet/app.py:500–531  ·  view source on GitHub ↗

Resolve assets directory to an absolute path and apply env override. Args: assets_dir: Input assets directory path. relative_to_cwd: Resolve relative paths from current working directory instead of current script directory. Returns: Resolved assets

(assets_dir: Optional[str], relative_to_cwd=False)

Source from the content-addressed store, hash-verified

498
499
500def __get_assets_dir_path(assets_dir: Optional[str], relative_to_cwd=False):
501 """
502 Resolve assets directory to an absolute path and apply env override.
503
504 Args:
505 assets_dir: Input assets directory path.
506 relative_to_cwd: Resolve relative paths from current working directory
507 instead of current script directory.
508
509 Returns:
510 Resolved assets directory path or `None`.
511 """
512
513 if assets_dir:
514 if not Path(assets_dir).is_absolute():
515 if "_MEI" in __file__:
516 # support for "onefile" PyInstaller
517 assets_dir = str(
518 Path(__file__).parent.parent.joinpath(assets_dir).resolve()
519 )
520 else:
521 assets_dir = str(
522 Path(os.getcwd() if relative_to_cwd else get_current_script_dir())
523 .joinpath(assets_dir)
524 .resolve()
525 )
526 logger.info("Assets path configured: %s", assets_dir)
527
528 env_assets_dir = os.getenv("FLET_ASSETS_DIR")
529 if env_assets_dir:
530 assets_dir = env_assets_dir
531 return assets_dir
532
533
534def __get_upload_dir_path(upload_dir: Optional[str], relative_to_cwd=False):

Callers 2

runFunction · 0.85
run_asyncFunction · 0.85

Calls 3

get_current_script_dirFunction · 0.90
PathClass · 0.85
infoMethod · 0.80

Tested by

no test coverage detected