Esempio n. 1
0
def assert_all_registered_modules(package_name, package,
                                  must_have_function_names):
    """Asserts that for given package all of its modules are properly registered in Perun

    Moreover checks that all of the must have functions are implemented as well.

    Arguments:
        package_name(str): name of the package we are checking all the modules
        package(module): checked package
        must_have_function_names(list): list of functions that the module from package has to have
          registered
    """
    registered_modules = utils.get_supported_module_names(package_name)
    for (_, module_name, _) in pkgutil.iter_modules(package.__path__,
                                                    package.__name__ + '.'):
        module = utils.get_module(module_name)
        for must_have_function_name in must_have_function_names:
            assert hasattr(
                module,
                must_have_function_name) and "Missing {} in module {}".format(
                    must_have_function_name, module_name)

        # Each module has to be registered in get_supported_module_names
        unit_name = module_name.split('.')[-1]
        assert unit_name in registered_modules and "{} was not registered properly".format(
            module_name)
Esempio n. 2
0
def assert_all_registered_cli_units(package_name, package,
                                    must_have_function_names):
    """Asserts that for given package all of its modules are properly registered in Perun

    Moreover checks that it has the CLI interface function in order to be called through click,
    and that certain functions are implemented as well (namely collect/postprocess) in order
    to automate the process of profile generation and postprocessing.

    Arguments:
        package_name(str): name of the package we are checking all the modules
        package(module): checked package (one of collect, postprocess, view)
        must_have_function_names(list): list of functions that the module from package has to have
          registered
    """
    registered_modules = utils.get_supported_module_names(package_name)
    for (_, module_name, _) in pkgutil.iter_modules(package.__path__,
                                                    package.__name__ + '.'):
        # Each module has to have run.py module
        module = utils.get_module(module_name)
        assert hasattr(
            module, 'run'
        ) and "Missing module run.py in the '{}' module".format(package_name)
        run_module = utils.get_module(".".join([module_name, "run"]))
        for must_have_function_name in must_have_function_names:
            assert not must_have_function_name or hasattr(run_module, must_have_function_name) and \
                "run.py is missing '{}' function".format(must_have_function_name)

        # Each module has to have CLI interface function of the same name
        unit_name = module_name.split('.')[-1]
        assert hasattr(
            run_module,
            unit_name) and "{} is missing CLI function point".format(unit_name)

        # Each module has to be registered in get_supported_module_names
        assert unit_name in registered_modules and "{} was not registered properly".format(
            module_name)
Esempio n. 3
0
    if 'vcs_params' not in ctx.params.keys():
        ctx.params['vcs_params'] = {}
    for v in value:
        if param.name.endswith("param"):
            ctx.params['vcs_params'][v[0]] = v[1]
        else:
            ctx.params['vcs_params'][v] = True
    return value


@cli.command()
@click.argument('dst', required=False, default=os.getcwd(), metavar='<path>')
@click.option('--vcs-type',
              metavar='<type>',
              default='git',
              type=click.Choice(utils.get_supported_module_names('vcs')),
              help="In parallel to initialization of Perun, initialize the vcs"
              " of <type> as well (by default ``git``).")
@click.option('--vcs-path',
              metavar='<path>',
              help="Sets the destination of wrapped vcs initialization at "
              "<path>.")
@click.option('--vcs-param',
              nargs=2,
              metavar='<param>',
              multiple=True,
              callback=parse_vcs_parameter,
              help="Passes additional (key, value) parameter to initialization"
              " of version control system, e.g. ``separate-git-dir dir``.")
@click.option('--vcs-flag',
              nargs=1,