1616"""
1717
1818
19+ class Dependency (TypedDict ):
20+ """Argument types for dependency class construction."""
21+
22+ branch : str
23+ tag : str
24+ revision : str
25+ remote_url : str
26+ destination : str
27+ source_type : str
28+
29+
1930class Options (TypedDict ): # pylint: disable=too-many-ancestors
2031 """Argument types for Metadata class construction."""
2132
@@ -27,6 +38,7 @@ class Options(TypedDict): # pylint: disable=too-many-ancestors
2738 destination : str
2839 hash : str
2940 patch : str | list [str ]
41+ dependencies : list ["Dependency" ]
3042
3143
3244class Metadata :
@@ -54,6 +66,8 @@ def __init__(self, kwargs: Options) -> None:
5466 # Historically only a single patch was allowed
5567 self ._patch : list [str ] = always_str_list (kwargs .get ("patch" , []))
5668
69+ self ._dependencies : list [Dependency ] = kwargs .get ("dependencies" , [])
70+
5771 @classmethod
5872 def from_project_entry (cls , project : ProjectEntry ) -> "Metadata" :
5973 """Create a metadata object from a project entry."""
@@ -66,6 +80,7 @@ def from_project_entry(cls, project: ProjectEntry) -> "Metadata":
6680 "last_fetch" : datetime .datetime (2000 , 1 , 1 , 0 , 0 , 0 ),
6781 "hash" : "" ,
6882 "patch" : project .patch ,
83+ "dependencies" : [],
6984 }
7085 return cls (data )
7186
@@ -77,13 +92,18 @@ def from_file(cls, path: str) -> "Metadata":
7792 return cls (data )
7893
7994 def fetched (
80- self , version : Version , hash_ : str = "" , patch_ : list [str ] | None = None
95+ self ,
96+ version : Version ,
97+ hash_ : str = "" ,
98+ patch_ : list [str ] | None = None ,
99+ dependencies : list [Dependency ] | None = None ,
81100 ) -> None :
82101 """Update metadata."""
83102 self ._last_fetch = datetime .datetime .now ()
84103 self ._version = version
85104 self ._hash = hash_
86105 self ._patch = patch_ or []
106+ self ._dependencies = dependencies or []
87107
88108 @property
89109 def version (self ) -> Version :
@@ -129,6 +149,11 @@ def patch(self) -> list[str]:
129149 """The list of applied patches as stored in the metadata."""
130150 return self ._patch
131151
152+ @property
153+ def dependencies (self ) -> list [Dependency ]:
154+ """The list of dependency projects as stored in the metadata."""
155+ return self ._dependencies
156+
132157 @property
133158 def path (self ) -> str :
134159 """Path to metadata file."""
@@ -152,12 +177,13 @@ def __eq__(self, other: object) -> bool:
152177 other ._version .revision == self ._version .revision ,
153178 other .hash == self .hash ,
154179 other .patch == self .patch ,
180+ other .dependencies == self .dependencies ,
155181 ]
156182 )
157183
158184 def dump (self ) -> None :
159185 """Dump metadata file to correct path."""
160- metadata = {
186+ metadata : dict [ str , dict [ str , str | list [ str ] | list [ Dependency ]]] = {
161187 "dfetch" : {
162188 "remote_url" : self .remote_url ,
163189 "branch" : self ._version .branch ,
@@ -169,6 +195,9 @@ def dump(self) -> None:
169195 }
170196 }
171197
198+ if self .dependencies :
199+ metadata ["dfetch" ]["dependencies" ] = self .dependencies
200+
172201 with open (self .path , "w+" , encoding = "utf-8" ) as metadata_file :
173202 metadata_file .write (DONT_EDIT_WARNING )
174203 yaml .dump (metadata , metadata_file )
0 commit comments