utils2p/main.py
def _find_file(directory, name, file_type, most_recent=True):
    """
    This function finds a unique file with a given name in
    in the directory.

    Parameters
    ----------
    directory : str
        Directory in which to search.
    name : str
        Name of the file.
    most_recent : bool
        If True, the file with the most recent change time
        is returned and no exception is raised if multiple
        files are present.

    Returns
    -------
    path : str
        Path to file.
    """
    file_names = list(Path(directory).rglob(name))
    if len(file_names) > 1:
        if most_recent:
            change_times = [os.stat(path).st_mtime for path in file_names]
            file_names = (file_names[np.argmax(change_times)], )
        else:
            raise RuntimeError(
                f"Could not identify {file_type} file unambiguously. " +
                f"Discovered {len(file_names)} {file_type} files in {directory}."
            )
    elif len(file_names) == 0:
        raise FileNotFoundError(f"No {file_type} file found in {directory}")
    return str(file_names[0])

    This function finds a unique file with a given name in
    in the directory.

    Parameters
    ----------
    directory : str
        Directory in which to search.
    name : str
        Name of the file.
    most_recent : bool
        If True, the file with the most recent change time
        is returned and no exception is raised if multiple
        files are present.

    Returns
    -------
    path : str
        Path to file.
    
This function finds a unique file with a given name in
in the directory.

Parameters

directory : str
Directory in which to search.
name : str
Name of the file.
most_recent : bool
If True, the file with the most recent change time
is returned and no exception is raised if multiple
files are present.

Returns

path : str
Path to file.
This function finds a unique file with a given name in in the directory . Parameters directory : str Directory in which to search . name : str Name of the file . most_recent : bool If True the file with the most recent change time is returned and no exception is raised if multiple files are present . Returns path : str Path to file .
def _find_file(directory, name, file_type, most_recent=True):
    file_names = list(Path(directory).rglob(name))
    if len(file_names) > 1:
        if most_recent:
            change_times = [os.stat(path).st_mtime for path in file_names]
            file_names = (file_names[np.argmax(change_times)], )
        else:
            raise RuntimeError(
                f"Could not identify {file_type} file unambiguously. " +
                f"Discovered {len(file_names)} {file_type} files in {directory}."
            )
    elif len(file_names) == 0:
        raise FileNotFoundError(f"No {file_type} file found in {directory}")
    return str(file_names[0])
def _find_file ( directory , name , file_type , most_recent = True ) : file_names = list ( Path ( directory ) . rglob ( name ) ) if len ( file_names ) > 1 : if most_recent : change_times = [ os . stat ( path ) . st_mtime for path in file_names ] file_names = ( file_names [ np . argmax ( change_times ) ] , ) else : raise RuntimeError ( f"Could not identify {file_type} file unambiguously. " + f"Discovered {len(file_names)} {file_type} files in {directory}." ) elif len ( file_names ) == 0 : raise FileNotFoundError ( f"No {file_type} file found in {directory}" ) return str ( file_names [ 0 ] )
This function finds a unique file with a given name in
in the directory.
This function finds a unique file with a given name in in the directory .
"""
    This function finds a unique file with a given name in
    in the directory.

    Parameters
    ----------
    directory : str
        Directory in which to search.
    name : str
        Name of the file.
    most_recent : bool
        If True, the file with the most recent change time
        is returned and no exception is raised if multiple
        files are present.

    Returns
    -------
    path : str
        Path to file.
    """
directory
name
file_type
most_recent