From 2327610945323390cc330d23938d3c50a6f596c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Fri, 18 Mar 2022 13:54:06 -0700 Subject: [PATCH] manifest: ManifestImportFailed: relax argument specification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Continue to accept all arguments previously accepted, but widen the allowed argument types as follows: - Allow passing a None argument as the project to signal the manifest repository is where the import is happening. This will be useful for allowing us to continue using this exception type without mandating use of the ManifestProject class, which we'd like to get rid of eventually. - Generalize the 'filename' argument to allow specifying arbitrary import data which could not be imported. This will be useful for specifying failures that happen when importing a map by giving the entire map that failed to import, instead of just a file name. Signed-off-by: Martí Bolívar --- src/west/manifest.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/west/manifest.py b/src/west/manifest.py index 858bccf..7d23b6c 100644 --- a/src/west/manifest.py +++ b/src/west/manifest.py @@ -547,18 +547,24 @@ class ManifestImportFailed(Exception): Attributes: - - ``project``: the Project instance with the missing manifest data - - ``filename``: the missing file, as a str + - ``project``: the Project instance with the missing manifest data; + None if it's from the manifest via "manifest: self: import:" + - ``imp``: the parsed YAML data whose import was requested ''' - def __init__(self, project: 'Project', filename: PathType): - super().__init__(project, filename) + def __init__(self, project: Optional['Project'], imp: Any): + super().__init__() self.project = project - self.filename = os.fspath(filename) + self.imp = imp def __str__(self): - return (f'ManifestImportFailed: project {self.project} ' - f'file {self.filename}') + if self.project is not None: + return (f'ManifestImportFailed: project {self.project} ' + f'value {self.imp}') + else: + return (f'ManifestImportFailed: manifest repository ' + f'value {self.imp}') + class ManifestVersionError(Exception): '''The manifest required a version of west more recent than the