Source code for schrodinger.utils.install_scripts
"""
Python code used in the Maestro Install Scripts panel.  Note that the panel
itself is in C++.
Copyright Schrodinger, LLC. All rights reserved.
"""
import ast
[docs]def get_module_docstring(filepath, default=""):
    """
    Get the docstring for a given module
    :param filepath: The path where the module is located
    :type filepath: str
    :param default: The docstring to use if the file cannot be parsed or does
        not contain a docstring.
    :type default: str
    :return: The docstring
    :rtype: str
    """
    try:
        with open(filepath) as fh:
            file_contents = fh.read()
    except OSError:
        return default
    # Use AST parsing to get docstring to avoid having dependencies
    # for import. Also, faster for builds.
    try:
        module_ast = ast.parse(file_contents)
        docstring = ast.get_docstring(module_ast)
    except (SyntaxError, ValueError):
        # If we can't parse the file for any reason, return the default
        # docstring
        return default
    if docstring:
        return docstring
    else:
        return default