2727import yaml
2828from typing_extensions import TypedDict
2929
30- import dfetch .manifest .validate
3130from dfetch import DEFAULT_MANIFEST_NAME
3231from dfetch .log import get_logger
3332from dfetch .manifest .project import ProjectEntry , ProjectEntryDict
3433from dfetch .manifest .remote import Remote , RemoteDict
34+ from dfetch .manifest .validate import validate
3535from dfetch .util .util import find_file , prefix_runtime_exceptions
3636
3737logger = get_logger (__name__ )
@@ -89,7 +89,7 @@ class ManifestDict( # pylint: disable=too-many-ancestors
8989): # When https://www.python.org/dev/peps/pep-0655/ is accepted, only make remotes optional
9090 """Serialized dict types."""
9191
92- version : str
92+ version : Union [ int , str ]
9393 remotes : Sequence [Union [RemoteDict , Remote ]]
9494 projects : Sequence [Union [ProjectEntryDict , ProjectEntry , Dict [str , str ]]]
9595
@@ -104,7 +104,7 @@ class Manifest:
104104
105105 def __init__ (self , manifest : ManifestDict ) -> None :
106106 """Create the manifest."""
107- self .__version : str = manifest .get ("version" , self .CURRENT_VERSION )
107+ self .__version : str = str ( manifest .get ("version" , self .CURRENT_VERSION ) )
108108
109109 self ._remotes , default_remotes = self ._determine_remotes (
110110 manifest .get ("remotes" , [])
@@ -114,6 +114,9 @@ def __init__(self, manifest: ManifestDict) -> None:
114114 default_remotes = list (self ._remotes .values ())[0 :1 ]
115115
116116 self ._default_remote = None if not default_remotes else default_remotes [0 ]
117+
118+ if "projects" not in manifest :
119+ raise KeyError ("No projects in manifest!" )
117120 self ._projects = self ._init_projects (manifest ["projects" ])
118121
119122 def _init_projects (
@@ -133,6 +136,8 @@ def _init_projects(
133136 _projects : Dict [str , ProjectEntry ] = {}
134137 for project in projects :
135138 if isinstance (project , dict ):
139+ if "name" not in project :
140+ raise KeyError ("Missing name!" )
136141 last_project = _projects [project ["name" ]] = ProjectEntry .from_yaml (
137142 project , self ._default_remote
138143 )
@@ -306,11 +311,11 @@ def get_manifest() -> Tuple[Manifest, str]:
306311 """Get manifest and its path."""
307312 logger .debug ("Looking for manifest" )
308313 manifest_path = find_manifest ()
309- dfetch . manifest . validate . validate (manifest_path )
314+ validate (manifest_path )
310315
311316 logger .debug (f"Using manifest { manifest_path } " )
312317 return (
313- dfetch . manifest . manifest . Manifest .from_file (manifest_path ),
318+ Manifest .from_file (manifest_path ),
314319 manifest_path ,
315320 )
316321
@@ -320,16 +325,16 @@ def get_childmanifests(skip: Optional[List[str]] = None) -> List[Tuple[Manifest,
320325 skip = skip or []
321326 logger .debug ("Looking for sub-manifests" )
322327
323- childmanifests = []
328+ childmanifests : List [ Tuple [ Manifest , str ]] = []
324329 for path in find_file (DEFAULT_MANIFEST_NAME , "." ):
325330 path = os .path .realpath (path )
326331 if path not in skip :
327332 logger .debug (f"Found sub-manifests { path } " )
328333 with prefix_runtime_exceptions (
329334 pathlib .Path (path ).relative_to (os .path .dirname (os .getcwd ())).as_posix ()
330335 ):
331- dfetch . manifest . validate . validate (path )
332- childmanifest = dfetch . manifest . manifest . Manifest .from_file (path )
336+ validate (path )
337+ childmanifest = Manifest .from_file (path )
333338 childmanifests += [(childmanifest , path )]
334339
335340 return childmanifests
0 commit comments