8383 "threads" ,
8484}
8585
86+ LAPTOP_REQUIRED = {
87+ "slug" ,
88+ "name" ,
89+ "brand" ,
90+ "release_date" ,
91+ "ram_gb" ,
92+ "os" ,
93+ "source_urls" ,
94+ "verified" ,
95+ }
96+
8697DATE_RE = re .compile (r"^\d{4}-\d{2}-\d{2}$" )
8798
8899
@@ -205,9 +216,12 @@ def validate() -> list[str]:
205216 pdas = _load ("pda" )
206217 gpus = _load ("gpu" )
207218 cpus = _load ("cpu" )
219+ laptops = _load ("laptop" )
208220
209221 brand_slugs = {rec ["slug" ] for _ , rec in brands if "slug" in rec }
210222 soc_slugs = {rec ["slug" ] for _ , rec in socs if "slug" in rec }
223+ cpu_slugs = {rec ["slug" ] for _ , rec in cpus if "slug" in rec }
224+ gpu_slugs = {rec ["slug" ] for _ , rec in gpus if "slug" in rec }
211225
212226 for category , records in (
213227 ("brand" , brands ),
@@ -218,6 +232,7 @@ def validate() -> list[str]:
218232 ("pda" , pdas ),
219233 ("gpu" , gpus ),
220234 ("cpu" , cpus ),
235+ ("laptop" , laptops ),
221236 ):
222237 _check_unique_slugs (category , records , errors )
223238
@@ -330,6 +345,27 @@ def validate() -> list[str]:
330345 if rec .get ("manufacturer" ) not in brand_slugs :
331346 errors .append (f"{ fname } : manufacturer '{ rec .get ('manufacturer' )} ' not a known brand" )
332347
348+ for fname , rec in laptops :
349+ _check_required (fname , rec , LAPTOP_REQUIRED , errors )
350+ _check_source_urls (fname , rec , errors )
351+ _check_slug (fname , rec .get ("slug" ), errors )
352+ if "release_date" in rec :
353+ _check_date (fname , rec ["release_date" ], errors )
354+ _check_range (fname , "ram_gb" , rec .get ("ram_gb" ), 1 , 256 , errors )
355+ if rec .get ("storage_gb" ) is not None :
356+ _check_range (fname , "storage_gb" , rec .get ("storage_gb" ), 1 , 65536 , errors )
357+ if rec .get ("weight_g" ) is not None :
358+ _check_range (fname , "weight_g" , rec .get ("weight_g" ), 300 , 6000 , errors )
359+ if "msrp_usd" in rec :
360+ _check_range (fname , "msrp_usd" , rec ["msrp_usd" ], 50 , 50000 , errors )
361+ if rec .get ("brand" ) not in brand_slugs :
362+ errors .append (f"{ fname } : brand '{ rec .get ('brand' )} ' not a known brand" )
363+ if rec .get ("cpu" ) is not None and rec .get ("cpu" ) not in cpu_slugs :
364+ errors .append (f"{ fname } : cpu '{ rec .get ('cpu' )} ' not a known CPU" )
365+ if rec .get ("gpu" ) is not None and rec .get ("gpu" ) not in gpu_slugs :
366+ errors .append (f"{ fname } : gpu '{ rec .get ('gpu' )} ' not a known GPU" )
367+ _check_variant_path (fname , rec , "laptop" , errors , allow_flat = True )
368+
333369 return errors
334370
335371
0 commit comments