def _find_directory_upwards(base: str, target: str) -> Optional[str]:
    """
    Walk directories upwards from base, until the root directory is
    reached. At each step, check if the target directory exist, and return
    it if found. Return None if the search is unsuccessful.
    """
    while True:
        step = os.path.join(base, target)
        LOG.debug("Trying with: `%s`", step)
        if os.path.isdir(step):
            return step
        parent_directory = os.path.dirname(base)
        if parent_directory == base:
            # We have reached the root.
            break
        base = parent_directory
    return None
def _find_directory_upwards ( base : str , target : str ) -> Optional [ str ] : while True : step = os . path . join ( base , target ) LOG . debug ( "Trying with: `%s`" , step ) if os . path . isdir ( step ) : return step parent_directory = os . path . dirname ( base ) if parent_directory == base : break base = parent_directory return None
Walk directories upwards from base, until the root directory is
    reached. At each step, check if the target directory exist, and return
    it if found. Return None if the search is unsuccessful.