# Copyright 2023-2024 Canonical Ltd.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.## For further info, check https://github.com/canonical/charmcraft"""Charmcraft configuration pydantic model."""fromtypingimportTypedDict,castimportpydanticfromcraft_applicationimportutilfromcraft_application.modelsimportCraftBaseModelfromtyping_extensionsimportSelffromcharmcraft.models.basicimportAttributeName,LinterNameclassBaseDict(TypedDict,total=False):"""TypedDict that describes only one base. This is equivalent to the short form base definition. """name:strchannel:strarchitectures:list[str]LongFormBasesDict=TypedDict("LongFormBasesDict",{"build-on":list[BaseDict],"run-on":list[BaseDict]})classCharmhub(CraftBaseModel):"""Definition of Charmhub endpoint configuration."""api_url:pydantic.HttpUrl=cast(pydantic.HttpUrl,"https://api.charmhub.io")storage_url:pydantic.HttpUrl=cast(pydantic.HttpUrl,"https://storage.snapcraftcontent.com")registry_url:pydantic.HttpUrl=cast(pydantic.HttpUrl,"https://registry.jujucharms.com")
[docs]classBase(CraftBaseModel):"""Represents a base."""name:pydantic.StrictStrchannel:pydantic.StrictStrarchitectures:list[pydantic.StrictStr]=[util.get_host_architecture()]
[docs]@classmethoddeffrom_str_and_arch(cls,base_str:str,architectures:list[str])->Self:"""Get a Base from a base string and list of architectures. :param base_str: A base string along the lines of "<name>@<channel>" :param architectures: A list of architectures (or ["all"]) """name,_,channel=base_str.partition("@")returncls(name=name,channel=channel,architectures=architectures)
classIgnore(CraftBaseModel):"""Definition of `analysis.ignore` configuration."""attributes:list[AttributeName]=[]linters:list[LinterName]=[]classAnalysisConfig(CraftBaseModel):"""Definition of `analysis` configuration."""ignore:Ignore=Ignore()
[docs]classLinks(CraftBaseModel):"""Definition of `links` in metadata."""contact:pydantic.StrictStr|list[pydantic.StrictStr]|None=None"""Instructions for contacting the owner of the charm."""documentation:pydantic.AnyHttpUrl|None=None"""The URL of the documentation for this charm."""issues:pydantic.AnyHttpUrl|list[pydantic.AnyHttpUrl]|None=None"""A link to the issue tracker for this charm."""source:pydantic.AnyHttpUrl|list[pydantic.AnyHttpUrl]|None=None"""Where to find this charm's source code."""website:pydantic.AnyHttpUrl|list[pydantic.AnyHttpUrl]|None=None"""The website for this charm."""