Exemplo n.º 1
0
    def setUpClass(cls):
        cls.MOOSE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
        cls._cache = mooseutils.git_ls_files(cls.MOOSE_DIR)

        cls.file_is_stub = getattr(sys.modules['moosesqa.check_syntax'], 'file_is_stub')
        cls.find_md_file = getattr(sys.modules['moosesqa.check_syntax'], 'find_md_file')
        cls._check_node = getattr(sys.modules['moosesqa.check_syntax'], '_check_node')
Exemplo n.º 2
0
def doc_tree(items):
    """
    Create a tree of files for processing.

    Inputs:
        inputs: [list[dict(),...] A list of dict items, each dict entry must contain the 'root_dir'
                and 'content' fields that are passed to the doc_import function.
    """
    # Error checking
    if not isinstance(items, list) or any(not isinstance(x, dict)
                                          for x in items):
        LOG.error(
            'The supplied items must be a list of dict items, each with a "root_dir" and '
            'optionally a "content" entry.')
        return None

    # Define a dict for storing nodes by path
    nodes = dict()

    # Create the root node
    nodes[()] = page.DirectoryNode(source='')

    # Create the file tree
    for value in items:

        if 'root_dir' not in value:
            LOG.error(
                'The supplied items must be a list of dict items, each with a "root_dir" and '
                'optionally a "content" entry.')

        root = mooseutils.eval_path(value['root_dir'])
        if not os.path.isabs(root):
            root = os.path.join(MooseDocs.ROOT_DIR, root)

        # Update the project files
        MooseDocs.PROJECT_FILES.update(
            mooseutils.git_ls_files(mooseutils.git_root_dir(root)))

        files = doc_import(root, content=value.get('content', None))
        for filename in files:
            key = tuple(filename.replace(root, '').strip('/').split('/'))

            # Create directory nodes if they don't exist
            for i in range(1, len(key)):
                dir_key = key[:i]
                if dir_key not in nodes:
                    nodes[dir_key] = page.DirectoryNode(nodes[key[:i - 1]],
                                                        name=key[i - 1],
                                                        source=os.path.join(
                                                            root, *dir_key))

            # Create the file node, if it doesn't already exist. This enforces that the first
            # item in the supplied content lists is the page that is rendered.
            if key not in nodes:
                nodes[key] = create_file_node(nodes[key[:-1]], key[-1],
                                              filename)

    return nodes[()]
Exemplo n.º 3
0
def _locate_filenames(directories, ext):
    """Locate files in the directories with the given extension."""

    out = set()
    for location in directories:
        for filename in mooseutils.git_ls_files(os.path.join(MooseDocs.ROOT_DIR, location)):
            if filename.endswith(ext) and not os.path.islink(filename):
                out.add(filename)
    return out
Exemplo n.º 4
0
 def _getFiles(locations):
     """Get complete list of files for the given *locations*."""
     file_list = list()
     for working_dir in locations:
         path = mooseutils.eval_path(working_dir)
         if mooseutils.git_is_repo(path):
             file_list += mooseutils.git_ls_files(path)
         else:
             file_list += glob.glob(os.path.join(path, '**', '*.*'),
                                    recursive=True)
     return file_list
Exemplo n.º 5
0
def compute_requirement_stats(location,
                              specs=['tests'],
                              working_dir=None,
                              show=True,
                              list_missing=False):
    """
    Report requirement statistics for the test spec files with the supplied location.

    Inputs:
        location: Path to directory contain test specifications, the supplied path should be
                  relative to the cwd input.
        specs: The filename(s) to consider
        working_dir: The working directory, if not supplied the root directory of the repository is used
    """
    from .hit_load import hit_load

    tests_with_missing_requirements = set()
    working_dir = git_root_dir(
        os.getcwd()) if working_dir is None else working_dir
    data = SQAStats(location)
    location = os.path.join(working_dir, location)
    for filename in git_ls_files(location):
        if not os.path.isfile(filename):
            continue
        fname = os.path.basename(filename)
        if fname in specs:
            root = hit_load(filename)
            has_requirement = False
            for child in root.children[0]:
                data.tests += 1

                deprecated = root.children[0].get(
                    'deprecated', False) or child.get('deprecated', False)
                if deprecated:
                    data.tests_deprecated += 1

                if child.get('requirement', None):
                    has_requirement = True
                    data.tests_with_requirement += 1
                elif not deprecated:
                    tests_with_missing_requirements.add((filename, child.name))

            data.files += 1

    if show:
        print(data)
    if list_missing and tests_with_missing_requirements:
        print('\nMissing Requirements:')
        for filename, test in tests_with_missing_requirements:
            print('{}:{}'.format(filename, test))

    return data
Exemplo n.º 6
0
    def execute(self, **kwargs):
        """Determine the status"""
        file_list = list()
        for working_dir in self.working_dirs:
            path = mooseutils.eval_path(working_dir)
            if mooseutils.is_git_repo(path):
                file_list += mooseutils.git_ls_files(path)
            else:
                file_list += glob.glob(os.path.join(path, '**', '*.*'),
                                       recursive=True)

        logger = check_documents(self.documents, file_list, **kwargs)
        return logger
Exemplo n.º 7
0
    def execute(self, **kwargs):
        """Perform app syntax checking"""

        # Check that the supplied content dir exists
        content_dir = mooseutils.eval_path(self.content_directory)
        if not os.path.isdir(content_dir):
            content_dir = os.path.join(self.working_dir, content_dir)
        if not os.path.isdir(content_dir):
            raise NotADirectoryError("'content_directory' input is not a directory: {}".format(content_dir))

        # Populate the available list of files
        file_cache = mooseutils.git_ls_files(content_dir)

        # Check that the supplied exe dir exists
        exe_dir = mooseutils.eval_path(self.exe_directory)
        if not os.path.isdir(exe_dir):
            exe_dir = os.path.join(self.working_dir, exe_dir)
        if not os.path.isdir(exe_dir):
            raise NotADirectoryError("'exe_directory' input is not a directory: {}".format(exe_dir))

        # Locate the executable
        exe = mooseutils.find_moose_executable(exe_dir, name=self.exe_name, show_error=False)
        if exe is None:
            raise OSError("An executable was not found in '{}' with a name '{}'.".format(exe_dir, self.exe_name))

        # Determine the application type (e.g., MooseTestApp)
        if self.app_types is None:
            out = subprocess.check_output([exe, '--type'], encoding='utf-8')
            match = re.search(r'^MooseApp Type:\s+(?P<type>.*?)$', out, flags=re.MULTILINE)
            if match:
                self.app_types = [match.group("type").replace('TestApp', 'App')]

        # Build syntax tree if not provided
        if self.app_syntax is None:

            # Get the removed/alias information
            remove = self._loadYamlFiles(self.remove)
            alias = self._loadYamlFiles(self.alias)
            unregister = self._loadYamlFiles(self.unregister)

            # Build the complete syntax tree
            self.app_syntax = moosesyntax.get_moose_syntax_tree(exe, remove=remove,
                                                                alias=alias, unregister=unregister)

        # Perform the checks
        kwargs.setdefault('syntax_prefix', mooseutils.eval_path(self.syntax_prefix))
        kwargs.setdefault('object_prefix', mooseutils.eval_path(self.object_prefix))
        kwargs.setdefault('allow_test_objects', self.allow_test_objects)
        logger = check_syntax(self.app_syntax, self.app_types, file_cache, **kwargs)

        return logger
Exemplo n.º 8
0
def doc_tree(items):
    """
    Create a tree of files for processing.

    Inputs:
        inputs: [list[dict(),...] A list of dict items, each dict entry must contain the 'root_dir'
                and 'content' fields that are passed to the doc_import function.
    """
    # Error checking
    if not isinstance(items, list) or any(not isinstance(x, dict) for x in items):
        LOG.error('The supplied items must be a list of dict items, each with a "root_dir" and '
                  'optionally a "content" entry.')
        return None

    # Define a dict for storing nodes by path
    nodes = dict()

    # Create the root node
    nodes[()] = page.DirectoryNode(source='')

    # Create the file tree
    for value in items:

        if 'root_dir' not in value:
            LOG.error('The supplied items must be a list of dict items, each with a "root_dir" and '
                      'optionally a "content" entry.')

        root = mooseutils.eval_path(value['root_dir'])
        if not os.path.isabs(root):
            root = os.path.join(MooseDocs.ROOT_DIR, root)

        # Update the project files
        MooseDocs.PROJECT_FILES.update(mooseutils.git_ls_files(mooseutils.git_root_dir(root)))

        files = doc_import(root, content=value.get('content', None))
        for filename in files:
            key = tuple(filename.replace(root, '').strip('/').split('/'))

            # Create directory nodes if they don't exist
            for i in range(1, len(key)):
                dir_key = key[:i]
                if dir_key not in nodes:
                    nodes[dir_key] = page.DirectoryNode(nodes[key[:i-1]],
                                                        name=key[i-1],
                                                        source=os.path.join(root, *dir_key))

            # Create the file node
            nodes[key] = create_file_node(nodes[key[:-1]], key[-1], filename)

    return nodes[()]
Exemplo n.º 9
0
def get_content(items, in_ext):
    """
    Create a tree of files for processing.

    Inputs:
        items: [list[dict(),...] A list of dict items, each dict entry must contain the 'root_dir'
                and 'content' fields that are passed to the doc_import function.
        in_ext[tuple]: Set of extensions to be converted (e.g., ('.md', )).
        out_ext[str]: The extension of rendered result (e.g., '.html').
    """
    if not isinstance(items, list) or any(not isinstance(x, dict)
                                          for x in items):
        LOG.error(
            'The supplied items must be a list of dict items, each with a "root_dir" and '
            'optionally a "content" entry.')
        return None

    roots = set()
    nodes = dict()
    for root, filename, external in get_files(items, in_ext):
        roots.add(root)
        key = filename.replace(root, '').strip('/')
        parts = key.split('/')

        # Create directory nodes if they don't exist
        for i in range(1, len(parts)):
            dir_key = os.path.join(*parts[:i])
            if dir_key not in nodes:
                nodes[dir_key] = pages.Directory(dir_key,
                                                 external=external,
                                                 source=os.path.join(
                                                     root, dir_key))

        # Create the file node, if it doesn't already exist. This enforces that the first
        # item in the supplied content lists is the page that is rendered.
        if key not in nodes:
            nodes[key] = create_file_page(key, filename, in_ext)

        nodes[key].external = external

    # Update the project files
    for root in roots:
        if mooseutils.is_git_repo(root):
            MooseDocs.PROJECT_FILES.update(
                mooseutils.git_ls_files(mooseutils.git_root_dir(root)))
        else:
            MooseDocs.PROJECT_FILES.update(mooseutils.list_files(root))

    return list(nodes.values())
Exemplo n.º 10
0
def get_requirements_from_tests(directories, specs):
    """
    Build requirements dictionary from the provided directories.

    Input:
        directories[list]: A list of directories to consider
        specs[list]: A list of test specification names (e.g., ['tests'])
    """
    out = collections.defaultdict(list)
    for location in directories:
        for filename in sorted(mooseutils.git_ls_files(location)):
            if os.path.isfile(filename) and (os.path.basename(filename)
                                             in specs):
                group = os.path.relpath(filename, location).split('/')[0]
                out[group] += get_requirements_from_file(filename)
    return out
Exemplo n.º 11
0
def get_requirements(directories, specs):
    """
    Build requirements dictionary from the provided directories.
    """
    out = collections.defaultdict(list)
    for location in directories:
        for filename in mooseutils.git_ls_files(location):
            if not os.path.isfile(filename):
                continue
            fname = os.path.basename(filename)
            if fname in specs:
                _add_requirements(out, location, filename)

    for i, requirements in enumerate(out.itervalues()):
        for j, req in enumerate(requirements):
            req.label = "F{}.{}".format(i+1, j+1)
    return out
Exemplo n.º 12
0
def get_requirements(directories, specs):
    """
    Build requirements dictionary from the provided directories.
    """
    out = collections.defaultdict(list)
    for location in directories:
        for filename in mooseutils.git_ls_files(location):
            if not os.path.isfile(filename):
                continue
            fname = os.path.basename(filename)
            if fname in specs:
                _add_requirements(out, location, filename)

    for i, requirements in enumerate(out.itervalues()):
        for j, req in enumerate(requirements):
            req.label = "F{}.{}".format(i+1, j+1)
    return out
Exemplo n.º 13
0
def _find_file(working_dir, pattern):
    """
    Helper for finding file in repository.

    see _create_specification
    """
    if pattern.startswith('/'):
        pattern = os.path.join(working_dir, pattern.strip('/'))

    matches = [f for f in mooseutils.git_ls_files(working_dir) if f.endswith(pattern)]

    if not matches:
        raise NameError("Unable to locate a test specification with pattern: {}".format(pattern))
    elif len(matches) > 1:
        msg = "Located multiple test specifications with pattern: {}\n".format(pattern)
        msg += "    \n".join(matches)
        raise NameError(msg)

    return matches[0]
Exemplo n.º 14
0
def get_content(items, in_ext):
    """
    Create a tree of files for processing.

    Inputs:
        items: [list[dict(),...] A list of dict items, each dict entry must contain the 'root_dir'
                and 'content' fields that are passed to the doc_import function.
        in_ext[tuple]: Set of extensions to be converted (e.g., ('.md', )).
        out_ext[str]: The extension of rendered result (e.g., '.html').
    """
    if not isinstance(items, list) or any(not isinstance(x, dict) for x in items):
        LOG.error('The supplied items must be a list of dict items, each with a "root_dir" and '
                  'optionally a "content" entry.')
        return None

    roots = set()
    nodes = dict()
    for root, filename in get_files(items, in_ext):
        roots.add(root)
        key = filename.replace(root, '').strip('/')
        parts = key.split('/')

        # Create directory nodes if they don't exist
        for i in range(1, len(parts)):
            dir_key = os.path.join(*parts[:i])
            if dir_key not in nodes:
                nodes[dir_key] = MooseDocs.tree.pages.Directory(dir_key,
                                                                source=os.path.join(root, dir_key))

        # Create the file node, if it doesn't already exist. This enforces that the first
        # item in the supplied content lists is the page that is rendered.
        if key not in nodes:
            nodes[key] = create_file_page(key, filename, in_ext)

    # Update the project files
    for root in roots:
        if mooseutils.is_git_repo(root):
            MooseDocs.PROJECT_FILES.update(mooseutils.git_ls_files(mooseutils.git_root_dir(root)))
        else:
            MooseDocs.PROJECT_FILES.update(mooseutils.list_files(root))

    return nodes.values()
Exemplo n.º 15
0
def get_requirements(directories, specs, prefix='F', category=None):
    """
    Build requirements dictionary from the provided directories.
    """
    out = collections.defaultdict(list)
    for location in directories:
        for filename in sorted(mooseutils.git_ls_files(location)):
            if not os.path.isfile(filename):
                continue
            fname = os.path.basename(filename)
            if fname in specs:
                _add_requirements(out, location, filename)

    for i, requirements in enumerate(out.values()):
        for j, req in enumerate(requirements):
            if category:
                req.label = "{}{}.{}.{}".format(prefix, category, i + 1, j + 1)
            else:
                req.label = "{}{}.{}".format(prefix, i + 1, j + 1)
    return out
Exemplo n.º 16
0
def compute_requirement_stats(location,
                              specs=['tests'],
                              working_dir=None,
                              show=True):
    """
    Report requirement statistics for the test spec files with the supplied location.

    Inputs:
        location: Path to directory contain test specifications, the supplied path should be
                  relative to the cwd input.
        specs: The filename(s) to consider
        working_dir: The working directory, if not supplied the root directory of the repository is used

    """
    working_dir = git_root_dir(
        os.getcwd()) if working_dir is None else working_dir
    data = SQAStats(location)
    location = os.path.join(working_dir, location)
    for filename in git_ls_files(location):
        if not os.path.isfile(filename):
            continue
        fname = os.path.basename(filename)
        if fname in specs:
            root = hit_load(filename)
            has_requirement = False
            for child in root.children[0]:
                data.tests += 1
                if child.get('requirement', None):
                    has_requirement = True
                    data.tests_with_requirement += 1

            data.files += 1
            if has_requirement:
                data.files_with_requirement += 1

    if show:
        print(data)
    return data
Exemplo n.º 17
0
def report_requirement_stats(location, specs):
    """
    Report requirement statistics for the test spec files with the supplied location.
    """
    requirements = 0
    tests = 0
    for filename in mooseutils.git_ls_files(location):
        if not os.path.isfile(filename):
            continue
        fname = os.path.basename(filename)
        if fname in specs:
            root = mooseutils.hit_load(filename)
            for child in root.children[0]:
                tests += 1
                if child.get('requirement', None):
                    requirements += 1

    complete = float(requirements) / float(tests)
    print 'Requirement Definitions ({:2.1f}% complete):'.format(complete * 100)
    print '                 Location: {}'.format(location)
    print '                    Specs: {}'.format(' '.join(specs))
    print '    Total Number of Tests: {}'.format(tests)
    print '  Tests with Requirements: {}'.format(requirements)
Exemplo n.º 18
0
def check_documents(documents, file_list=None, **kwargs):
    """
    Tool for checking SQA document deficiencies
    """

    # Setup logger, assume the names of the documents with a "log_" prefix are the logging flags (see get_documents)
    for doc in documents:
        kwargs.setdefault("log_" + doc.name, logging.ERROR)
    logger = LogHelper(__name__, **kwargs)

    # Setup file_list, if not provided
    if (file_list is None) and (not mooseutils.is_git_repo()):
        msg = "If the 'file_list' is not provided then the working directory must be a git repository."
        raise ValueError(msg)
    elif file_list is None:
        root = mooseutils.git_root_dir()
        file_list = mooseutils.git_ls_files(root, recurse_submodules=False)

    # Perform document checks
    for doc in documents:
        _check_document(doc.name, doc.filename, file_list, logger)

    return logger
Exemplo n.º 19
0
def report_requirement_stats(location, specs):
    """
    Report requirement statistics for the test spec files with the supplied location.
    """
    requirements = 0
    tests = 0
    for filename in mooseutils.git_ls_files(location):
        if not os.path.isfile(filename):
            continue
        fname = os.path.basename(filename)
        if fname in specs:
            root = mooseutils.hit_load(filename)
            for child in root.children[0]:
                tests += 1
                if child.get('requirement', None):
                    requirements += 1

    complete = float(requirements)/float(tests)
    print 'Requirement Definitions ({:2.1f}% complete):'.format(complete*100)
    print '                 Location: {}'.format(location)
    print '                    Specs: {}'.format(' '.join(specs))
    print '    Total Number of Tests: {}'.format(tests)
    print '  Tests with Requirements: {}'.format(requirements)
Exemplo n.º 20
0
import subprocess
import logging

if sys.version_info < (3, 6):
    print('"MOOSEDocs" requires python version 3.6 or greater, version {}.{} is being used.' \
          .format(sys.version_info[0], sys.version_info[1]))
    sys.exit(1)

import mooseutils

# Current logging level, used to allow for debug only type checking, etc.
LOG_LEVEL = logging.NOTSET

# The repository root location
ROOT_DIR = mooseutils.git_root_dir()
os.environ['ROOT_DIR'] = ROOT_DIR

# Setup MOOSE_DIR/ROOT_DIR
MOOSE_DIR = os.getenv('MOOSE_DIR', None)
if MOOSE_DIR is None:
    print(
        "The MOOSE_DIR environment must be set, this should be set within moosedocs.py."
    )
    sys.exit(1)

# List all files with git, this is done here to avoid running this command many times
PROJECT_FILES = mooseutils.git_ls_files(ROOT_DIR)
PROJECT_FILES.update(mooseutils.git_ls_files(MOOSE_DIR))
PROJECT_FILES.update(
    mooseutils.git_ls_files(os.path.join(MOOSE_DIR, 'large_media')))
Exemplo n.º 21
0
    def execute(self, **kwargs):
        """Perform app syntax checking"""

        # Check that the supplied content dir exists
        content_dir = mooseutils.eval_path(self.content_directory)
        if not os.path.isdir(content_dir):
            content_dir = os.path.join(self.working_dir, content_dir)
        if not os.path.isdir(content_dir):
            raise NotADirectoryError(
                "'content_directory' input is not a directory: {}".format(
                    content_dir))

        # Populate the available list of files
        file_cache = mooseutils.git_ls_files(content_dir)

        # Check that the supplied exe dir exists
        exe_dir = mooseutils.eval_path(self.exe_directory)
        if not os.path.isdir(exe_dir):
            exe_dir = os.path.join(self.working_dir, exe_dir)
        if not os.path.isdir(exe_dir):
            raise NotADirectoryError(
                "'exe_directory' input is not a directory: {}".format(exe_dir))

        # Locate the executable
        exe = mooseutils.find_moose_executable(exe_dir,
                                               name=self.exe_name,
                                               show_error=False)
        if exe is None:
            raise OSError(
                "An executable was not found in '{}' with a name '{}'.".format(
                    exe_dir, self.exe_name))

        # Build syntax tree if not provided
        if self.app_syntax is None:

            # Get the hidden/removed/alias information
            hide = self._loadYamlFiles(self.hidden)
            remove = self._loadYamlFiles(self.remove)
            alias = self._loadYamlFiles(self.alias)
            unregister = self._loadYamlFiles(self.unregister)

            # Build the complete syntax tree
            self.app_syntax = moosesyntax.get_moose_syntax_tree(
                exe,
                hide=hide,
                remove=remove,
                alias=alias,
                unregister=unregister,
                allow_test_objects=self.allow_test_objects)

        # Determine the application type (e.g., MooseTestApp)
        if self.app_types is None:
            out = mooseutils.run_executable(exe, ['--type'])
            match = re.search(r'^MooseApp Type:\s+(?P<type>.*?)$',
                              out,
                              flags=re.MULTILINE)
            if match:
                self.app_types = [
                    match.group("type").replace('TestApp', 'App')
                ]

        # Perform the checks
        kwargs.setdefault('syntax_prefix',
                          mooseutils.eval_path(self.syntax_prefix))
        kwargs.setdefault('object_prefix',
                          mooseutils.eval_path(self.object_prefix))
        logger = check_syntax(self.app_syntax, self.app_types, file_cache,
                              **kwargs)

        # Create stub pages
        if self.generate_stubs:
            func = lambda n: (not n.removed) \
                             and ('_md_file' in n) \
                             and ((n['_md_file'] is None) or n['_is_stub']) \
                             and ((n.group in self.app_types) \
                                  or (n.groups() == set(self.app_types)))
            for node in moosetree.iterate(self.app_syntax, func):
                self._createStubPage(node)

        # Dump
        if self.dump_syntax:
            print(self.app_syntax)

        return logger
Exemplo n.º 22
0
    MSG += "    pip install --upgrade --user anytree"
    print MSG
    sys.exit(1)

import mooseutils

# Markdown component types TODO: Move these to reader
BLOCK = 'block'
INLINE = 'inline'

# Current logging level, used to allow for debug only type checking, etc.
LOG_LEVEL = logging.NOTSET

# The repository root location
ROOT_DIR = mooseutils.git_root_dir()
os.environ['ROOT_DIR'] = ROOT_DIR

# File extensions to consider when building the content tree
FILE_EXT = ('.md', '.jpg', '.jpeg', '.gif', '.png', '.svg', '.ogg', '.webm', '.mp4', '.css', \
            '.js', '.bib', '.woff', '.woff2')

# Setup MOOSE_DIR/ROOT_DIR
MOOSE_DIR = os.getenv('MOOSE_DIR', None)
if MOOSE_DIR is None:
    print "The MOOSE_DIR environment must be set, this should be set within moosedocs.py."
    sys.exit(1)

# List all files with git, this is done here to avoid running this command many times
PROJECT_FILES = mooseutils.git_ls_files(ROOT_DIR)
PROJECT_FILES.update(mooseutils.git_ls_files(MOOSE_DIR))
Exemplo n.º 23
0
def check_requirements(requirements,
                       file_list=None,
                       color_text=True,
                       allowed_collections=None,
                       allowed_classifications=None,
                       **kwargs):
    """
    Tool for checking Requirement for deficiencies
    """

    # Create key values for the logging messages
    log_default = kwargs.get('log_default', logging.ERROR)
    kwargs.setdefault('log_deprecated_requirement', log_default)
    kwargs.setdefault('log_deprecated_design', log_default)
    kwargs.setdefault('log_deprecated_issues', log_default)
    kwargs.setdefault('log_deprecated_detail', log_default)
    kwargs.setdefault('log_deprecated_verification', log_default)
    kwargs.setdefault('log_deprecated_validation', log_default)
    kwargs.setdefault('log_deprecated_with_details', log_default)
    kwargs.setdefault('log_missing', log_default)
    kwargs.setdefault('log_missing_requirement', log_default)
    kwargs.setdefault('log_missing_design', log_default)
    kwargs.setdefault('log_missing_issues', log_default)
    kwargs.setdefault('log_empty_requirement', log_default)
    kwargs.setdefault('log_empty_design', log_default)
    kwargs.setdefault('log_empty_issues', log_default)
    kwargs.setdefault('log_empty_verification', log_default)
    kwargs.setdefault('log_empty_validation', log_default)
    kwargs.setdefault('log_top_level_detail', log_default)
    kwargs.setdefault('log_missing_detail', log_default)
    kwargs.setdefault('log_empty_detail', log_default)
    kwargs.setdefault('log_extra_requirement', log_default)
    kwargs.setdefault('log_extra_design', log_default)
    kwargs.setdefault('log_extra_issues', log_default)
    kwargs.setdefault('log_extra_collections', log_default)
    kwargs.setdefault('log_invalid_collection', log_default)
    kwargs.setdefault('log_issue_format', log_default)
    kwargs.setdefault('log_design_files', log_default)
    kwargs.setdefault('log_validation_files', log_default)
    kwargs.setdefault('log_verification_files', log_default)
    kwargs.setdefault('log_testable', log_default)
    kwargs.setdefault('log_duplicate_requirement', log_default)
    kwargs.setdefault('log_duplicate_detail', log_default)

    logger = RequirementLogHelper(__name__, **kwargs)
    RequirementLogHelper.COLOR_TEXT = color_text

    # Setup file_list, if not provided
    if (file_list is None) and (not mooseutils.git_is_repo()):
        msg = "If the 'file_list' is not provided then the working directory must be a git repository."
        raise ValueError(msg)
    elif file_list is None:
        root = mooseutils.git_root_dir()
        ver = mooseutils.git_version()
        file_list = mooseutils.git_ls_files(root, recurse_submodules=True)

    # Setup allowed collections
    if allowed_collections is None:
        allowed_collections = set(moosesqa.MOOSESQA_COLLECTIONS)

    # Storage container for duplicate detection
    requirement_dict = collections.defaultdict(set)

    # Check each Requirement object for deficiencies
    for req in requirements:
        _check_requirement(req, logger, file_list, allowed_collections)
        if req.requirement is not None:
            key = [req.requirement]
            for detail in req.details:
                if detail.detail is not None:
                    key.append(detail.detail)
            requirement_dict['\n'.join(key)].add(req)

    # Duplicate checking
    for txt, value in requirement_dict.items():
        if len(value) > 1:
            msg = 'Duplicate requirements found:'
            msg += '\n{}\n'.format(
                mooseutils.colorText(txt, 'GREY', colored=color_text))
            for r in value:
                r.duplicate = True
                msg += RequirementLogHelper._colorTestInfo(r, None, None, None)

            LogHelper.log(logger, 'log_duplicate_requirement', msg.strip('\n'))

    return logger
Exemplo n.º 24
0
#* All rights reserved, see COPYRIGHT for full restrictions
#* https://github.com/idaholab/moose/blob/master/COPYRIGHT
#*
#* Licensed under LGPL 2.1, please see LICENSE for details
#* https://www.gnu.org/licenses/lgpl-2.1.html
import os
import sys
import subprocess
import logging

import mooseutils

# Current logging level, used to allow for debug only type checking, etc.
LOG_LEVEL = logging.NOTSET

# The repository root location
ROOT_DIR = mooseutils.git_root_dir()
os.environ['ROOT_DIR'] = ROOT_DIR

# Setup MOOSE_DIR/ROOT_DIR
MOOSE_DIR = os.getenv('MOOSE_DIR', None)
if MOOSE_DIR is None:
    print(
        "The MOOSE_DIR environment must be set, this should be set within moosedocs.py."
    )
    sys.exit(1)

# List all files with git, this is done here to avoid running this command many times
PROJECT_FILES = mooseutils.git_ls_files(ROOT_DIR)
PROJECT_FILES.update(mooseutils.git_ls_files(MOOSE_DIR))
Exemplo n.º 25
0
 def testGitLsFiles(self):
     files = mooseutils.git_ls_files()
     self.assertIn(os.path.abspath(__file__), files)
Exemplo n.º 26
0
        os.path.join(os.path.dirname(__name__), '..', '..', 'moose'))
if not os.path.exists(MOOSE_DIR):
    raise Exception(
        'Failed to locate MOOSE, specify the MOOSE_DIR environment variable.')
os.environ['MOOSE_DIR'] = MOOSE_DIR

# Locate BlackBear directory
BLACKBEAR_DIR = os.getenv('BLACKBEAR_DIR',
                          os.path.join(os.getcwd(), '..', 'blackbear'))
if not os.path.exists(os.path.join(BLACKBEAR_DIR, 'src')):
    BLACKBEAR_DIR = os.getenv(
        'BLACKBEAR_DIR', os.path.join(os.getcwd(), '..', '..', 'blackbear'))
if not os.path.exists(BLACKBEAR_DIR):
    raise Exception(
        'Failed to locate BlackBear, specify the BLACKBEAR_DIR environment variable.'
    )
os.environ['BLACKBEAR_DIR'] = os.path.abspath(BLACKBEAR_DIR)

# Append MOOSE python directory
MOOSE_PYTHON_DIR = os.path.join(MOOSE_DIR, 'python')
if MOOSE_PYTHON_DIR not in sys.path:
    sys.path.append(MOOSE_PYTHON_DIR)

import MooseDocs
import mooseutils
MooseDocs.PROJECT_FILES.update(mooseutils.git_ls_files(BLACKBEAR_DIR))

from MooseDocs import main
if __name__ == '__main__':
    sys.exit(main.run())
Exemplo n.º 27
0
                          *['{:,}'.format(totals[key]) for key in titles]))


if __name__ == '__main__':
    args = get_options()

    # Populate desired langauges
    lang = collections.OrderedDict()
    for key in args.languages:
        lang[key] = LANGUAGES[key]

    # List all files in the repository
    all_files = set()
    for location in args.locations:
        all_files.update(
            mooseutils.git_ls_files(os.path.abspath(args.locations[0]),
                                    exclude=args.exclude))

    # Group filenames by extension
    groups = collections.defaultdict(list)
    for filename in all_files:
        for key, func in lang.items():
            if func(filename):
                groups[key].append(filename)

    # Report author counts by file type
    counts = collections.defaultdict(lambda: {g: 0 for g in lang.keys()})
    for group, files in groups.items():
        print('Counting {} lines...'.format(group), end='')
        with multiprocessing.Pool(processes=args.num_threads) as pool:
            for c in pool.imap_unordered(target, files):
                update_count(c, group, counts)