@@ -31,6 +31,37 @@ class STPerson(BaseModel):
3131 email : Annotated [Optional [str ], Field (min_length = 1 )] = None
3232
3333
34+ class License (BaseModel ):
35+ """License model for setuptools."""
36+
37+ model_config = dict (validate_assignment = True )
38+
39+ file : Optional [Path ] = None
40+ text : Optional [LicenseEnum ] = None
41+
42+ @model_validator (mode = "before" )
43+ @classmethod
44+ def validate_xor (cls , values ):
45+ """Validate that only one of file or text is set."""
46+ # check if this has just str or list of str
47+ if isinstance (values , str ):
48+ if values in LicenseEnum .__members__ :
49+ return {"text" : values }
50+ else :
51+ raise ValueError ("Invalid license." )
52+ if isinstance (values , list ):
53+ # check if all elements are valid string for LicenseEnum
54+ for v in values :
55+ if not isinstance (v , str ):
56+ raise ValueError ("All elements must be strings." )
57+ if v not in LicenseEnum .__members__ :
58+ raise ValueError ("Invalid license." )
59+ return values
60+ if sum ([bool (v ) for v in values .values ()]) != 1 :
61+ raise ValueError ("Either file or text must be set." )
62+ return values
63+
64+
3465class PoetryConfig (BaseModel ):
3566 """Poetry configuration model."""
3667
@@ -49,7 +80,7 @@ class PoetryConfig(BaseModel):
4980 ]
5081 description : Annotated [str , Field (description = "Package description" )]
5182 license : Annotated [
52- Optional [Union [LicenseEnum , List [LicenseEnum ]]],
83+ Optional [Union [LicenseEnum , List [LicenseEnum ], License ]],
5384 Field (description = "An SPDX license identifier." ),
5485 ]
5586
@@ -150,23 +181,6 @@ class File(BaseModel):
150181 content_type : Optional [ContentTypeEnum ] = Field (alias = "content-type" )
151182
152183
153- class License (BaseModel ):
154- """License model for setuptools."""
155-
156- model_config = dict (validate_assignment = True )
157-
158- file : Optional [Path ] = None
159- text : Optional [LicenseEnum ] = None
160-
161- @model_validator (mode = "before" )
162- @classmethod
163- def validate_xor (cls , values ):
164- """Validate that only one of file or text is set."""
165- if sum ([bool (v ) for v in values .values ()]) != 1 :
166- raise ValueError ("Either file or text must be set." )
167- return values
168-
169-
170184class URLs (BaseModel ):
171185 """URLs model for setuptools."""
172186
0 commit comments