Path utilities
path_utilities ¶
A module for managing Edk2 file paths agnostic to OS path separators ("/" vs "\").
This module converts all windows style paths to Posix file paths internally, but will return the OS specific path with the exception of of any function that returns an Edk2 style path, which will always return Posix form.
Edk2Path ¶
Represents edk2 file paths.
Class that helps perform path operations within an EDK workspace.
Attributes:
Name | Type | Description |
---|---|---|
WorkspacePath |
str
|
Absolute path to the workspace root. |
PackagePathList |
List[str]
|
List of absolute paths to a package. |
Attributes are initialized by the constructor and are read-only.
Warning
Edk2Path performs expensive packages path and package validation when instantiated. If using the same Workspace root and packages path, it is suggested that only a single Edk2Path instance is instantiated and passed to any consumers.
__init__ ¶
__init__(
ws: os.PathLike,
package_path_list: Iterable[os.PathLike],
error_on_invalid_pp: bool = True,
) -> Edk2Path
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ws |
PathLike
|
absolute path or cwd relative path of the workspace. |
required |
package_path_list |
Iterable[PathLike]
|
list of packages path. Entries can be Absolute path, workspace relative path, or CWD relative. |
required |
error_on_invalid_pp |
bool
|
default value is True. If packages path value is invalid raise exception. |
True
|
Raises:
Type | Description |
---|---|
NotADirectoryError
|
Invalid workspace or package path directory. |
GetEdk2RelativePathFromAbsolutePath ¶
GetEdk2RelativePathFromAbsolutePath(*abspath: str) -> str
Transforms an absolute path to an edk2 path relative to the workspace or a packages path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*abspath |
str
|
absolute path to a file or directory. Can be the entire path or parts of the path provided separately. Supports both Windows and Posix style paths |
()
|
Returns:
Type | Description |
---|---|
str
|
POSIX-like path relative to the workspace or packages path |
None
|
abspath is None |
None
|
path is not valid |
Example
rel_path = edk2path.GetEdk2RelativePathFromAbsolutePath("C:/Workspace/edk2/MdePkg/Include")
rel_path = edk2path.GetEdk2RelativePathFromAbsolutePath("C:/Workspace", "edk2", "MdePkg", "Include")
GetAbsolutePathOnThisSystemFromEdk2RelativePath ¶
GetAbsolutePathOnThisSystemFromEdk2RelativePath(
*relpath: str, log_errors: Optional[bool] = True
) -> str
Given a relative path return an absolute path to the file in this workspace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*relpath |
str
|
Relative path to convert. Can be the entire path or parts of the path provided separately |
()
|
log_errors |
Optional[bool]
|
whether to log errors |
True
|
Returns:
Type | Description |
---|---|
str
|
absolute path in the OS specific form |
None
|
invalid relpath |
None
|
Unable to get the absolute path |
Example
abs_path = edk2path.GetAbsolutePathOnThisSystemFromEdk2RelativePath("MdePkg/Include")
abs_path = edk2path.GetAbsolutePathOnThisSystemFromEdk2RelativePath("MdePkg", "Include")
GetContainingPackage ¶
GetContainingPackage(InputPath: str) -> str
Finds the package that contains the given path.
This isn't perfect, but at least identifies the direcotry consistently.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
InputPath |
str
|
absolute path to a file, directory, or module. Supports both windows and posix paths. |
required |
Returns:
Type | Description |
---|---|
str
|
name of the package that the path is in. |
GetContainingModules ¶
GetContainingModules(input_path: str) -> list[str]
Find the list of modules (inf files) for a file path.
This function only accepts absolute paths. An exception will
be raised if a non-absolute path is given.
If input_path does not exist in the filesystem, this function
will try to return the likely containing module(s) but if the entire module has been deleted, this isn't possible.
- If a .inf file is given, that file is returned.
- Otherwise, the nearest set of .inf files (in the closest parent) will be returned in a list of file path strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_path |
str
|
Absolute path to a file, directory, or module. Supports both Windows and Posix like paths. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
Absolute paths of .inf files that could be the containing module. |