How to use the peru.module.Module function in peru

To help you get started, we’ve selected a few peru examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github buildinspace / peru / tests / test_parser.py View on Github external
def test_parse_module_default_rule(self):
        input = dedent("""\
            git module bar:
                export: bar
            """)
        scope, imports = parse_string(input)
        self.assertIn("bar", scope.modules)
        module = scope.modules["bar"]
        self.assertIsInstance(module, Module)
        self.assertIsInstance(module.default_rule, Rule)
        self.assertEqual(module.default_rule.export, "bar")
github buildinspace / peru / tests / test_parser.py View on Github external
def test_parse_module(self):
        input = dedent("""\
            sometype module foo:
                url: http://www.example.com/
                rev: abcdefg
            """)
        scope, imports = parse_string(input)
        self.assertIn("foo", scope.modules)
        module = scope.modules["foo"]
        self.assertIsInstance(module, Module)
        self.assertEqual(module.name, "foo")
        self.assertEqual(module.type, "sometype")
        self.assertDictEqual(module.plugin_fields, {
            "url": "http://www.example.com/",
            "rev": "abcdefg"
        })
github buildinspace / peru / peru / module.py View on Github external
def extract_modules(runtime, blob):
    modules = {}
    for field in list(blob.keys()):
        parts = field.split()
        if len(parts) == 3 and parts[1] == "module":
            type_, _, name = parts
            inner_blob = blob.pop(field)  # remove the field from blob
            remote = extract_remote(runtime, type_, inner_blob, name)
            rules = extract_rules(inner_blob)
            modules[name] = Module(inner_blob, rules, name=name, remote=remote)
    return modules
github buildinspace / peru / peru / module.py View on Github external
def parse(runtime, filename):
    with open(filename) as f:
        blob = yaml.safe_load(f.read())
    rules = extract_rules(blob)
    modules = extract_modules(runtime, blob)
    return Module(blob, rules, modules=modules)
github buildinspace / peru / peru / parser.py View on Github external
plugin_fields = blob

    # Stringify all the plugin fields.
    for k, v in plugin_fields.items():
        if not isinstance(k, str):
            raise ParserError(
                'Module field names must be strings. Found "{}".'.format(
                    repr(k)))
        if isinstance(v, bool):
            # Avoid the Python-specific True/False capitalization, to be
            # consistent with what people will usually type in YAML.
            plugin_fields[k] = "true" if v else "false"
        else:
            plugin_fields[k] = str(v)

    module = Module(name, type, default_rule, plugin_fields, yaml_name,
                    peru_file, recursive)
    return module