@@ -21,7 +21,13 @@ class PyprojectCommon(ProjectMetadataWriter):
2121 """Poetry config file handler parsed from pyproject.toml."""
2222
2323 def __init__ (
24- self , path : Path , * , section : List [str ], model_cls , direct_mappings = None
24+ self ,
25+ path : Path ,
26+ * ,
27+ section : List [str ],
28+ model_cls ,
29+ direct_mappings = None ,
30+ pass_validation : Optional [bool ] = False ,
2531 ):
2632 """Poetry config file handler parsed from pyproject.toml.
2733
@@ -30,7 +36,10 @@ def __init__(
3036 self ._model_cls = model_cls
3137 self ._section = section
3238 super ().__init__ (
33- path , create_if_not_exists = False , direct_mappings = direct_mappings or {}
39+ path ,
40+ create_if_not_exists = False ,
41+ direct_mappings = direct_mappings or {},
42+ pass_validation = pass_validation ,
3443 )
3544
3645 def _load (self ) -> None :
@@ -44,6 +53,8 @@ def _validate(self) -> None:
4453 In order to preserve toml comments and structure, tomlkit library is used.
4554 Pydantic class only used for validation.
4655 """
56+ if self .pass_validation :
57+ return
4758 config = dict (self ._get_property ([]))
4859 logger .debug (
4960 f"Validating config using { self ._model_cls .__name__ } : { pretty_repr (config )} "
@@ -89,12 +100,21 @@ def _set_property(self, key: Union[str, List[str], IgnoreKey], value: Any) -> No
89100class Poetry (PyprojectCommon ):
90101 """Poetry config file handler parsed from pyproject.toml."""
91102
92- def __init__ (self , path : Path ):
103+ def __init__ (
104+ self ,
105+ path : Path ,
106+ pass_validation : Optional [bool ] = False ,
107+ ):
93108 """Poetry config file handler parsed from pyproject.toml.
94109
95110 See [somesy.core.writer.ProjectMetadataWriter.__init__][].
96111 """
97- super ().__init__ (path , section = ["tool" , "poetry" ], model_cls = PoetryConfig )
112+ super ().__init__ (
113+ path ,
114+ section = ["tool" , "poetry" ],
115+ model_cls = PoetryConfig ,
116+ pass_validation = pass_validation ,
117+ )
98118
99119 @staticmethod
100120 def _from_person (person : Union [Person , Entity ]):
@@ -119,7 +139,7 @@ def _to_person(person: str) -> Optional[Union[Person, Entity]]:
119139class SetupTools (PyprojectCommon ):
120140 """Setuptools config file handler parsed from setup.cfg."""
121141
122- def __init__ (self , path : Path ):
142+ def __init__ (self , path : Path , pass_validation : Optional [ bool ] = False ):
123143 """Setuptools config file handler parsed from pyproject.toml.
124144
125145 See [somesy.core.writer.ProjectMetadataWriter.__init__][].
@@ -132,7 +152,11 @@ def __init__(self, path: Path):
132152 "license" : ["license" , "text" ],
133153 }
134154 super ().__init__ (
135- path , section = section , direct_mappings = mappings , model_cls = SetuptoolsConfig
155+ path ,
156+ section = section ,
157+ direct_mappings = mappings ,
158+ model_cls = SetuptoolsConfig ,
159+ pass_validation = pass_validation ,
136160 )
137161
138162 @staticmethod
@@ -186,11 +210,12 @@ class Pyproject(wrapt.ObjectProxy):
186210
187211 __wrapped__ : Union [SetupTools , Poetry ]
188212
189- def __init__ (self , path : Path ):
213+ def __init__ (self , path : Path , pass_validation : Optional [ bool ] = False ):
190214 """Pyproject wrapper class. Wraps either setuptools or poetry.
191215
192216 Args:
193217 path (Path): Path to pyproject.toml file.
218+ pass_validation (bool, optional): Whether to pass validation. Defaults to False.
194219
195220 Raises:
196221 FileNotFoundError: Raised when pyproject.toml file is not found.
@@ -207,10 +232,10 @@ def __init__(self, path: Path):
207232 # inspect file to pick suitable project metadata writer
208233 if "project" in data :
209234 logger .verbose ("Found setuptools-based metadata in pyproject.toml" )
210- self .__wrapped__ = SetupTools (path )
235+ self .__wrapped__ = SetupTools (path , pass_validation = pass_validation )
211236 elif "tool" in data and "poetry" in data ["tool" ]:
212237 logger .verbose ("Found poetry-based metadata in pyproject.toml" )
213- self .__wrapped__ = Poetry (path )
238+ self .__wrapped__ = Poetry (path , pass_validation = pass_validation )
214239 else :
215240 msg = "The pyproject.toml file is ambiguous, either add a [project] or [tool.poetry] section"
216241 raise ValueError (msg )
0 commit comments