@@ -214,6 +214,11 @@ def _exactly_one(iterable: Iterable[object]) -> bool:
214
214
return found
215
215
216
216
217
+ def _validate_path_url (path : Optional [str ], url : Optional [str ]) -> None :
218
+ if not path and not url :
219
+ raise PylockValidationError ("path or url must be provided" )
220
+
221
+
217
222
def _validate_hashes (hashes : Dict [str , Any ]) -> None :
218
223
if not hashes :
219
224
raise PylockValidationError ("At least one hash must be provided" )
@@ -248,8 +253,7 @@ class PackageVcs:
248
253
subdirectory : Optional [str ]
249
254
250
255
def __post_init__ (self ) -> None :
251
- if not self .path and not self .url :
252
- raise PylockValidationError ("No path nor url set for vcs package" )
256
+ _validate_path_url (self .path , self .url )
253
257
254
258
@classmethod
255
259
def from_dict (cls , d : Dict [str , Any ]) -> "Self" :
@@ -288,8 +292,7 @@ class PackageArchive:
288
292
subdirectory : Optional [str ]
289
293
290
294
def __post_init__ (self ) -> None :
291
- if not self .path and not self .url :
292
- raise PylockValidationError ("No path nor url set for archive package" )
295
+ _validate_path_url (self .path , self .url )
293
296
_validate_hashes (self .hashes )
294
297
295
298
@classmethod
@@ -314,8 +317,7 @@ class PackageSdist:
314
317
hashes : Dict [str , str ]
315
318
316
319
def __post_init__ (self ) -> None :
317
- if not self .path and not self .url :
318
- raise PylockValidationError ("No path nor url set for sdist package" )
320
+ _validate_path_url (self .path , self .url )
319
321
_validate_hashes (self .hashes )
320
322
321
323
@classmethod
@@ -340,8 +342,7 @@ class PackageWheel:
340
342
hashes : Dict [str , str ]
341
343
342
344
def __post_init__ (self ) -> None :
343
- if not self .path and not self .url :
344
- raise PylockValidationError ("No path nor url set for wheel package" )
345
+ _validate_path_url (self .path , self .url )
345
346
_validate_hashes (self .hashes )
346
347
347
348
@classmethod
0 commit comments