1# SPDX-License-Identifier: Apache-2.0
2# -----------------------------------------------------------------------------
3# Copyright 2020 Arm Limited
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy
7# of the License at:
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16# -----------------------------------------------------------------------------
17"""
18A collection of useful utility functions that are not module specific.
19"""
20
21import os
22
23
24def path_splitall(path):
25    """
26    Utility function to split a relative path into its component pieces.
27
28    Args:
29        path(str): The relative path to split.
30
31    Returns:
32        list(str): An array of path parts.
33    """
34    # Sanity check we have a relative path on Windows
35    assert ":" not in path
36
37    parts = []
38    while path:
39        head, tail = os.path.split(path)
40        path = head
41        parts.insert(0, tail)
42
43    return parts
44