
Fixing issues with the ResourceFinder and the CollectionPlugin not finding files if test-case-level pytest paths were getting used. Change-Id: I317749a0d5f5908105c525f4f33ee786b0ff1a1b Signed-off-by: croy <Christian.Roy@windriver.com>
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
# This utility file contains functions to help the code find the path to resource files
|
|
# when starlingx gets used as a submodule, or from outside code.
|
|
import os.path
|
|
from pathlib import Path
|
|
|
|
|
|
def get_stx_repo_root() -> str:
|
|
"""
|
|
Find the full path to the repository root.
|
|
|
|
Uses the position of the current file relative to the root of the repo.
|
|
|
|
Returns:
|
|
str: The absolute path to the repository root.
|
|
|
|
Example:
|
|
>>> get_repo_root()
|
|
will return /home/user/repo/starlingx
|
|
"""
|
|
path_of_this_file = Path(__file__)
|
|
|
|
# This file is in framework/resources/resource_finder.py, so go up 3 levels
|
|
root_folder = path_of_this_file.parent.parent.parent
|
|
return root_folder.as_posix()
|
|
|
|
|
|
def get_stx_resource_path(relative_path: str) -> str:
|
|
"""
|
|
This function will get the full path to the resource from the relative_path provided.
|
|
|
|
This will allow projects that use StarlingX as a submodule to still find resource files using the relative path.
|
|
|
|
Args:
|
|
relative_path (str): The relative path to the resource.
|
|
|
|
Returns:
|
|
str: The full path to the resource.
|
|
|
|
Example:
|
|
>>> get_resource_path("framework/resources/resource_finder.py")
|
|
will return /home/user/repo/starlingx/framework/resources/resource_finder.py
|
|
"""
|
|
# check to see if the path really is relative, if not just return the path
|
|
if os.path.isabs(relative_path):
|
|
return relative_path
|
|
root_folder_of_stx = get_stx_repo_root()
|
|
path_to_resource = Path(root_folder_of_stx, relative_path).as_posix()
|
|
|
|
return path_to_resource
|