コード例 #1
0
ファイル: test_metadata.py プロジェクト: sed-i/charmcraft
def test_parse_metadata_yaml_error_invalid_names(tmp_path, name):
    metadata_file = tmp_path / "metadata.yaml"
    metadata_file.write_text(f"name: {name}")

    expected_error_msg = dedent("""\
        Bad metadata.yaml content:
        - string type expected in field 'name'""")
    with pytest.raises(CommandError, match=re.escape(expected_error_msg)):
        parse_metadata_yaml(tmp_path)
コード例 #2
0
ファイル: build.py プロジェクト: sed-i/charmcraft
    def __init__(self, args, config):
        self.charmdir = args["from"]
        self.entrypoint = args["entrypoint"]
        self.requirement_paths = args["requirement"]
        self.force_packing = args["force"]
        self.debug = args["debug"]
        self.shell = args["shell"]
        self.shell_after = args["shell_after"]

        self.buildpath = self.charmdir / BUILD_DIRNAME
        self.config = config
        self.metadata = parse_metadata_yaml(self.charmdir)

        if self.config.parts:
            self._parts = self.config.parts.copy()
        else:
            # "parts" not declared, create an implicit "charm" part
            self._parts = {"charm": {"plugin": "charm"}}

        # a part named "charm" using plugin "charm" is special and has
        # predefined values set automatically.
        charm_part = self._parts.get("charm")
        if charm_part and charm_part.get("plugin") == "charm":
            self._special_charm_part = charm_part
        else:
            self._special_charm_part = None

        self.provider = get_provider()
コード例 #3
0
ファイル: test_metadata.py プロジェクト: sed-i/charmcraft
def test_parse_metadata_yaml_valid_names(tmp_path, name):
    metadata_file = tmp_path / "metadata.yaml"
    metadata_file.write_text(f"name: {name}")

    metadata = parse_metadata_yaml(tmp_path)

    assert metadata.name == name
コード例 #4
0
    def run(self, parsed_args):
        """Run the command."""
        project_path = self.config.project.dirpath
        metadata = parse_metadata_yaml(project_path)
        logger.debug("Cleaning project %r.", metadata.name)

        clean_project_environments(metadata.name, project_path)
        logger.info("Cleaned project %r.", metadata.name)
コード例 #5
0
ファイル: clean.py プロジェクト: sed-i/charmcraft
    def run(self, parsed_args):
        """Run the command."""
        project_path = self.config.project.dirpath
        metadata = parse_metadata_yaml(project_path)
        emit.progress(f"Cleaning project {metadata.name!r}.")

        provider = get_provider()
        provider.clean_project_environments(charm_name=metadata.name, project_path=project_path)
        emit.message(f"Cleaned project {metadata.name!r}.")
コード例 #6
0
    def __init__(self, args, config):
        self.charmdir = args["from"]
        self.entrypoint = args["entrypoint"]
        self.requirement_paths = args["requirement"]
        self.force_packing = args["force"]

        self.buildpath = self.charmdir / BUILD_DIRNAME
        self.config = config
        self.metadata = parse_metadata_yaml(self.charmdir)

        self._parts = self.config.parts.copy()
        self._charm_part = self._parts.setdefault("charm", {})
        self._prime = self._charm_part.setdefault("prime", [])
コード例 #7
0
ファイル: linters.py プロジェクト: sed-i/charmcraft
    def run(self, basedir: pathlib.Path) -> str:
        """Run the proper verifications."""
        try:
            metadata = parse_metadata_yaml(basedir)
        except Exception:
            # file not found, corrupted, or mandatory "name" not present
            return self.Result.errors

        # no need to verify "name" as it's mandatory in the metadata parsing
        if metadata.summary and metadata.description:
            result = self.Result.ok
        else:
            result = self.Result.errors
        return result
コード例 #8
0
ファイル: test_metadata.py プロジェクト: sed-i/charmcraft
def test_parse_metadata_yaml_complete(tmp_path):
    """Example of parsing with all the optional attributes."""
    metadata_file = tmp_path / "metadata.yaml"
    metadata_file.write_text("""
        name: test-name
        summary: Test summary
        description: Lot of text.
    """)

    metadata = parse_metadata_yaml(tmp_path)

    assert metadata.name == "test-name"
    assert metadata.summary == "Test summary"
    assert metadata.description == "Lot of text."
コード例 #9
0
ファイル: linters.py プロジェクト: dstathis/charmcraft
    def _check_reactive(self, basedir: pathlib.Path) -> bool:
        """Detect if the Reactive Framework is used."""
        try:
            metadata = parse_metadata_yaml(basedir)
        except Exception:
            # file not found, corrupted, or mandatory "name" not present
            return False

        wheelhouse_dir = basedir / "wheelhouse"
        if not wheelhouse_dir.exists():
            return False
        if not any(f.name.startswith("charms.reactive-") for f in wheelhouse_dir.iterdir()):
            return False

        entrypoint = basedir / "reactive" / f"{metadata.name}.py"
        for import_parts in self._get_imports(entrypoint):
            if import_parts[0] == "charms" and import_parts[1] == "reactive":
                return True
        return False
コード例 #10
0
ファイル: test_metadata.py プロジェクト: sed-i/charmcraft
def test_parse_metadata_yaml_error_missing(tmp_path):
    with pytest.raises(CommandError,
                       match=r"Missing mandatory metadata.yaml."):
        parse_metadata_yaml(tmp_path)