Ejemplo n.º 1
0
def update_internal_paths(paths):
    """.. Update within-directory paths using default configuration file.
    
    Returns dictionary ``paths`` with directory locations listed in file ``config``.
    
    Parameters
    ----------
    paths : dict 
        Dictionary of paths to update. 
        Dictionary should ex-ante contain values for all keys listed below.

    Path Keys
    ---------
    root : str
        Path of project repo root
    config : str
        Path of user configuration file.  

    Returns
    -------
    paths : dict
        Dictionary of paths. 
    """

    try:
        config_default = get_path(paths, 'config')
        config_default = open_yaml(config_default)

        root = get_path(paths, 'root')
        relative_paths = {path_label: os.path.join(root, path) for \
            path_label, path in config_default['make_paths']['root_relative'].items()}
        absolute_paths = config_default['make_paths']['absolute']

        paths.update(relative_paths)
        paths.update(absolute_paths)

        return (paths)

    except:
        error_message = 'Error with update_external_paths. Traceback can be found below.'
        error_message = format_message(error_message)
        raise_from(ColoredError(error_message, traceback.format_exc()), None)
Ejemplo n.º 2
0
def update_paths(paths):
    """.. Update paths using user configuration file. 
    
    Updates dictionary ``paths`` with externals listed in file ``config_user``.
    
    Note
    ----
    The ``paths`` argument for :ref:`sourcing functions<sourcing functions>` is used not only to get 
    default paths for writing/logging, but also to 
    `string format <https://docs.python.org/3.4/library/string.html#format-string-syntax>`__ 
    sourcing instructions.
    
    Parameters
    ----------
    paths : dict 
        Dictionary of paths to update. 
        Dictionary should ex-ante contain values for all keys listed below.

    Path Keys
    ---------
    config_user : str
        Path of user configuration file.  

    Returns
    -------
    paths : dict
        Dictionary of updated paths. 
    """

    try:
        config_user = get_path(paths, 'config_user')
        config_user = open_yaml(config_user)

        if config_user['external']:
            paths.update(config_user['external'])

        return (paths)
    except:
        error_message = 'Error with update_paths. Traceback can be found below.'
        error_message = format_message(error_message)
        raise_from(ColoredError(error_message, traceback.format_exc()), None)
Ejemplo n.º 3
0
def update_executables(paths, osname=None):
    """.. Update executable names using user configuration file. 
    
    Updates executable names with executables listed in file ``config_user``.
    
    Note
    ----
    Executable names are used by :ref:`program functions <program functions>`.
    
    Parameters
    ----------
    paths : dict 
        Dictionary of paths. Dictionary should contain values for all keys listed below.
    osname : str, optional
        Name of OS. Defaults to ``os.name``.

    Path Keys
    ---------
    config_user : str
        Path of user configuration file.   

    Returns
    -------
    None
    """

    osname = osname if osname else os.name  # https://github.com/sphinx-doc/sphinx/issues/759

    try:
        config_user = get_path(paths, 'config_user')
        config_user = open_yaml(config_user)

        _check_os(osname)

        if config_user['local']['executables']:
            metadata.default_executables[osname].update(
                config_user['local']['executables'])
    except:
        error_message = 'Error with update_executables. Traceback can be found below.'
        error_message = format_message(error_message)
        raise_from(ColoredError(error_message, traceback.format_exc()), None)
Ejemplo n.º 4
0
def check_module_size(paths):
    """.. Check file sizes for module.

    Checks file sizes for files to be committed in the current working directory. 
    Compares file sizes to size limits in file ``config`` and 
    produces warnings if any of the following limits are exceeded.

    - Individual size of a file tracked by git lfs (``file_MB_limit_lfs``)
    - Total size of all files tracked by git lfs (``total_MB_limit_lfs``)
    - Individual size of a file tracked by git (``file_MB_limit``)
    - Total size of all files tracked by git (``total_MB_limit``)
   
    Warning messages are appended to file ``makelog``.

    Parameters
    ----------
    paths : dict 
        Dictionary of paths. Dictionary should contain values for all keys listed below.

    Path Keys
    ---------
    config : str
        Path of project configuration file.   
    makelog : str
        Path of makelog.

    Returns
    -------
    None
    """

    try:
        git_files, git_lfs_files = _get_dir_sizes('.')
        file_MB, total_MB, file_MB_lfs, total_MB_lfs = _get_size_values(
            git_files, git_lfs_files)

        config = get_path(paths, 'config')
        config = open_yaml(config)
        max_file_sizes = config['max_file_sizes']

        print_message = ''
        if file_MB > max_file_sizes['file_MB_limit']:
            print_message = print_message + messages.warning_git_file_print % max_file_sizes[
                'file_MB_limit']
        if total_MB > max_file_sizes['total_MB_limit']:
            print_message = print_message + messages.warning_git_repo % max_file_sizes[
                'total_MB_limit']
        if file_MB_lfs > max_file_sizes['file_MB_limit_lfs']:
            print_message = print_message + messages.warning_git_lfs_file_print % max_file_sizes[
                'file_MB_limit_lfs']
        if total_MB_lfs > max_file_sizes['total_MB_limit_lfs']:
            print_message = print_message + messages.warning_git_lfs_repo % max_file_sizes[
                'total_MB_limit_lfs']
        print_message = print_message.strip()

        log_message = ''
        if file_MB > max_file_sizes['file_MB_limit']:
            log_message = log_message + messages.warning_git_file_log % max_file_sizes[
                'file_MB_limit']
            exceed_files = [
                f for (f, s) in git_files.items()
                if s / (1024**2) > max_file_sizes['file_MB_limit']
            ]
            exceed_files = '\n'.join(exceed_files)
            log_message = log_message + '\n' + exceed_files
        if total_MB > max_file_sizes['total_MB_limit']:
            log_message = log_message + messages.warning_git_repo % max_file_sizes[
                'total_MB_limit']
        if file_MB_lfs > max_file_sizes['file_MB_limit_lfs']:
            log_message = log_message + messages.warning_git_lfs_file_log % max_file_sizes[
                'file_MB_limit_lfs']
            exceed_files = [
                f for (f, s) in git_lfs_files.items()
                if s / (1024**2) > max_file_sizes['file_MB_limit_lfs']
            ]
            exceed_files = '\n'.join(exceed_files)
            log_message = log_message + '\n' + exceed_files
        if total_MB_lfs > max_file_sizes['total_MB_limit_lfs']:
            log_message = log_message + messages.warning_git_lfs_repo % max_file_sizes[
                'total_MB_limit_lfs']
        log_message = log_message.strip()

        if print_message:
            print(colored(print_message, metadata.color_failure))
        if log_message:
            write_to_makelog(paths, log_message)
    except:
        error_message = 'Error with `check_repo_size`. Traceback can be found below.'
        error_message = format_message(error_message)
        write_to_makelog(paths,
                         error_message + '\n\n' + traceback.format_exc())
        raise_from(ColoredError(error_message, traceback.format_exc()), None)