Get the version scheme as defined in the configuration or from an overridden `name`. :raises VersionSchemeUnknown: if the version scheme is not found.
(settings: Settings, name: str | None = None)
| 395 | |
| 396 | |
| 397 | def get_version_scheme(settings: Settings, name: str | None = None) -> VersionScheme: |
| 398 | """ |
| 399 | Get the version scheme as defined in the configuration |
| 400 | or from an overridden `name`. |
| 401 | |
| 402 | |
| 403 | |
| 404 | :raises VersionSchemeUnknown: if the version scheme is not found. |
| 405 | """ |
| 406 | # TODO: Remove the deprecated `version_type` handling |
| 407 | deprecated_setting: str | None = settings.get("version_type") |
| 408 | if deprecated_setting: |
| 409 | warnings.warn( |
| 410 | DeprecationWarning( |
| 411 | "`version_type` setting is deprecated and will be removed in v5. " |
| 412 | "Please use `version_scheme` instead" |
| 413 | ) |
| 414 | ) |
| 415 | name = name or settings.get("version_scheme") or deprecated_setting |
| 416 | if not name: |
| 417 | return DEFAULT_SCHEME |
| 418 | |
| 419 | try: |
| 420 | (ep,) = metadata.entry_points(name=name, group=SCHEMES_ENTRYPOINT) |
| 421 | except ValueError: |
| 422 | raise VersionSchemeUnknown(f'Version scheme "{name}" unknown.') |
| 423 | scheme = cast("VersionScheme", ep.load()) |
| 424 | |
| 425 | # `VersionProtocol` is a `@runtime_checkable` Protocol, but `issubclass()` is not |
| 426 | # supported for Protocols with non-method members. We check an instance instead by |
| 427 | # verifying the loaded object is a class with the expected interface. |
| 428 | if isinstance(scheme, type): |
| 429 | # Check for a key method/attribute that VersionProtocol requires |
| 430 | if not hasattr(scheme, "bump"): |
| 431 | warnings.warn( |
| 432 | f"Version scheme {name} does not implement the VersionProtocol" |
| 433 | ) |
| 434 | else: |
| 435 | warnings.warn(f"Version scheme {name} does not implement the VersionProtocol") |
| 436 | |
| 437 | return scheme |
searching dependent graphs…