@@ -1348,58 +1348,42 @@ def __init__(self, root: str, config: dict[str, Any], plugin_manager: PluginMana
1348
1348
self .config = config
1349
1349
self .plugin_manager = plugin_manager
1350
1350
1351
- self ._cached : str | None = None
1352
- self ._source_name : str | None = None
1353
- self ._scheme_name : str | None = None
1354
- self ._source : VersionSourceInterface | None = None
1355
- self ._scheme : VersionSchemeInterface | None = None
1356
-
1357
- @property
1351
+ @cached_property
1358
1352
def cached (self ) -> str :
1359
- if self ._cached is None :
1360
- try :
1361
- self ._cached = self .source .get_version_data ()['version' ]
1362
- except Exception as e : # noqa: BLE001
1363
- message = f'Error getting the version from source `{ self .source .PLUGIN_NAME } `: { e } '
1364
- raise type (e )(message ) from None
1365
-
1366
- return self ._cached
1353
+ try :
1354
+ return self .source .get_version_data ()['version' ]
1355
+ except Exception as e : # noqa: BLE001
1356
+ message = f'Error getting the version from source `{ self .source .PLUGIN_NAME } `: { e } '
1357
+ raise type (e )(message ) from None
1367
1358
1368
- @property
1359
+ @cached_property
1369
1360
def source_name (self ) -> str :
1370
- if self ._source_name is None :
1371
- source : str = self .config .get ('source' , 'regex' )
1372
- if not source :
1373
- message = 'The `source` option under the `tool.hatch.version` table must not be empty if defined'
1374
- raise ValueError (message )
1375
-
1376
- if not isinstance (source , str ):
1377
- message = 'Field `tool.hatch.version.source` must be a string'
1378
- raise TypeError (message )
1361
+ source : str = self .config .get ('source' , 'regex' )
1362
+ if not source :
1363
+ message = 'The `source` option under the `tool.hatch.version` table must not be empty if defined'
1364
+ raise ValueError (message )
1379
1365
1380
- self ._source_name = source
1366
+ if not isinstance (source , str ):
1367
+ message = 'Field `tool.hatch.version.source` must be a string'
1368
+ raise TypeError (message )
1381
1369
1382
- return self . _source_name
1370
+ return source
1383
1371
1384
- @property
1372
+ @cached_property
1385
1373
def scheme_name (self ) -> str :
1386
- if self ._scheme_name is None :
1387
- scheme : str = self .config .get ('scheme' , 'standard' )
1388
- if not scheme :
1389
- message = 'The `scheme` option under the `tool.hatch.version` table must not be empty if defined'
1390
- raise ValueError (message )
1391
-
1392
- if not isinstance (scheme , str ):
1393
- message = 'Field `tool.hatch.version.scheme` must be a string'
1394
- raise TypeError (message )
1374
+ scheme : str = self .config .get ('scheme' , 'standard' )
1375
+ if not scheme :
1376
+ message = 'The `scheme` option under the `tool.hatch.version` table must not be empty if defined'
1377
+ raise ValueError (message )
1395
1378
1396
- self ._scheme_name = scheme
1379
+ if not isinstance (scheme , str ):
1380
+ message = 'Field `tool.hatch.version.scheme` must be a string'
1381
+ raise TypeError (message )
1397
1382
1398
- return self . _scheme_name
1383
+ return scheme
1399
1384
1400
- @property
1385
+ @cached_property
1401
1386
def source (self ) -> VersionSourceInterface :
1402
- if self ._source is None :
1403
1387
from copy import deepcopy
1404
1388
1405
1389
source_name = self .source_name
@@ -1410,26 +1394,21 @@ def source(self) -> VersionSourceInterface:
1410
1394
message = f'Unknown version source: { source_name } '
1411
1395
raise UnknownPluginError (message )
1412
1396
1413
- self . _source = version_source (self .root , deepcopy (self .config ))
1397
+ return version_source (self .root , deepcopy (self .config ))
1414
1398
1415
- return self ._source
1416
-
1417
- @property
1399
+ @cached_property
1418
1400
def scheme (self ) -> VersionSchemeInterface :
1419
- if self ._scheme is None :
1420
- from copy import deepcopy
1401
+ from copy import deepcopy
1421
1402
1422
- scheme_name = self .scheme_name
1423
- version_scheme = self .plugin_manager .version_scheme .get (scheme_name )
1424
- if version_scheme is None :
1425
- from hatchling .plugin .exceptions import UnknownPluginError
1426
-
1427
- message = f'Unknown version scheme: { scheme_name } '
1428
- raise UnknownPluginError (message )
1403
+ scheme_name = self .scheme_name
1404
+ version_scheme = self .plugin_manager .version_scheme .get (scheme_name )
1405
+ if version_scheme is None :
1406
+ from hatchling .plugin .exceptions import UnknownPluginError
1429
1407
1430
- self ._scheme = version_scheme (self .root , deepcopy (self .config ))
1408
+ message = f'Unknown version scheme: { scheme_name } '
1409
+ raise UnknownPluginError (message )
1431
1410
1432
- return self ._scheme
1411
+ return version_scheme ( self .root , deepcopy ( self . config ))
1433
1412
1434
1413
1435
1414
class HatchMetadataSettings (Generic [PluginManagerBound ]):
0 commit comments